forked from parrot/parrot
/
chartype.c
65 lines (56 loc) · 1.39 KB
/
chartype.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* chartype.c
* Copyright: (When this is determined...it will go here)
* CVS Info
* $Id$
* Overview:
* This defines the string character type subsystem
* Data Structure and Algorithms:
* History:
* Notes:
* References:
*/
#include "parrot/parrot.h"
extern const CHARTYPE usascii_chartype;
extern const CHARTYPE unicode_chartype;
static const CHARTYPE *chartype_array[enum_chartype_MAX];
const CHARTYPE *
chartype_lookup(const char *name)
{
if (strcmp(name, "usascii") == 0) {
return &usascii_chartype;
}
else if (strcmp(name, "unicode") == 0) {
return &unicode_chartype;
}
else {
internal_exception(INVALID_CHARTYPE, "Invalid chartype '%s'\n", name);
return NULL;
}
}
const CHARTYPE *
chartype_lookup_index(INTVAL n)
{
if (!chartype_array[0]) {
chartype_array[enum_chartype_unicode] = &unicode_chartype;
chartype_array[enum_chartype_usascii] = &usascii_chartype;
}
return chartype_array[n];
}
CHARTYPE_TRANSCODER
chartype_lookup_transcoder(const CHARTYPE *from, const CHARTYPE *to)
{
CHARTYPE_TRANSCODER transcoder;
if ((transcoder = from->transcode_to(to->name)) == NULL) {
transcoder = to->transcode_from(from->name);
}
return transcoder;
}
/*
* Local variables:
* c-indentation-style: bsd
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*
* vim: expandtab shiftwidth=4:
*/