1 /* 2 ********************************************************************** 3 * Copyright (C) 1999-2011, 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 struct UBreakIterator UBreakIterator; 26 #endif 27 28 #ifndef U_COMPARE_IGNORE_CASE 29 /* see also unorm.h */ 30 /** 31 * Option bit for unorm_compare: 32 * Perform case-insensitive comparison. 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. 40 */ 41 #define _STRNCMP_STYLE 0x1000 42 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). 48 */ 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); 53 54 /** 55 * Internal API, used by u_strcasecmp() etc. 56 * Compare strings case-insensitively, 57 * in code point order or code unit order. 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 65 /** 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. 70 */ 71 U_CFUNC UBool 72 uprv_haveProperties(UErrorCode *pErrorCode); 73 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. 79 */ 80 /*U_CFUNC int8_t 81 uprv_loadPropsData(UErrorCode *errorCode);*/ 82 83 /* 84 * Internal string casing functions implementing 85 * ustring.h/ustrcase.c and UnicodeString case mapping functions. 86 */ 87 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 102 enum { 103 TO_LOWER, 104 TO_UPPER, 105 TO_TITLE, 106 FOLD_CASE 107 }; 108 109 U_CFUNC int32_t 110 ustr_toLower(const UCaseProps *csp, 111 UChar *dest, int32_t destCapacity, 112 const UChar *src, int32_t srcLength, 113 const char *locale, 114 UErrorCode *pErrorCode); 115 116 U_CFUNC int32_t 117 ustr_toUpper(const UCaseProps *csp, 118 UChar *dest, int32_t destCapacity, 119 const UChar *src, int32_t srcLength, 120 const char *locale, 121 UErrorCode *pErrorCode); 122 123 #if !UCONFIG_NO_BREAK_ITERATION 124 125 U_CFUNC int32_t 126 ustr_toTitle(const UCaseProps *csp, 127 UChar *dest, int32_t destCapacity, 128 const UChar *src, int32_t srcLength, 129 UBreakIterator *titleIter, 130 const char *locale, uint32_t options, 131 UErrorCode *pErrorCode); 132 133 #endif 134 135 /** 136 * Internal case folding function. 137 */ 138 U_CFUNC int32_t 139 ustr_foldCase(const UCaseProps *csp, 140 UChar *dest, int32_t destCapacity, 141 const UChar *src, int32_t srcLength, 142 uint32_t options, 143 UErrorCode *pErrorCode); 144 145 /** 146 * NUL-terminate a UChar * string if possible. 147 * If length < destCapacity then NUL-terminate. 148 * If length == destCapacity then do not terminate but set U_STRING_NOT_TERMINATED_WARNING. 149 * If length > destCapacity then do not terminate but set U_BUFFER_OVERFLOW_ERROR. 150 * 151 * @param dest Destination buffer, can be NULL if destCapacity==0. 152 * @param destCapacity Number of UChars available at dest. 153 * @param length Number of UChars that were (to be) written to dest. 154 * @param pErrorCode ICU error code. 155 * @return length 156 */ 157 U_CAPI int32_t U_EXPORT2 158 u_terminateUChars(UChar *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); 159 160 /** 161 * NUL-terminate a char * string if possible. 162 * Same as u_terminateUChars() but for a different string type. 163 */ 164 U_CAPI int32_t U_EXPORT2 165 u_terminateChars(char *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); 166 167 /** 168 * NUL-terminate a UChar32 * string if possible. 169 * Same as u_terminateUChars() but for a different string type. 170 */ 171 U_CAPI int32_t U_EXPORT2 172 u_terminateUChar32s(UChar32 *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); 173 174 /** 175 * NUL-terminate a wchar_t * string if possible. 176 * Same as u_terminateUChars() but for a different string type. 177 */ 178 U_CAPI int32_t U_EXPORT2 179 u_terminateWChars(wchar_t *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); 180 181 #endif 182