1 --- icu/source/common/uchar.c.orig 2009-04-30 18:01:03.553019868 +0800 |
|
2 +++ icu/source/common/uchar.c 2009-04-30 18:03:57.598557863 +0800 |
|
3 @@ -580,6 +580,79 @@ |
|
4 u_isIDIgnorable(c)); |
|
5 } |
|
6 |
|
7 +/* Transforms the Unicode character to its lower case equivalent.*/ |
|
8 +U_CAPI UChar32 U_EXPORT2 |
|
9 +u_tolower(UChar32 c) { |
|
10 + uint32_t props; |
|
11 + GET_PROPS(c, props); |
|
12 + if(!PROPS_VALUE_IS_EXCEPTION(props)) { |
|
13 + if(CAT_MASK(props)&(U_GC_LU_MASK|U_GC_LT_MASK)) { |
|
14 + return c+GET_SIGNED_VALUE(props); |
|
15 + } |
|
16 + } else { |
|
17 + const uint32_t *pe=GET_EXCEPTIONS(props); |
|
18 + uint32_t firstExceptionValue=*pe; |
|
19 + if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_LOWERCASE)) { |
|
20 + int i=EXC_LOWERCASE; |
|
21 + ++pe; |
|
22 + ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe); |
|
23 + return (UChar32)*pe; |
|
24 + } |
|
25 + } |
|
26 + return c; /* no mapping - return c itself */ |
|
27 +} |
|
28 + |
|
29 +/* Transforms the Unicode character to its upper case equivalent.*/ |
|
30 +U_CAPI UChar32 U_EXPORT2 |
|
31 +u_toupper(UChar32 c) { |
|
32 + uint32_t props; |
|
33 + GET_PROPS(c, props); |
|
34 + if(!PROPS_VALUE_IS_EXCEPTION(props)) { |
|
35 + if(GET_CATEGORY(props)==U_LOWERCASE_LETTER) { |
|
36 + return c-GET_SIGNED_VALUE(props); |
|
37 + } |
|
38 + } else { |
|
39 + const uint32_t *pe=GET_EXCEPTIONS(props); |
|
40 + uint32_t firstExceptionValue=*pe; |
|
41 + if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_UPPERCASE)) { |
|
42 + int i=EXC_UPPERCASE; |
|
43 + ++pe; |
|
44 + ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe); |
|
45 + return (UChar32)*pe; |
|
46 + } |
|
47 + } |
|
48 + return c; /* no mapping - return c itself */ |
|
49 +} |
|
50 + |
|
51 +/* Transforms the Unicode character to its title case equivalent.*/ |
|
52 +U_CAPI UChar32 U_EXPORT2 |
|
53 +u_totitle(UChar32 c) { |
|
54 + uint32_t props; |
|
55 + GET_PROPS(c, props); |
|
56 + if(!PROPS_VALUE_IS_EXCEPTION(props)) { |
|
57 + if(GET_CATEGORY(props)==U_LOWERCASE_LETTER) { |
|
58 + /* here, titlecase is same as uppercase */ |
|
59 + return c-GET_SIGNED_VALUE(props); |
|
60 + } |
|
61 + } else { |
|
62 + const uint32_t *pe=GET_EXCEPTIONS(props); |
|
63 + uint32_t firstExceptionValue=*pe; |
|
64 + if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_TITLECASE)) { |
|
65 + int i=EXC_TITLECASE; |
|
66 + ++pe; |
|
67 + ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe); |
|
68 + return (UChar32)*pe; |
|
69 + } else if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_UPPERCASE)) { |
|
70 + /* here, titlecase is same as uppercase */ |
|
71 + int i=EXC_UPPERCASE; |
|
72 + ++pe; |
|
73 + ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe); |
|
74 + return (UChar32)*pe; |
|
75 + } |
|
76 + } |
|
77 + return c; /* no mapping - return c itself */ |
|
78 +} |
|
79 + |
|
80 U_CAPI int32_t U_EXPORT2 |
|
81 u_charDigitValue(UChar32 c) { |
|
82 uint32_t props; |
|
83 @@ -977,3 +1050,79 @@ |
|
84 utrie_enum(&propsVectorsTrie, NULL, _enumPropertyStartsRange, sa); |
|
85 } |
|
86 } |
|
87 + |
|
88 +/* return the simple case folding mapping for c */ |
|
89 +U_CAPI UChar32 U_EXPORT2 |
|
90 +u_foldCase(UChar32 c, uint32_t options) { |
|
91 + uint32_t props; |
|
92 + GET_PROPS(c, props); |
|
93 + if(!PROPS_VALUE_IS_EXCEPTION(props)) { |
|
94 + if(CAT_MASK(props)&(U_GC_LU_MASK|U_GC_LT_MASK)) { |
|
95 + return c+GET_SIGNED_VALUE(props); |
|
96 + } |
|
97 + } else { |
|
98 + const uint32_t *pe=GET_EXCEPTIONS(props); |
|
99 + uint32_t firstExceptionValue=*pe; |
|
100 + if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_CASE_FOLDING)) { |
|
101 + const uint32_t *oldPE=pe; |
|
102 + int i=EXC_CASE_FOLDING; |
|
103 + ++pe; |
|
104 + ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe); |
|
105 + props=*pe; |
|
106 + if(props!=0) { |
|
107 + /* return the simple mapping, if there is one */ |
|
108 + const UChar *uchars=ucharsTable+(props&0xffff); |
|
109 + UChar32 simple; |
|
110 + i=0; |
|
111 + UTF_NEXT_CHAR_UNSAFE(uchars, i, simple); |
|
112 + if(simple!=0) { |
|
113 + return simple; |
|
114 + } |
|
115 + /* fall through to use the lowercase exception value if there is no simple mapping */ |
|
116 + pe=oldPE; |
|
117 + } else { |
|
118 + /* special case folding mappings, hardcoded */ |
|
119 + if((options&_FOLD_CASE_OPTIONS_MASK)==U_FOLD_CASE_DEFAULT) { |
|
120 + /* default mappings */ |
|
121 + if(c==0x49) { |
|
122 + /* 0049; C; 0069; # LATIN CAPITAL LETTER I */ |
|
123 + return 0x69; |
|
124 + } else if(c==0x130) { |
|
125 + /* no simple default mapping for U+0130, use UnicodeData.txt */ |
|
126 + return 0x69; |
|
127 + } |
|
128 + } else { |
|
129 + /* Turkic mappings */ |
|
130 + if(c==0x49) { |
|
131 + /* 0049; T; 0131; # LATIN CAPITAL LETTER I */ |
|
132 + return 0x131; |
|
133 + } else if(c==0x130) { |
|
134 + /* 0130; T; 0069; # LATIN CAPITAL LETTER I WITH DOT ABOVE */ |
|
135 + return 0x69; |
|
136 + } |
|
137 + } |
|
138 + /* return c itself because there is no special mapping for it */ |
|
139 + return c; |
|
140 + } |
|
141 + } |
|
142 + /* not else! - allow to fall through from above */ |
|
143 + if(HAVE_EXCEPTION_VALUE(firstExceptionValue, EXC_LOWERCASE)) { |
|
144 + int i=EXC_LOWERCASE; |
|
145 + ++pe; |
|
146 + ADD_EXCEPTION_OFFSET(firstExceptionValue, i, pe); |
|
147 + return (UChar32)*pe; |
|
148 + } |
|
149 + } |
|
150 + return c; /* no mapping - return c itself */ |
|
151 +} |
|
152 + |
|
153 +U_CAPI UBool U_EXPORT2 |
|
154 +u_isULowercase(UChar32 c) { |
|
155 + return u_hasBinaryProperty(c, UCHAR_LOWERCASE); |
|
156 +} |
|
157 + |
|
158 +U_CAPI UBool U_EXPORT2 |
|
159 +u_isUUppercase(UChar32 c) { |
|
160 + return u_hasBinaryProperty(c, UCHAR_UPPERCASE); |
|
161 +} |
|
162 + |
|