]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/ustr_imp.h
ICU-491.11.1.tar.gz
[apple/icu.git] / icuSources / common / ustr_imp.h
index 25d93da1d33abdc5e540c6b94322e8ff6b7de36d..ee54d332ef04590796e0f7f2ea66aeedc8a3da28 100644 (file)
@@ -1,6 +1,6 @@
 /*  
 **********************************************************************
-*   Copyright (C) 1999-2008, International Business Machines
+*   Copyright (C) 1999-2011, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
 *   file name:  ustr_imp.h
 #include "unicode/uiter.h"
 #include "ucase.h"
 
-/** Simple declaration for u_strToTitle() to avoid including unicode/ubrk.h. */
+/** Simple declaration to avoid including unicode/ubrk.h. */
 #ifndef UBRK_TYPEDEF_UBREAK_ITERATOR
 #   define UBRK_TYPEDEF_UBREAK_ITERATOR
-    typedef void UBreakIterator;
+    typedef struct UBreakIterator UBreakIterator;
 #endif
 
+#ifndef U_COMPARE_IGNORE_CASE
+/* see also unorm.h */
+/**
+ * Option bit for unorm_compare:
+ * Perform case-insensitive comparison.
+ */
+#define U_COMPARE_IGNORE_CASE       0x10000
+#endif
+
+/**
+ * Internal option for unorm_cmpEquivFold() for strncmp style.
+ * If set, checks for both string length and terminating NUL.
+ */
+#define _STRNCMP_STYLE 0x1000
+
 /**
  * Compare two strings in code point order or code unit order.
  * Works in strcmp style (both lengths -1),
  * strncmp style (lengths equal and >=0, flag TRUE),
  * and memcmp/UnicodeString style (at least one length >=0).
- * @internal
  */
 U_CFUNC int32_t U_EXPORT2
 uprv_strCompare(const UChar *s1, int32_t length1,
@@ -41,7 +55,6 @@ uprv_strCompare(const UChar *s1, int32_t length1,
  * Internal API, used by u_strcasecmp() etc.
  * Compare strings case-insensitively,
  * in code point order or code unit order.
- * @internal
  */
 U_CFUNC int32_t
 u_strcmpFold(const UChar *s1, int32_t length1,
@@ -53,9 +66,7 @@ u_strcmpFold(const UChar *s1, int32_t length1,
  * Are the Unicode properties loaded?
  * This must be used before internal functions are called that do
  * not perform this check.
- * Generate a debug assertion failure if data is not loaded, to flag the fact
- *   that u_init() wasn't called first, before trying to access character properties.
- * @internal
+ * Generate a debug assertion failure if data is not loaded.
  */
 U_CFUNC UBool
 uprv_haveProperties(UErrorCode *pErrorCode);
@@ -65,42 +76,15 @@ uprv_haveProperties(UErrorCode *pErrorCode);
   * Intended primarily for use from u_init().
   * Has no effect if property data is already loaded.
   * NOT thread safe.
-  * @internal
   */
 /*U_CFUNC int8_t
 uprv_loadPropsData(UErrorCode *errorCode);*/
 
-/**
- * Type of a function that may be passed to the internal case mapping functions
- * or similar for growing the destination buffer.
- * @internal
- */
-typedef UBool U_CALLCONV
-UGrowBuffer(void *context,      /* opaque pointer for this function */
-            UChar **pBuffer,    /* in/out destination buffer pointer */
-            int32_t *pCapacity, /* in/out buffer capacity in numbers of UChars */
-            int32_t reqCapacity,/* requested capacity */
-            int32_t length);    /* number of UChars to be copied to new buffer */
-
-/**
- * Default implementation of UGrowBuffer.
- * Takes a static buffer as context, allocates a new buffer,
- * and releases the old one if it is not the same as the one passed as context.
- * @internal
- */
-U_CAPI UBool /* U_CALLCONV U_EXPORT2 */
-u_growBufferFromStatic(void *context,
-                       UChar **pBuffer, int32_t *pCapacity, int32_t reqCapacity,
-                       int32_t length);
-
 /*
  * Internal string casing functions implementing
  * ustring.h/ustrcase.c and UnicodeString case mapping functions.
  */
 
-/**
- * @internal
- */
 struct UCaseMap {
     const UCaseProps *csp;
 #if !UCONFIG_NO_BREAK_ITERATION
@@ -115,61 +99,114 @@ struct UCaseMap {
 typedef struct UCaseMap UCaseMap;
 #endif
 
+#if UCONFIG_NO_BREAK_ITERATION
+#   define UCASEMAP_INITIALIZER { NULL, { 0 }, 0, 0 }
+#else
+#   define UCASEMAP_INITIALIZER { NULL, NULL, { 0 }, 0, 0 }
+#endif
+
+U_CFUNC void
+ustrcase_setTempCaseMapLocale(UCaseMap *csm, const char *locale);
+
+#ifndef U_STRING_CASE_MAPPER_DEFINED
+#define U_STRING_CASE_MAPPER_DEFINED
+
 /**
- * @internal
+ * String case mapping function type, used by ustrcase_map().
+ * All error checking must be done.
+ * The UCaseMap must be fully initialized, with locale and/or iter set as needed.
+ * src and dest must not overlap.
  */
-enum {
-    TO_LOWER,
-    TO_UPPER,
-    TO_TITLE,
-    FOLD_CASE
-};
+typedef int32_t U_CALLCONV
+UStringCaseMapper(const UCaseMap *csm,
+                  UChar *dest, int32_t destCapacity,
+                  const UChar *src, int32_t srcLength,
+                  UErrorCode *pErrorCode);
+
+#endif
+
+/** Implements UStringCaseMapper. */
+U_CFUNC int32_t U_CALLCONV
+ustrcase_internalToLower(const UCaseMap *csm,
+                         UChar *dest, int32_t destCapacity,
+                         const UChar *src, int32_t srcLength,
+                         UErrorCode *pErrorCode);
+
+/** Implements UStringCaseMapper. */
+U_CFUNC int32_t U_CALLCONV
+ustrcase_internalToUpper(const UCaseMap *csm,
+                         UChar *dest, int32_t destCapacity,
+                         const UChar *src, int32_t srcLength,
+                         UErrorCode *pErrorCode);
+
+#if !UCONFIG_NO_BREAK_ITERATION
+
+/** Implements UStringCaseMapper. */
+U_CFUNC int32_t U_CALLCONV
+ustrcase_internalToTitle(const UCaseMap *csm,
+                         UChar *dest, int32_t destCapacity,
+                         const UChar *src, int32_t srcLength,
+                         UErrorCode *pErrorCode);
+
+#endif
+
+/** Implements UStringCaseMapper. */
+U_CFUNC int32_t U_CALLCONV
+ustrcase_internalFold(const UCaseMap *csm,
+                      UChar *dest, int32_t destCapacity,
+                      const UChar *src, int32_t srcLength,
+                      UErrorCode *pErrorCode);
 
 /**
- * @internal
+ * Implements argument checking and buffer handling
+ * for string case mapping as a common function.
  */
 U_CFUNC int32_t
-ustr_toLower(const UCaseProps *csp,
+ustrcase_map(const UCaseMap *csm,
              UChar *dest, int32_t destCapacity,
              const UChar *src, int32_t srcLength,
-             const char *locale,
+             UStringCaseMapper *stringCaseMapper,
              UErrorCode *pErrorCode);
 
 /**
- * @internal
+ * UTF-8 string case mapping function type, used by ucasemap_mapUTF8().
+ * UTF-8 version of UStringCaseMapper.
+ * All error checking must be done.
+ * The UCaseMap must be fully initialized, with locale and/or iter set as needed.
+ * src and dest must not overlap.
  */
-U_CFUNC int32_t
-ustr_toUpper(const UCaseProps *csp,
-             UChar *dest, int32_t destCapacity,
-             const UChar *src, int32_t srcLength,
-             const char *locale,
-             UErrorCode *pErrorCode);
+typedef int32_t U_CALLCONV
+UTF8CaseMapper(const UCaseMap *csm,
+               uint8_t *dest, int32_t destCapacity,
+               const uint8_t *src, int32_t srcLength,
+               UErrorCode *pErrorCode);
 
-#if !UCONFIG_NO_BREAK_ITERATION
+/** Implements UTF8CaseMapper. */
+U_CFUNC int32_t U_CALLCONV
+ucasemap_internalUTF8ToTitle(const UCaseMap *csm,
+         uint8_t *dest, int32_t destCapacity,
+         const uint8_t *src, int32_t srcLength,
+         UErrorCode *pErrorCode);
 
 /**
- * @internal
+ * Implements argument checking and buffer handling
+ * for UTF-8 string case mapping as a common function.
  */
 U_CFUNC int32_t
-ustr_toTitle(const UCaseProps *csp,
-             UChar *dest, int32_t destCapacity,
-             const UChar *src, int32_t srcLength,
-             UBreakIterator *titleIter,
-             const char *locale, uint32_t options,
-             UErrorCode *pErrorCode);
+ucasemap_mapUTF8(const UCaseMap *csm,
+                 uint8_t *dest, int32_t destCapacity,
+                 const uint8_t *src, int32_t srcLength,
+                 UTF8CaseMapper *stringCaseMapper,
+                 UErrorCode *pErrorCode);
 
-#endif
+U_CAPI int32_t U_EXPORT2 
+ustr_hashUCharsN(const UChar *str, int32_t length);
 
-/**
- * Internal case folding function.
- * @internal
- */
-U_CFUNC int32_t
-ustr_foldCase(const UCaseProps *csp,
-              UChar *dest, int32_t destCapacity,
-              const UChar *src, int32_t srcLength,
-              uint32_t options,
-              UErrorCode *pErrorCode);
+U_CAPI int32_t U_EXPORT2 
+ustr_hashCharsN(const char *str, int32_t length);
+
+U_CAPI int32_t U_EXPORT2
+ustr_hashICharsN(const char *str, int32_t length);
 
 /**
  * NUL-terminate a UChar * string if possible.
@@ -182,7 +219,6 @@ ustr_foldCase(const UCaseProps *csp,
  * @param length Number of UChars that were (to be) written to dest.
  * @param pErrorCode ICU error code.
  * @return length
- * @internal
  */
 U_CAPI int32_t U_EXPORT2
 u_terminateUChars(UChar *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode);