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