]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ********************************************************************** | |
4388f060 | 3 | * Copyright (C) 1999-2011, International Business Machines |
b75a7d8f A |
4 | * Corporation and others. All Rights Reserved. |
5 | ********************************************************************** | |
6 | * file name: ustr_imp.h | |
7 | * encoding: US-ASCII | |
8 | * tab size: 8 (not used) | |
9 | * indentation:4 | |
10 | * | |
11 | * created on: 2001jan30 | |
12 | * created by: Markus W. Scherer | |
13 | */ | |
14 | ||
15 | #ifndef __USTR_IMP_H__ | |
16 | #define __USTR_IMP_H__ | |
17 | ||
18 | #include "unicode/utypes.h" | |
b75a7d8f | 19 | #include "unicode/uiter.h" |
374ca955 | 20 | #include "ucase.h" |
b75a7d8f | 21 | |
4388f060 | 22 | /** Simple declaration to avoid including unicode/ubrk.h. */ |
b75a7d8f A |
23 | #ifndef UBRK_TYPEDEF_UBREAK_ITERATOR |
24 | # define UBRK_TYPEDEF_UBREAK_ITERATOR | |
729e4ab9 | 25 | typedef struct UBreakIterator UBreakIterator; |
b75a7d8f A |
26 | #endif |
27 | ||
729e4ab9 A |
28 | #ifndef U_COMPARE_IGNORE_CASE |
29 | /* see also unorm.h */ | |
30 | /** | |
31 | * Option bit for unorm_compare: | |
32 | * Perform case-insensitive comparison. | |
729e4ab9 A |
33 | */ |
34 | #define U_COMPARE_IGNORE_CASE 0x10000 | |
35 | #endif | |
36 | ||
37 | /** | |
38 | * Internal option for unorm_cmpEquivFold() for strncmp style. | |
39 | * If set, checks for both string length and terminating NUL. | |
729e4ab9 A |
40 | */ |
41 | #define _STRNCMP_STYLE 0x1000 | |
42 | ||
b75a7d8f A |
43 | /** |
44 | * Compare two strings in code point order or code unit order. | |
45 | * Works in strcmp style (both lengths -1), | |
46 | * strncmp style (lengths equal and >=0, flag TRUE), | |
47 | * and memcmp/UnicodeString style (at least one length >=0). | |
b75a7d8f | 48 | */ |
46f4442e | 49 | U_CFUNC int32_t U_EXPORT2 |
b75a7d8f A |
50 | uprv_strCompare(const UChar *s1, int32_t length1, |
51 | const UChar *s2, int32_t length2, | |
52 | UBool strncmpStyle, UBool codePointOrder); | |
53 | ||
374ca955 A |
54 | /** |
55 | * Internal API, used by u_strcasecmp() etc. | |
56 | * Compare strings case-insensitively, | |
57 | * in code point order or code unit order. | |
374ca955 A |
58 | */ |
59 | U_CFUNC int32_t | |
60 | u_strcmpFold(const UChar *s1, int32_t length1, | |
61 | const UChar *s2, int32_t length2, | |
62 | uint32_t options, | |
63 | UErrorCode *pErrorCode); | |
64 | ||
b75a7d8f A |
65 | /** |
66 | * Are the Unicode properties loaded? | |
67 | * This must be used before internal functions are called that do | |
68 | * not perform this check. | |
729e4ab9 | 69 | * Generate a debug assertion failure if data is not loaded. |
b75a7d8f A |
70 | */ |
71 | U_CFUNC UBool | |
72 | uprv_haveProperties(UErrorCode *pErrorCode); | |
73 | ||
374ca955 A |
74 | /** |
75 | * Load the Unicode property data. | |
76 | * Intended primarily for use from u_init(). | |
77 | * Has no effect if property data is already loaded. | |
78 | * NOT thread safe. | |
374ca955 | 79 | */ |
73c04bcf A |
80 | /*U_CFUNC int8_t |
81 | uprv_loadPropsData(UErrorCode *errorCode);*/ | |
374ca955 | 82 | |
b75a7d8f A |
83 | /* |
84 | * Internal string casing functions implementing | |
85 | * ustring.h/ustrcase.c and UnicodeString case mapping functions. | |
374ca955 A |
86 | */ |
87 | ||
46f4442e A |
88 | struct UCaseMap { |
89 | const UCaseProps *csp; | |
90 | #if !UCONFIG_NO_BREAK_ITERATION | |
91 | UBreakIterator *iter; /* We adopt the iterator, so we own it. */ | |
92 | #endif | |
93 | char locale[32]; | |
94 | int32_t locCache; | |
95 | uint32_t options; | |
96 | }; | |
97 | ||
98 | #ifndef __UCASEMAP_H__ | |
99 | typedef struct UCaseMap UCaseMap; | |
100 | #endif | |
101 | ||
4388f060 A |
102 | #if UCONFIG_NO_BREAK_ITERATION |
103 | # define UCASEMAP_INITIALIZER { NULL, { 0 }, 0, 0 } | |
104 | #else | |
105 | # define UCASEMAP_INITIALIZER { NULL, NULL, { 0 }, 0, 0 } | |
106 | #endif | |
107 | ||
108 | U_CFUNC void | |
109 | ustrcase_setTempCaseMapLocale(UCaseMap *csm, const char *locale); | |
110 | ||
111 | #ifndef U_STRING_CASE_MAPPER_DEFINED | |
112 | #define U_STRING_CASE_MAPPER_DEFINED | |
113 | ||
46f4442e | 114 | /** |
4388f060 A |
115 | * String case mapping function type, used by ustrcase_map(). |
116 | * All error checking must be done. | |
117 | * The UCaseMap must be fully initialized, with locale and/or iter set as needed. | |
118 | * src and dest must not overlap. | |
46f4442e | 119 | */ |
4388f060 A |
120 | typedef int32_t U_CALLCONV |
121 | UStringCaseMapper(const UCaseMap *csm, | |
122 | UChar *dest, int32_t destCapacity, | |
123 | const UChar *src, int32_t srcLength, | |
124 | UErrorCode *pErrorCode); | |
125 | ||
126 | #endif | |
127 | ||
128 | /** Implements UStringCaseMapper. */ | |
129 | U_CFUNC int32_t U_CALLCONV | |
130 | ustrcase_internalToLower(const UCaseMap *csm, | |
131 | UChar *dest, int32_t destCapacity, | |
132 | const UChar *src, int32_t srcLength, | |
133 | UErrorCode *pErrorCode); | |
134 | ||
135 | /** Implements UStringCaseMapper. */ | |
136 | U_CFUNC int32_t U_CALLCONV | |
137 | ustrcase_internalToUpper(const UCaseMap *csm, | |
138 | UChar *dest, int32_t destCapacity, | |
139 | const UChar *src, int32_t srcLength, | |
140 | UErrorCode *pErrorCode); | |
141 | ||
142 | #if !UCONFIG_NO_BREAK_ITERATION | |
143 | ||
144 | /** Implements UStringCaseMapper. */ | |
145 | U_CFUNC int32_t U_CALLCONV | |
146 | ustrcase_internalToTitle(const UCaseMap *csm, | |
147 | UChar *dest, int32_t destCapacity, | |
148 | const UChar *src, int32_t srcLength, | |
149 | UErrorCode *pErrorCode); | |
150 | ||
151 | #endif | |
152 | ||
153 | /** Implements UStringCaseMapper. */ | |
154 | U_CFUNC int32_t U_CALLCONV | |
155 | ustrcase_internalFold(const UCaseMap *csm, | |
156 | UChar *dest, int32_t destCapacity, | |
157 | const UChar *src, int32_t srcLength, | |
158 | UErrorCode *pErrorCode); | |
46f4442e | 159 | |
374ca955 | 160 | /** |
4388f060 A |
161 | * Implements argument checking and buffer handling |
162 | * for string case mapping as a common function. | |
b75a7d8f A |
163 | */ |
164 | U_CFUNC int32_t | |
4388f060 | 165 | ustrcase_map(const UCaseMap *csm, |
374ca955 A |
166 | UChar *dest, int32_t destCapacity, |
167 | const UChar *src, int32_t srcLength, | |
4388f060 | 168 | UStringCaseMapper *stringCaseMapper, |
374ca955 | 169 | UErrorCode *pErrorCode); |
b75a7d8f A |
170 | |
171 | /** | |
4388f060 A |
172 | * UTF-8 string case mapping function type, used by ucasemap_mapUTF8(). |
173 | * UTF-8 version of UStringCaseMapper. | |
174 | * All error checking must be done. | |
175 | * The UCaseMap must be fully initialized, with locale and/or iter set as needed. | |
176 | * src and dest must not overlap. | |
b75a7d8f | 177 | */ |
4388f060 A |
178 | typedef int32_t U_CALLCONV |
179 | UTF8CaseMapper(const UCaseMap *csm, | |
180 | uint8_t *dest, int32_t destCapacity, | |
181 | const uint8_t *src, int32_t srcLength, | |
182 | UErrorCode *pErrorCode); | |
b75a7d8f | 183 | |
4388f060 A |
184 | /** Implements UTF8CaseMapper. */ |
185 | U_CFUNC int32_t U_CALLCONV | |
186 | ucasemap_internalUTF8ToTitle(const UCaseMap *csm, | |
187 | uint8_t *dest, int32_t destCapacity, | |
188 | const uint8_t *src, int32_t srcLength, | |
189 | UErrorCode *pErrorCode); | |
b75a7d8f A |
190 | |
191 | /** | |
4388f060 A |
192 | * Implements argument checking and buffer handling |
193 | * for UTF-8 string case mapping as a common function. | |
b75a7d8f A |
194 | */ |
195 | U_CFUNC int32_t | |
4388f060 A |
196 | ucasemap_mapUTF8(const UCaseMap *csm, |
197 | uint8_t *dest, int32_t destCapacity, | |
198 | const uint8_t *src, int32_t srcLength, | |
199 | UTF8CaseMapper *stringCaseMapper, | |
200 | UErrorCode *pErrorCode); | |
b75a7d8f | 201 | |
4388f060 A |
202 | U_CAPI int32_t U_EXPORT2 |
203 | ustr_hashUCharsN(const UChar *str, int32_t length); | |
b75a7d8f | 204 | |
4388f060 A |
205 | U_CAPI int32_t U_EXPORT2 |
206 | ustr_hashCharsN(const char *str, int32_t length); | |
207 | ||
208 | U_CAPI int32_t U_EXPORT2 | |
209 | ustr_hashICharsN(const char *str, int32_t length); | |
b75a7d8f A |
210 | |
211 | /** | |
212 | * NUL-terminate a UChar * string if possible. | |
213 | * If length < destCapacity then NUL-terminate. | |
214 | * If length == destCapacity then do not terminate but set U_STRING_NOT_TERMINATED_WARNING. | |
215 | * If length > destCapacity then do not terminate but set U_BUFFER_OVERFLOW_ERROR. | |
216 | * | |
217 | * @param dest Destination buffer, can be NULL if destCapacity==0. | |
218 | * @param destCapacity Number of UChars available at dest. | |
219 | * @param length Number of UChars that were (to be) written to dest. | |
220 | * @param pErrorCode ICU error code. | |
221 | * @return length | |
b75a7d8f A |
222 | */ |
223 | U_CAPI int32_t U_EXPORT2 | |
224 | u_terminateUChars(UChar *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); | |
225 | ||
226 | /** | |
227 | * NUL-terminate a char * string if possible. | |
228 | * Same as u_terminateUChars() but for a different string type. | |
229 | */ | |
230 | U_CAPI int32_t U_EXPORT2 | |
231 | u_terminateChars(char *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); | |
232 | ||
233 | /** | |
234 | * NUL-terminate a UChar32 * string if possible. | |
235 | * Same as u_terminateUChars() but for a different string type. | |
236 | */ | |
237 | U_CAPI int32_t U_EXPORT2 | |
238 | u_terminateUChar32s(UChar32 *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); | |
239 | ||
240 | /** | |
241 | * NUL-terminate a wchar_t * string if possible. | |
242 | * Same as u_terminateUChars() but for a different string type. | |
243 | */ | |
244 | U_CAPI int32_t U_EXPORT2 | |
245 | u_terminateWChars(wchar_t *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); | |
246 | ||
b75a7d8f | 247 | #endif |