2 **********************************************************************
3 * Copyright (C) 1999-2015, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 * file name: ustr_imp.h
8 * tab size: 8 (not used)
11 * created on: 2001jan30
12 * created by: Markus W. Scherer
15 #ifndef __USTR_IMP_H__
16 #define __USTR_IMP_H__
18 #include "unicode/utypes.h"
19 #include "unicode/uiter.h"
22 /** Simple declaration to avoid including unicode/ubrk.h. */
23 #ifndef UBRK_TYPEDEF_UBREAK_ITERATOR
24 # define UBRK_TYPEDEF_UBREAK_ITERATOR
25 typedef struct UBreakIterator UBreakIterator
;
28 #ifndef U_COMPARE_IGNORE_CASE
29 /* see also unorm.h */
31 * Option bit for unorm_compare:
32 * Perform case-insensitive comparison.
34 #define U_COMPARE_IGNORE_CASE 0x10000
38 * Internal option for unorm_cmpEquivFold() for strncmp style.
39 * If set, checks for both string length and terminating NUL.
41 #define _STRNCMP_STYLE 0x1000
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).
49 U_CFUNC
int32_t U_EXPORT2
50 uprv_strCompare(const UChar
*s1
, int32_t length1
,
51 const UChar
*s2
, int32_t length2
,
52 UBool strncmpStyle
, UBool codePointOrder
);
55 * Internal API, used by u_strcasecmp() etc.
56 * Compare strings case-insensitively,
57 * in code point order or code unit order.
60 u_strcmpFold(const UChar
*s1
, int32_t length1
,
61 const UChar
*s2
, int32_t length2
,
63 UErrorCode
*pErrorCode
);
66 * Interanl API, used for detecting length of
67 * shared prefix case-insensitively.
68 * @param s1 input string 1
69 * @param length1 length of string 1, or -1 (NULL terminated)
70 * @param s2 input string 2
71 * @param length2 length of string 2, or -1 (NULL terminated)
72 * @param options compare options
73 * @param matchLen1 (output) length of partial prefix match in s1
74 * @param matchLen2 (output) length of partial prefix match in s2
75 * @param pErrorCode receives error status
78 u_caseInsensitivePrefixMatch(const UChar
*s1
, int32_t length1
,
79 const UChar
*s2
, int32_t length2
,
81 int32_t *matchLen1
, int32_t *matchLen2
,
82 UErrorCode
*pErrorCode
);
85 * Are the Unicode properties loaded?
86 * This must be used before internal functions are called that do
87 * not perform this check.
88 * Generate a debug assertion failure if data is not loaded.
91 uprv_haveProperties(UErrorCode
*pErrorCode
);
94 * Load the Unicode property data.
95 * Intended primarily for use from u_init().
96 * Has no effect if property data is already loaded.
100 uprv_loadPropsData(UErrorCode *errorCode);*/
103 * Internal string casing functions implementing
104 * ustring.h/ustrcase.c and UnicodeString case mapping functions.
108 const UCaseProps
*csp
;
109 #if !UCONFIG_NO_BREAK_ITERATION
110 UBreakIterator
*iter
; /* We adopt the iterator, so we own it. */
117 #ifndef __UCASEMAP_H__
118 typedef struct UCaseMap UCaseMap
;
121 #if UCONFIG_NO_BREAK_ITERATION
122 # define UCASEMAP_INITIALIZER { NULL, { 0 }, 0, 0 }
124 # define UCASEMAP_INITIALIZER { NULL, NULL, { 0 }, 0, 0 }
128 ustrcase_setTempCaseMapLocale(UCaseMap
*csm
, const char *locale
);
130 #ifndef U_STRING_CASE_MAPPER_DEFINED
131 #define U_STRING_CASE_MAPPER_DEFINED
134 * String case mapping function type, used by ustrcase_map().
135 * All error checking must be done.
136 * The UCaseMap must be fully initialized, with locale and/or iter set as needed.
137 * src and dest must not overlap.
139 typedef int32_t U_CALLCONV
140 UStringCaseMapper(const UCaseMap
*csm
,
141 UChar
*dest
, int32_t destCapacity
,
142 const UChar
*src
, int32_t srcLength
,
143 UErrorCode
*pErrorCode
);
147 /** Implements UStringCaseMapper. */
148 U_CFUNC
int32_t U_CALLCONV
149 ustrcase_internalToLower(const UCaseMap
*csm
,
150 UChar
*dest
, int32_t destCapacity
,
151 const UChar
*src
, int32_t srcLength
,
152 UErrorCode
*pErrorCode
);
154 /** Implements UStringCaseMapper. */
155 U_CFUNC
int32_t U_CALLCONV
156 ustrcase_internalToUpper(const UCaseMap
*csm
,
157 UChar
*dest
, int32_t destCapacity
,
158 const UChar
*src
, int32_t srcLength
,
159 UErrorCode
*pErrorCode
);
161 #if !UCONFIG_NO_BREAK_ITERATION
163 /** Implements UStringCaseMapper. */
164 U_CFUNC
int32_t U_CALLCONV
165 ustrcase_internalToTitle(const UCaseMap
*csm
,
166 UChar
*dest
, int32_t destCapacity
,
167 const UChar
*src
, int32_t srcLength
,
168 UErrorCode
*pErrorCode
);
172 /** Implements UStringCaseMapper. */
173 U_CFUNC
int32_t U_CALLCONV
174 ustrcase_internalFold(const UCaseMap
*csm
,
175 UChar
*dest
, int32_t destCapacity
,
176 const UChar
*src
, int32_t srcLength
,
177 UErrorCode
*pErrorCode
);
180 * Implements argument checking and buffer handling
181 * for string case mapping as a common function.
184 ustrcase_map(const UCaseMap
*csm
,
185 UChar
*dest
, int32_t destCapacity
,
186 const UChar
*src
, int32_t srcLength
,
187 UStringCaseMapper
*stringCaseMapper
,
188 UErrorCode
*pErrorCode
);
191 * UTF-8 string case mapping function type, used by ucasemap_mapUTF8().
192 * UTF-8 version of UStringCaseMapper.
193 * All error checking must be done.
194 * The UCaseMap must be fully initialized, with locale and/or iter set as needed.
195 * src and dest must not overlap.
197 typedef int32_t U_CALLCONV
198 UTF8CaseMapper(const UCaseMap
*csm
,
199 uint8_t *dest
, int32_t destCapacity
,
200 const uint8_t *src
, int32_t srcLength
,
201 UErrorCode
*pErrorCode
);
203 /** Implements UTF8CaseMapper. */
204 U_CFUNC
int32_t U_CALLCONV
205 ucasemap_internalUTF8ToTitle(const UCaseMap
*csm
,
206 uint8_t *dest
, int32_t destCapacity
,
207 const uint8_t *src
, int32_t srcLength
,
208 UErrorCode
*pErrorCode
);
211 * Implements argument checking and buffer handling
212 * for UTF-8 string case mapping as a common function.
215 ucasemap_mapUTF8(const UCaseMap
*csm
,
216 uint8_t *dest
, int32_t destCapacity
,
217 const uint8_t *src
, int32_t srcLength
,
218 UTF8CaseMapper
*stringCaseMapper
,
219 UErrorCode
*pErrorCode
);
221 U_CAPI
int32_t U_EXPORT2
222 ustr_hashUCharsN(const UChar
*str
, int32_t length
);
224 U_CAPI
int32_t U_EXPORT2
225 ustr_hashCharsN(const char *str
, int32_t length
);
227 U_CAPI
int32_t U_EXPORT2
228 ustr_hashICharsN(const char *str
, int32_t length
);
231 * NUL-terminate a UChar * string if possible.
232 * If length < destCapacity then NUL-terminate.
233 * If length == destCapacity then do not terminate but set U_STRING_NOT_TERMINATED_WARNING.
234 * If length > destCapacity then do not terminate but set U_BUFFER_OVERFLOW_ERROR.
236 * @param dest Destination buffer, can be NULL if destCapacity==0.
237 * @param destCapacity Number of UChars available at dest.
238 * @param length Number of UChars that were (to be) written to dest.
239 * @param pErrorCode ICU error code.
242 U_CAPI
int32_t U_EXPORT2
243 u_terminateUChars(UChar
*dest
, int32_t destCapacity
, int32_t length
, UErrorCode
*pErrorCode
);
246 * NUL-terminate a char * string if possible.
247 * Same as u_terminateUChars() but for a different string type.
249 U_CAPI
int32_t U_EXPORT2
250 u_terminateChars(char *dest
, int32_t destCapacity
, int32_t length
, UErrorCode
*pErrorCode
);
253 * NUL-terminate a UChar32 * string if possible.
254 * Same as u_terminateUChars() but for a different string type.
256 U_CAPI
int32_t U_EXPORT2
257 u_terminateUChar32s(UChar32
*dest
, int32_t destCapacity
, int32_t length
, UErrorCode
*pErrorCode
);
260 * NUL-terminate a wchar_t * string if possible.
261 * Same as u_terminateUChars() but for a different string type.
263 U_CAPI
int32_t U_EXPORT2
264 u_terminateWChars(wchar_t *dest
, int32_t destCapacity
, int32_t length
, UErrorCode
*pErrorCode
);