Home | History | Annotate | Download | only in common
      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 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 #if UCONFIG_NO_BREAK_ITERATION
    103 #   define UCASEMAP_INITIALIZER { NULL, { 0 }, 0, 0 }
    104 #else
    105 #   define UCASEMAP_INITIALIZER { NULL, NULL, { 0 }, 0, 0 }
    106 #endif
    107 
    108 U_CFUNC void
    109 ustrcase_setTempCaseMapLocale(UCaseMap *csm, const char *locale);
    110 
    111 #ifndef U_STRING_CASE_MAPPER_DEFINED
    112 #define U_STRING_CASE_MAPPER_DEFINED
    113 
    114 /**
    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.
    119  */
    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);
    125 
    126 #endif
    127 
    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);
    134 
    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);
    141 
    142 #if !UCONFIG_NO_BREAK_ITERATION
    143 
    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);
    150 
    151 #endif
    152 
    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);
    159 
    160 /**
    161  * Implements argument checking and buffer handling
    162  * for string case mapping as a common function.
    163  */
    164 U_CFUNC int32_t
    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);
    170 
    171 /**
    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.
    177  */
    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);
    183 
    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);
    190 
    191 /**
    192  * Implements argument checking and buffer handling
    193  * for UTF-8 string case mapping as a common function.
    194  */
    195 U_CFUNC int32_t
    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);
    201 
    202 U_CAPI int32_t U_EXPORT2
    203 ustr_hashUCharsN(const UChar *str, int32_t length);
    204 
    205 U_CAPI int32_t U_EXPORT2
    206 ustr_hashCharsN(const char *str, int32_t length);
    207 
    208 U_CAPI int32_t U_EXPORT2
    209 ustr_hashICharsN(const char *str, int32_t length);
    210 
    211 /**
    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.
    216  *
    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.
    221  * @return length
    222  */
    223 U_CAPI int32_t U_EXPORT2
    224 u_terminateUChars(UChar *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode);
    225 
    226 /**
    227  * NUL-terminate a char * string if possible.
    228  * Same as u_terminateUChars() but for a different string type.
    229  */
    230 U_CAPI int32_t U_EXPORT2
    231 u_terminateChars(char *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode);
    232 
    233 /**
    234  * NUL-terminate a UChar32 * string if possible.
    235  * Same as u_terminateUChars() but for a different string type.
    236  */
    237 U_CAPI int32_t U_EXPORT2
    238 u_terminateUChar32s(UChar32 *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode);
    239 
    240 /**
    241  * NUL-terminate a wchar_t * string if possible.
    242  * Same as u_terminateUChars() but for a different string type.
    243  */
    244 U_CAPI int32_t U_EXPORT2
    245 u_terminateWChars(wchar_t *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode);
    246 
    247 #endif
    248