1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (C) 1999-2015, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
8 * file name: ustr_imp.h
10 * tab size: 8 (not used)
13 * created on: 2001jan30
14 * created by: Markus W. Scherer
17 #ifndef __USTR_IMP_H__
18 #define __USTR_IMP_H__
20 #include "unicode/utypes.h"
21 #include "unicode/uiter.h"
24 /** Simple declaration to avoid including unicode/ubrk.h. */
25 #ifndef UBRK_TYPEDEF_UBREAK_ITERATOR
26 # define UBRK_TYPEDEF_UBREAK_ITERATOR
27 typedef struct UBreakIterator UBreakIterator;
30 #ifndef U_COMPARE_IGNORE_CASE
31 /* see also unorm.h */
33 * Option bit for unorm_compare:
34 * Perform case-insensitive comparison.
36 #define U_COMPARE_IGNORE_CASE 0x10000
40 * Internal option for unorm_cmpEquivFold() for strncmp style.
41 * If set, checks for both string length and terminating NUL.
43 #define _STRNCMP_STYLE 0x1000
46 * Compare two strings in code point order or code unit order.
47 * Works in strcmp style (both lengths -1),
48 * strncmp style (lengths equal and >=0, flag TRUE),
49 * and memcmp/UnicodeString style (at least one length >=0).
51 U_CFUNC int32_t U_EXPORT2
52 uprv_strCompare(const UChar *s1, int32_t length1,
53 const UChar *s2, int32_t length2,
54 UBool strncmpStyle, UBool codePointOrder);
57 * Internal API, used by u_strcasecmp() etc.
58 * Compare strings case-insensitively,
59 * in code point order or code unit order.
62 u_strcmpFold(const UChar *s1, int32_t length1,
63 const UChar *s2, int32_t length2,
65 UErrorCode *pErrorCode);
68 * Interanl API, used for detecting length of
69 * shared prefix case-insensitively.
70 * @param s1 input string 1
71 * @param length1 length of string 1, or -1 (NULL terminated)
72 * @param s2 input string 2
73 * @param length2 length of string 2, or -1 (NULL terminated)
74 * @param options compare options
75 * @param matchLen1 (output) length of partial prefix match in s1
76 * @param matchLen2 (output) length of partial prefix match in s2
77 * @param pErrorCode receives error status
80 u_caseInsensitivePrefixMatch(const UChar *s1, int32_t length1,
81 const UChar *s2, int32_t length2,
83 int32_t *matchLen1, int32_t *matchLen2,
84 UErrorCode *pErrorCode);
87 * Are the Unicode properties loaded?
88 * This must be used before internal functions are called that do
89 * not perform this check.
90 * Generate a debug assertion failure if data is not loaded.
93 uprv_haveProperties(UErrorCode *pErrorCode);
96 * Load the Unicode property data.
97 * Intended primarily for use from u_init().
98 * Has no effect if property data is already loaded.
102 uprv_loadPropsData(UErrorCode *errorCode);*/
105 * Internal string casing functions implementing
106 * ustring.h/ustrcase.c and UnicodeString case mapping functions.
110 const UCaseProps *csp;
111 #if !UCONFIG_NO_BREAK_ITERATION
112 UBreakIterator *iter; /* We adopt the iterator, so we own it. */
119 #ifndef __UCASEMAP_H__
120 typedef struct UCaseMap UCaseMap;
123 #if UCONFIG_NO_BREAK_ITERATION
124 # define UCASEMAP_INITIALIZER { NULL, { 0 }, 0, 0 }
126 # define UCASEMAP_INITIALIZER { NULL, NULL, { 0 }, 0, 0 }
130 ustrcase_setTempCaseMapLocale(UCaseMap *csm, const char *locale);
132 #ifndef U_STRING_CASE_MAPPER_DEFINED
133 #define U_STRING_CASE_MAPPER_DEFINED
136 * String case mapping function type, used by ustrcase_map().
137 * All error checking must be done.
138 * The UCaseMap must be fully initialized, with locale and/or iter set as needed.
139 * src and dest must not overlap.
141 typedef int32_t U_CALLCONV
142 UStringCaseMapper(const UCaseMap *csm,
143 UChar *dest, int32_t destCapacity,
144 const UChar *src, int32_t srcLength,
145 UErrorCode *pErrorCode);
149 /** Implements UStringCaseMapper. */
150 U_CFUNC int32_t U_CALLCONV
151 ustrcase_internalToLower(const UCaseMap *csm,
152 UChar *dest, int32_t destCapacity,
153 const UChar *src, int32_t srcLength,
154 UErrorCode *pErrorCode);
156 /** Implements UStringCaseMapper. */
157 U_CFUNC int32_t U_CALLCONV
158 ustrcase_internalToUpper(const UCaseMap *csm,
159 UChar *dest, int32_t destCapacity,
160 const UChar *src, int32_t srcLength,
161 UErrorCode *pErrorCode);
163 #if !UCONFIG_NO_BREAK_ITERATION
165 /** Implements UStringCaseMapper. */
166 U_CFUNC int32_t U_CALLCONV
167 ustrcase_internalToTitle(const UCaseMap *csm,
168 UChar *dest, int32_t destCapacity,
169 const UChar *src, int32_t srcLength,
170 UErrorCode *pErrorCode);
174 /** Implements UStringCaseMapper. */
175 U_CFUNC int32_t U_CALLCONV
176 ustrcase_internalFold(const UCaseMap *csm,
177 UChar *dest, int32_t destCapacity,
178 const UChar *src, int32_t srcLength,
179 UErrorCode *pErrorCode);
182 * Implements argument checking and buffer handling
183 * for string case mapping as a common function.
186 ustrcase_map(const UCaseMap *csm,
187 UChar *dest, int32_t destCapacity,
188 const UChar *src, int32_t srcLength,
189 UStringCaseMapper *stringCaseMapper,
190 UErrorCode *pErrorCode);
193 * UTF-8 string case mapping function type, used by ucasemap_mapUTF8().
194 * UTF-8 version of UStringCaseMapper.
195 * All error checking must be done.
196 * The UCaseMap must be fully initialized, with locale and/or iter set as needed.
197 * src and dest must not overlap.
199 typedef int32_t U_CALLCONV
200 UTF8CaseMapper(const UCaseMap *csm,
201 uint8_t *dest, int32_t destCapacity,
202 const uint8_t *src, int32_t srcLength,
203 UErrorCode *pErrorCode);
205 /** Implements UTF8CaseMapper. */
206 U_CFUNC int32_t U_CALLCONV
207 ucasemap_internalUTF8ToTitle(const UCaseMap *csm,
208 uint8_t *dest, int32_t destCapacity,
209 const uint8_t *src, int32_t srcLength,
210 UErrorCode *pErrorCode);
213 * Implements argument checking and buffer handling
214 * for UTF-8 string case mapping as a common function.
217 ucasemap_mapUTF8(const UCaseMap *csm,
218 uint8_t *dest, int32_t destCapacity,
219 const uint8_t *src, int32_t srcLength,
220 UTF8CaseMapper *stringCaseMapper,
221 UErrorCode *pErrorCode);
226 namespace GreekUpper {
229 static const uint32_t UPPER_MASK = 0x3ff;
230 static const uint32_t HAS_VOWEL = 0x1000;
231 static const uint32_t HAS_YPOGEGRAMMENI = 0x2000;
232 static const uint32_t HAS_ACCENT = 0x4000;
233 static const uint32_t HAS_DIALYTIKA = 0x8000;
234 // Further bits during data building and processing, not stored in the data map.
235 static const uint32_t HAS_COMBINING_DIALYTIKA = 0x10000;
236 static const uint32_t HAS_OTHER_GREEK_DIACRITIC = 0x20000;
238 static const uint32_t HAS_VOWEL_AND_ACCENT = HAS_VOWEL | HAS_ACCENT;
239 static const uint32_t HAS_VOWEL_AND_ACCENT_AND_DIALYTIKA =
240 HAS_VOWEL_AND_ACCENT | HAS_DIALYTIKA;
241 static const uint32_t HAS_EITHER_DIALYTIKA = HAS_DIALYTIKA | HAS_COMBINING_DIALYTIKA;
244 static const uint32_t AFTER_CASED = 1;
245 static const uint32_t AFTER_VOWEL_WITH_ACCENT = 2;
247 uint32_t getLetterData(UChar32 c);
250 * Returns a non-zero value for each of the Greek combining diacritics
251 * listed in The Unicode Standard, version 8, chapter 7.2 Greek,
252 * plus some perispomeni look-alikes.
254 uint32_t getDiacriticData(UChar32 c);
256 } // namespace GreekUpper
259 #endif // __cplusplus
261 U_CAPI int32_t U_EXPORT2
262 ustr_hashUCharsN(const UChar *str, int32_t length);
264 U_CAPI int32_t U_EXPORT2
265 ustr_hashCharsN(const char *str, int32_t length);
267 U_CAPI int32_t U_EXPORT2
268 ustr_hashICharsN(const char *str, int32_t length);
271 * NUL-terminate a UChar * string if possible.
272 * If length < destCapacity then NUL-terminate.
273 * If length == destCapacity then do not terminate but set U_STRING_NOT_TERMINATED_WARNING.
274 * If length > destCapacity then do not terminate but set U_BUFFER_OVERFLOW_ERROR.
276 * @param dest Destination buffer, can be NULL if destCapacity==0.
277 * @param destCapacity Number of UChars available at dest.
278 * @param length Number of UChars that were (to be) written to dest.
279 * @param pErrorCode ICU error code.
282 U_CAPI int32_t U_EXPORT2
283 u_terminateUChars(UChar *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode);
286 * NUL-terminate a char * string if possible.
287 * Same as u_terminateUChars() but for a different string type.
289 U_CAPI int32_t U_EXPORT2
290 u_terminateChars(char *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode);
293 * NUL-terminate a UChar32 * string if possible.
294 * Same as u_terminateUChars() but for a different string type.
296 U_CAPI int32_t U_EXPORT2
297 u_terminateUChar32s(UChar32 *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode);
300 * NUL-terminate a wchar_t * string if possible.
301 * Same as u_terminateUChars() but for a different string type.
303 U_CAPI int32_t U_EXPORT2
304 u_terminateWChars(wchar_t *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode);