2 **********************************************************************
3 * Copyright (C) 1999-2011, 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 * Are the Unicode properties loaded?
67 * This must be used before internal functions are called that do
68 * not perform this check.
69 * Generate a debug assertion failure if data is not loaded.
72 uprv_haveProperties(UErrorCode
*pErrorCode
);
75 * Load the Unicode property data.
76 * Intended primarily for use from u_init().
77 * Has no effect if property data is already loaded.
81 uprv_loadPropsData(UErrorCode *errorCode);*/
84 * Internal string casing functions implementing
85 * ustring.h/ustrcase.c and UnicodeString case mapping functions.
89 const UCaseProps
*csp
;
90 #if !UCONFIG_NO_BREAK_ITERATION
91 UBreakIterator
*iter
; /* We adopt the iterator, so we own it. */
98 #ifndef __UCASEMAP_H__
99 typedef struct UCaseMap UCaseMap
;
102 #if UCONFIG_NO_BREAK_ITERATION
103 # define UCASEMAP_INITIALIZER { NULL, { 0 }, 0, 0 }
105 # define UCASEMAP_INITIALIZER { NULL, NULL, { 0 }, 0, 0 }
109 ustrcase_setTempCaseMapLocale(UCaseMap
*csm
, const char *locale
);
111 #ifndef U_STRING_CASE_MAPPER_DEFINED
112 #define U_STRING_CASE_MAPPER_DEFINED
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.
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
);
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
);
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
);
142 #if !UCONFIG_NO_BREAK_ITERATION
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
);
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
);
161 * Implements argument checking and buffer handling
162 * for string case mapping as a common function.
165 ustrcase_map(const UCaseMap
*csm
,
166 UChar
*dest
, int32_t destCapacity
,
167 const UChar
*src
, int32_t srcLength
,
168 UStringCaseMapper
*stringCaseMapper
,
169 UErrorCode
*pErrorCode
);
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.
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
);
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
);
192 * Implements argument checking and buffer handling
193 * for UTF-8 string case mapping as a common function.
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
);
202 U_CAPI
int32_t U_EXPORT2
203 ustr_hashUCharsN(const UChar
*str
, int32_t length
);
205 U_CAPI
int32_t U_EXPORT2
206 ustr_hashCharsN(const char *str
, int32_t length
);
208 U_CAPI
int32_t U_EXPORT2
209 ustr_hashICharsN(const char *str
, int32_t length
);
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.
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.
223 U_CAPI
int32_t U_EXPORT2
224 u_terminateUChars(UChar
*dest
, int32_t destCapacity
, int32_t length
, UErrorCode
*pErrorCode
);
227 * NUL-terminate a char * string if possible.
228 * Same as u_terminateUChars() but for a different string type.
230 U_CAPI
int32_t U_EXPORT2
231 u_terminateChars(char *dest
, int32_t destCapacity
, int32_t length
, UErrorCode
*pErrorCode
);
234 * NUL-terminate a UChar32 * string if possible.
235 * Same as u_terminateUChars() but for a different string type.
237 U_CAPI
int32_t U_EXPORT2
238 u_terminateUChar32s(UChar32
*dest
, int32_t destCapacity
, int32_t length
, UErrorCode
*pErrorCode
);
241 * NUL-terminate a wchar_t * string if possible.
242 * Same as u_terminateUChars() but for a different string type.
244 U_CAPI
int32_t U_EXPORT2
245 u_terminateWChars(wchar_t *dest
, int32_t destCapacity
, int32_t length
, UErrorCode
*pErrorCode
);