1 /* 2 ********************************************************************** 3 * Copyright (C) 1999-2008, International Business Machines 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" 19 #include "unicode/uiter.h" 20 #include "ucase.h" 21 22 /** Simple declaration for u_strToTitle() to avoid including unicode/ubrk.h. */ 23 #ifndef UBRK_TYPEDEF_UBREAK_ITERATOR 24 # define UBRK_TYPEDEF_UBREAK_ITERATOR 25 typedef void UBreakIterator; 26 #endif 27 28 /** 29 * Compare two strings in code point order or code unit order. 30 * Works in strcmp style (both lengths -1), 31 * strncmp style (lengths equal and >=0, flag TRUE), 32 * and memcmp/UnicodeString style (at least one length >=0). 33 * @internal 34 */ 35 U_CFUNC int32_t U_EXPORT2 36 uprv_strCompare(const UChar *s1, int32_t length1, 37 const UChar *s2, int32_t length2, 38 UBool strncmpStyle, UBool codePointOrder); 39 40 /** 41 * Internal API, used by u_strcasecmp() etc. 42 * Compare strings case-insensitively, 43 * in code point order or code unit order. 44 * @internal 45 */ 46 U_CFUNC int32_t 47 u_strcmpFold(const UChar *s1, int32_t length1, 48 const UChar *s2, int32_t length2, 49 uint32_t options, 50 UErrorCode *pErrorCode); 51 52 /** 53 * Are the Unicode properties loaded? 54 * This must be used before internal functions are called that do 55 * not perform this check. 56 * Generate a debug assertion failure if data is not loaded, to flag the fact 57 * that u_init() wasn't called first, before trying to access character properties. 58 * @internal 59 */ 60 U_CFUNC UBool 61 uprv_haveProperties(UErrorCode *pErrorCode); 62 63 /** 64 * Load the Unicode property data. 65 * Intended primarily for use from u_init(). 66 * Has no effect if property data is already loaded. 67 * NOT thread safe. 68 * @internal 69 */ 70 /*U_CFUNC int8_t 71 uprv_loadPropsData(UErrorCode *errorCode);*/ 72 73 /** 74 * Type of a function that may be passed to the internal case mapping functions 75 * or similar for growing the destination buffer. 76 * @internal 77 */ 78 typedef UBool U_CALLCONV 79 UGrowBuffer(void *context, /* opaque pointer for this function */ 80 UChar **pBuffer, /* in/out destination buffer pointer */ 81 int32_t *pCapacity, /* in/out buffer capacity in numbers of UChars */ 82 int32_t reqCapacity,/* requested capacity */ 83 int32_t length); /* number of UChars to be copied to new buffer */ 84 85 /** 86 * Default implementation of UGrowBuffer. 87 * Takes a static buffer as context, allocates a new buffer, 88 * and releases the old one if it is not the same as the one passed as context. 89 * @internal 90 */ 91 U_CAPI UBool /* U_CALLCONV U_EXPORT2 */ 92 u_growBufferFromStatic(void *context, 93 UChar **pBuffer, int32_t *pCapacity, int32_t reqCapacity, 94 int32_t length); 95 96 /* 97 * Internal string casing functions implementing 98 * ustring.h/ustrcase.c and UnicodeString case mapping functions. 99 */ 100 101 /** 102 * @internal 103 */ 104 struct UCaseMap { 105 const UCaseProps *csp; 106 #if !UCONFIG_NO_BREAK_ITERATION 107 UBreakIterator *iter; /* We adopt the iterator, so we own it. */ 108 #endif 109 char locale[32]; 110 int32_t locCache; 111 uint32_t options; 112 }; 113 114 #ifndef __UCASEMAP_H__ 115 typedef struct UCaseMap UCaseMap; 116 #endif 117 118 /** 119 * @internal 120 */ 121 enum { 122 TO_LOWER, 123 TO_UPPER, 124 TO_TITLE, 125 FOLD_CASE 126 }; 127 128 /** 129 * @internal 130 */ 131 U_CFUNC int32_t 132 ustr_toLower(const UCaseProps *csp, 133 UChar *dest, int32_t destCapacity, 134 const UChar *src, int32_t srcLength, 135 const char *locale, 136 UErrorCode *pErrorCode); 137 138 /** 139 * @internal 140 */ 141 U_CFUNC int32_t 142 ustr_toUpper(const UCaseProps *csp, 143 UChar *dest, int32_t destCapacity, 144 const UChar *src, int32_t srcLength, 145 const char *locale, 146 UErrorCode *pErrorCode); 147 148 #if !UCONFIG_NO_BREAK_ITERATION 149 150 /** 151 * @internal 152 */ 153 U_CFUNC int32_t 154 ustr_toTitle(const UCaseProps *csp, 155 UChar *dest, int32_t destCapacity, 156 const UChar *src, int32_t srcLength, 157 UBreakIterator *titleIter, 158 const char *locale, uint32_t options, 159 UErrorCode *pErrorCode); 160 161 #endif 162 163 /** 164 * Internal case folding function. 165 * @internal 166 */ 167 U_CFUNC int32_t 168 ustr_foldCase(const UCaseProps *csp, 169 UChar *dest, int32_t destCapacity, 170 const UChar *src, int32_t srcLength, 171 uint32_t options, 172 UErrorCode *pErrorCode); 173 174 /** 175 * NUL-terminate a UChar * string if possible. 176 * If length < destCapacity then NUL-terminate. 177 * If length == destCapacity then do not terminate but set U_STRING_NOT_TERMINATED_WARNING. 178 * If length > destCapacity then do not terminate but set U_BUFFER_OVERFLOW_ERROR. 179 * 180 * @param dest Destination buffer, can be NULL if destCapacity==0. 181 * @param destCapacity Number of UChars available at dest. 182 * @param length Number of UChars that were (to be) written to dest. 183 * @param pErrorCode ICU error code. 184 * @return length 185 * @internal 186 */ 187 U_CAPI int32_t U_EXPORT2 188 u_terminateUChars(UChar *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); 189 190 /** 191 * NUL-terminate a char * string if possible. 192 * Same as u_terminateUChars() but for a different string type. 193 */ 194 U_CAPI int32_t U_EXPORT2 195 u_terminateChars(char *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); 196 197 /** 198 * NUL-terminate a UChar32 * string if possible. 199 * Same as u_terminateUChars() but for a different string type. 200 */ 201 U_CAPI int32_t U_EXPORT2 202 u_terminateUChar32s(UChar32 *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); 203 204 /** 205 * NUL-terminate a wchar_t * string if possible. 206 * Same as u_terminateUChars() but for a different string type. 207 */ 208 U_CAPI int32_t U_EXPORT2 209 u_terminateWChars(wchar_t *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); 210 211 #endif 212