1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/common/ustr_imp.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,247 @@ 1.4 +/* 1.5 +********************************************************************** 1.6 +* Copyright (C) 1999-2011, International Business Machines 1.7 +* Corporation and others. All Rights Reserved. 1.8 +********************************************************************** 1.9 +* file name: ustr_imp.h 1.10 +* encoding: US-ASCII 1.11 +* tab size: 8 (not used) 1.12 +* indentation:4 1.13 +* 1.14 +* created on: 2001jan30 1.15 +* created by: Markus W. Scherer 1.16 +*/ 1.17 + 1.18 +#ifndef __USTR_IMP_H__ 1.19 +#define __USTR_IMP_H__ 1.20 + 1.21 +#include "unicode/utypes.h" 1.22 +#include "unicode/uiter.h" 1.23 +#include "ucase.h" 1.24 + 1.25 +/** Simple declaration to avoid including unicode/ubrk.h. */ 1.26 +#ifndef UBRK_TYPEDEF_UBREAK_ITERATOR 1.27 +# define UBRK_TYPEDEF_UBREAK_ITERATOR 1.28 + typedef struct UBreakIterator UBreakIterator; 1.29 +#endif 1.30 + 1.31 +#ifndef U_COMPARE_IGNORE_CASE 1.32 +/* see also unorm.h */ 1.33 +/** 1.34 + * Option bit for unorm_compare: 1.35 + * Perform case-insensitive comparison. 1.36 + */ 1.37 +#define U_COMPARE_IGNORE_CASE 0x10000 1.38 +#endif 1.39 + 1.40 +/** 1.41 + * Internal option for unorm_cmpEquivFold() for strncmp style. 1.42 + * If set, checks for both string length and terminating NUL. 1.43 + */ 1.44 +#define _STRNCMP_STYLE 0x1000 1.45 + 1.46 +/** 1.47 + * Compare two strings in code point order or code unit order. 1.48 + * Works in strcmp style (both lengths -1), 1.49 + * strncmp style (lengths equal and >=0, flag TRUE), 1.50 + * and memcmp/UnicodeString style (at least one length >=0). 1.51 + */ 1.52 +U_CFUNC int32_t U_EXPORT2 1.53 +uprv_strCompare(const UChar *s1, int32_t length1, 1.54 + const UChar *s2, int32_t length2, 1.55 + UBool strncmpStyle, UBool codePointOrder); 1.56 + 1.57 +/** 1.58 + * Internal API, used by u_strcasecmp() etc. 1.59 + * Compare strings case-insensitively, 1.60 + * in code point order or code unit order. 1.61 + */ 1.62 +U_CFUNC int32_t 1.63 +u_strcmpFold(const UChar *s1, int32_t length1, 1.64 + const UChar *s2, int32_t length2, 1.65 + uint32_t options, 1.66 + UErrorCode *pErrorCode); 1.67 + 1.68 +/** 1.69 + * Are the Unicode properties loaded? 1.70 + * This must be used before internal functions are called that do 1.71 + * not perform this check. 1.72 + * Generate a debug assertion failure if data is not loaded. 1.73 + */ 1.74 +U_CFUNC UBool 1.75 +uprv_haveProperties(UErrorCode *pErrorCode); 1.76 + 1.77 +/** 1.78 + * Load the Unicode property data. 1.79 + * Intended primarily for use from u_init(). 1.80 + * Has no effect if property data is already loaded. 1.81 + * NOT thread safe. 1.82 + */ 1.83 +/*U_CFUNC int8_t 1.84 +uprv_loadPropsData(UErrorCode *errorCode);*/ 1.85 + 1.86 +/* 1.87 + * Internal string casing functions implementing 1.88 + * ustring.h/ustrcase.c and UnicodeString case mapping functions. 1.89 + */ 1.90 + 1.91 +struct UCaseMap { 1.92 + const UCaseProps *csp; 1.93 +#if !UCONFIG_NO_BREAK_ITERATION 1.94 + UBreakIterator *iter; /* We adopt the iterator, so we own it. */ 1.95 +#endif 1.96 + char locale[32]; 1.97 + int32_t locCache; 1.98 + uint32_t options; 1.99 +}; 1.100 + 1.101 +#ifndef __UCASEMAP_H__ 1.102 +typedef struct UCaseMap UCaseMap; 1.103 +#endif 1.104 + 1.105 +#if UCONFIG_NO_BREAK_ITERATION 1.106 +# define UCASEMAP_INITIALIZER { NULL, { 0 }, 0, 0 } 1.107 +#else 1.108 +# define UCASEMAP_INITIALIZER { NULL, NULL, { 0 }, 0, 0 } 1.109 +#endif 1.110 + 1.111 +U_CFUNC void 1.112 +ustrcase_setTempCaseMapLocale(UCaseMap *csm, const char *locale); 1.113 + 1.114 +#ifndef U_STRING_CASE_MAPPER_DEFINED 1.115 +#define U_STRING_CASE_MAPPER_DEFINED 1.116 + 1.117 +/** 1.118 + * String case mapping function type, used by ustrcase_map(). 1.119 + * All error checking must be done. 1.120 + * The UCaseMap must be fully initialized, with locale and/or iter set as needed. 1.121 + * src and dest must not overlap. 1.122 + */ 1.123 +typedef int32_t U_CALLCONV 1.124 +UStringCaseMapper(const UCaseMap *csm, 1.125 + UChar *dest, int32_t destCapacity, 1.126 + const UChar *src, int32_t srcLength, 1.127 + UErrorCode *pErrorCode); 1.128 + 1.129 +#endif 1.130 + 1.131 +/** Implements UStringCaseMapper. */ 1.132 +U_CFUNC int32_t U_CALLCONV 1.133 +ustrcase_internalToLower(const UCaseMap *csm, 1.134 + UChar *dest, int32_t destCapacity, 1.135 + const UChar *src, int32_t srcLength, 1.136 + UErrorCode *pErrorCode); 1.137 + 1.138 +/** Implements UStringCaseMapper. */ 1.139 +U_CFUNC int32_t U_CALLCONV 1.140 +ustrcase_internalToUpper(const UCaseMap *csm, 1.141 + UChar *dest, int32_t destCapacity, 1.142 + const UChar *src, int32_t srcLength, 1.143 + UErrorCode *pErrorCode); 1.144 + 1.145 +#if !UCONFIG_NO_BREAK_ITERATION 1.146 + 1.147 +/** Implements UStringCaseMapper. */ 1.148 +U_CFUNC int32_t U_CALLCONV 1.149 +ustrcase_internalToTitle(const UCaseMap *csm, 1.150 + UChar *dest, int32_t destCapacity, 1.151 + const UChar *src, int32_t srcLength, 1.152 + UErrorCode *pErrorCode); 1.153 + 1.154 +#endif 1.155 + 1.156 +/** Implements UStringCaseMapper. */ 1.157 +U_CFUNC int32_t U_CALLCONV 1.158 +ustrcase_internalFold(const UCaseMap *csm, 1.159 + UChar *dest, int32_t destCapacity, 1.160 + const UChar *src, int32_t srcLength, 1.161 + UErrorCode *pErrorCode); 1.162 + 1.163 +/** 1.164 + * Implements argument checking and buffer handling 1.165 + * for string case mapping as a common function. 1.166 + */ 1.167 +U_CFUNC int32_t 1.168 +ustrcase_map(const UCaseMap *csm, 1.169 + UChar *dest, int32_t destCapacity, 1.170 + const UChar *src, int32_t srcLength, 1.171 + UStringCaseMapper *stringCaseMapper, 1.172 + UErrorCode *pErrorCode); 1.173 + 1.174 +/** 1.175 + * UTF-8 string case mapping function type, used by ucasemap_mapUTF8(). 1.176 + * UTF-8 version of UStringCaseMapper. 1.177 + * All error checking must be done. 1.178 + * The UCaseMap must be fully initialized, with locale and/or iter set as needed. 1.179 + * src and dest must not overlap. 1.180 + */ 1.181 +typedef int32_t U_CALLCONV 1.182 +UTF8CaseMapper(const UCaseMap *csm, 1.183 + uint8_t *dest, int32_t destCapacity, 1.184 + const uint8_t *src, int32_t srcLength, 1.185 + UErrorCode *pErrorCode); 1.186 + 1.187 +/** Implements UTF8CaseMapper. */ 1.188 +U_CFUNC int32_t U_CALLCONV 1.189 +ucasemap_internalUTF8ToTitle(const UCaseMap *csm, 1.190 + uint8_t *dest, int32_t destCapacity, 1.191 + const uint8_t *src, int32_t srcLength, 1.192 + UErrorCode *pErrorCode); 1.193 + 1.194 +/** 1.195 + * Implements argument checking and buffer handling 1.196 + * for UTF-8 string case mapping as a common function. 1.197 + */ 1.198 +U_CFUNC int32_t 1.199 +ucasemap_mapUTF8(const UCaseMap *csm, 1.200 + uint8_t *dest, int32_t destCapacity, 1.201 + const uint8_t *src, int32_t srcLength, 1.202 + UTF8CaseMapper *stringCaseMapper, 1.203 + UErrorCode *pErrorCode); 1.204 + 1.205 +U_CAPI int32_t U_EXPORT2 1.206 +ustr_hashUCharsN(const UChar *str, int32_t length); 1.207 + 1.208 +U_CAPI int32_t U_EXPORT2 1.209 +ustr_hashCharsN(const char *str, int32_t length); 1.210 + 1.211 +U_CAPI int32_t U_EXPORT2 1.212 +ustr_hashICharsN(const char *str, int32_t length); 1.213 + 1.214 +/** 1.215 + * NUL-terminate a UChar * string if possible. 1.216 + * If length < destCapacity then NUL-terminate. 1.217 + * If length == destCapacity then do not terminate but set U_STRING_NOT_TERMINATED_WARNING. 1.218 + * If length > destCapacity then do not terminate but set U_BUFFER_OVERFLOW_ERROR. 1.219 + * 1.220 + * @param dest Destination buffer, can be NULL if destCapacity==0. 1.221 + * @param destCapacity Number of UChars available at dest. 1.222 + * @param length Number of UChars that were (to be) written to dest. 1.223 + * @param pErrorCode ICU error code. 1.224 + * @return length 1.225 + */ 1.226 +U_CAPI int32_t U_EXPORT2 1.227 +u_terminateUChars(UChar *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); 1.228 + 1.229 +/** 1.230 + * NUL-terminate a char * string if possible. 1.231 + * Same as u_terminateUChars() but for a different string type. 1.232 + */ 1.233 +U_CAPI int32_t U_EXPORT2 1.234 +u_terminateChars(char *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); 1.235 + 1.236 +/** 1.237 + * NUL-terminate a UChar32 * string if possible. 1.238 + * Same as u_terminateUChars() but for a different string type. 1.239 + */ 1.240 +U_CAPI int32_t U_EXPORT2 1.241 +u_terminateUChar32s(UChar32 *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); 1.242 + 1.243 +/** 1.244 + * NUL-terminate a wchar_t * string if possible. 1.245 + * Same as u_terminateUChars() but for a different string type. 1.246 + */ 1.247 +U_CAPI int32_t U_EXPORT2 1.248 +u_terminateWChars(wchar_t *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); 1.249 + 1.250 +#endif