michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (C) 1999-2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * file name: ustr_imp.h michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 2001jan30 michael@0: * created by: Markus W. Scherer michael@0: */ michael@0: michael@0: #ifndef __USTR_IMP_H__ michael@0: #define __USTR_IMP_H__ michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/uiter.h" michael@0: #include "ucase.h" michael@0: michael@0: /** Simple declaration to avoid including unicode/ubrk.h. */ michael@0: #ifndef UBRK_TYPEDEF_UBREAK_ITERATOR michael@0: # define UBRK_TYPEDEF_UBREAK_ITERATOR michael@0: typedef struct UBreakIterator UBreakIterator; michael@0: #endif michael@0: michael@0: #ifndef U_COMPARE_IGNORE_CASE michael@0: /* see also unorm.h */ michael@0: /** michael@0: * Option bit for unorm_compare: michael@0: * Perform case-insensitive comparison. michael@0: */ michael@0: #define U_COMPARE_IGNORE_CASE 0x10000 michael@0: #endif michael@0: michael@0: /** michael@0: * Internal option for unorm_cmpEquivFold() for strncmp style. michael@0: * If set, checks for both string length and terminating NUL. michael@0: */ michael@0: #define _STRNCMP_STYLE 0x1000 michael@0: michael@0: /** michael@0: * Compare two strings in code point order or code unit order. michael@0: * Works in strcmp style (both lengths -1), michael@0: * strncmp style (lengths equal and >=0, flag TRUE), michael@0: * and memcmp/UnicodeString style (at least one length >=0). michael@0: */ michael@0: U_CFUNC int32_t U_EXPORT2 michael@0: uprv_strCompare(const UChar *s1, int32_t length1, michael@0: const UChar *s2, int32_t length2, michael@0: UBool strncmpStyle, UBool codePointOrder); michael@0: michael@0: /** michael@0: * Internal API, used by u_strcasecmp() etc. michael@0: * Compare strings case-insensitively, michael@0: * in code point order or code unit order. michael@0: */ michael@0: U_CFUNC int32_t michael@0: u_strcmpFold(const UChar *s1, int32_t length1, michael@0: const UChar *s2, int32_t length2, michael@0: uint32_t options, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: /** michael@0: * Are the Unicode properties loaded? michael@0: * This must be used before internal functions are called that do michael@0: * not perform this check. michael@0: * Generate a debug assertion failure if data is not loaded. michael@0: */ michael@0: U_CFUNC UBool michael@0: uprv_haveProperties(UErrorCode *pErrorCode); michael@0: michael@0: /** michael@0: * Load the Unicode property data. michael@0: * Intended primarily for use from u_init(). michael@0: * Has no effect if property data is already loaded. michael@0: * NOT thread safe. michael@0: */ michael@0: /*U_CFUNC int8_t michael@0: uprv_loadPropsData(UErrorCode *errorCode);*/ michael@0: michael@0: /* michael@0: * Internal string casing functions implementing michael@0: * ustring.h/ustrcase.c and UnicodeString case mapping functions. michael@0: */ michael@0: michael@0: struct UCaseMap { michael@0: const UCaseProps *csp; michael@0: #if !UCONFIG_NO_BREAK_ITERATION michael@0: UBreakIterator *iter; /* We adopt the iterator, so we own it. */ michael@0: #endif michael@0: char locale[32]; michael@0: int32_t locCache; michael@0: uint32_t options; michael@0: }; michael@0: michael@0: #ifndef __UCASEMAP_H__ michael@0: typedef struct UCaseMap UCaseMap; michael@0: #endif michael@0: michael@0: #if UCONFIG_NO_BREAK_ITERATION michael@0: # define UCASEMAP_INITIALIZER { NULL, { 0 }, 0, 0 } michael@0: #else michael@0: # define UCASEMAP_INITIALIZER { NULL, NULL, { 0 }, 0, 0 } michael@0: #endif michael@0: michael@0: U_CFUNC void michael@0: ustrcase_setTempCaseMapLocale(UCaseMap *csm, const char *locale); michael@0: michael@0: #ifndef U_STRING_CASE_MAPPER_DEFINED michael@0: #define U_STRING_CASE_MAPPER_DEFINED michael@0: michael@0: /** michael@0: * String case mapping function type, used by ustrcase_map(). michael@0: * All error checking must be done. michael@0: * The UCaseMap must be fully initialized, with locale and/or iter set as needed. michael@0: * src and dest must not overlap. michael@0: */ michael@0: typedef int32_t U_CALLCONV michael@0: UStringCaseMapper(const UCaseMap *csm, michael@0: UChar *dest, int32_t destCapacity, michael@0: const UChar *src, int32_t srcLength, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: #endif michael@0: michael@0: /** Implements UStringCaseMapper. */ michael@0: U_CFUNC int32_t U_CALLCONV michael@0: ustrcase_internalToLower(const UCaseMap *csm, michael@0: UChar *dest, int32_t destCapacity, michael@0: const UChar *src, int32_t srcLength, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: /** Implements UStringCaseMapper. */ michael@0: U_CFUNC int32_t U_CALLCONV michael@0: ustrcase_internalToUpper(const UCaseMap *csm, michael@0: UChar *dest, int32_t destCapacity, michael@0: const UChar *src, int32_t srcLength, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: #if !UCONFIG_NO_BREAK_ITERATION michael@0: michael@0: /** Implements UStringCaseMapper. */ michael@0: U_CFUNC int32_t U_CALLCONV michael@0: ustrcase_internalToTitle(const UCaseMap *csm, michael@0: UChar *dest, int32_t destCapacity, michael@0: const UChar *src, int32_t srcLength, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: #endif michael@0: michael@0: /** Implements UStringCaseMapper. */ michael@0: U_CFUNC int32_t U_CALLCONV michael@0: ustrcase_internalFold(const UCaseMap *csm, michael@0: UChar *dest, int32_t destCapacity, michael@0: const UChar *src, int32_t srcLength, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: /** michael@0: * Implements argument checking and buffer handling michael@0: * for string case mapping as a common function. michael@0: */ michael@0: U_CFUNC int32_t michael@0: ustrcase_map(const UCaseMap *csm, michael@0: UChar *dest, int32_t destCapacity, michael@0: const UChar *src, int32_t srcLength, michael@0: UStringCaseMapper *stringCaseMapper, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: /** michael@0: * UTF-8 string case mapping function type, used by ucasemap_mapUTF8(). michael@0: * UTF-8 version of UStringCaseMapper. michael@0: * All error checking must be done. michael@0: * The UCaseMap must be fully initialized, with locale and/or iter set as needed. michael@0: * src and dest must not overlap. michael@0: */ michael@0: typedef int32_t U_CALLCONV michael@0: UTF8CaseMapper(const UCaseMap *csm, michael@0: uint8_t *dest, int32_t destCapacity, michael@0: const uint8_t *src, int32_t srcLength, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: /** Implements UTF8CaseMapper. */ michael@0: U_CFUNC int32_t U_CALLCONV michael@0: ucasemap_internalUTF8ToTitle(const UCaseMap *csm, michael@0: uint8_t *dest, int32_t destCapacity, michael@0: const uint8_t *src, int32_t srcLength, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: /** michael@0: * Implements argument checking and buffer handling michael@0: * for UTF-8 string case mapping as a common function. michael@0: */ michael@0: U_CFUNC int32_t michael@0: ucasemap_mapUTF8(const UCaseMap *csm, michael@0: uint8_t *dest, int32_t destCapacity, michael@0: const uint8_t *src, int32_t srcLength, michael@0: UTF8CaseMapper *stringCaseMapper, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: ustr_hashUCharsN(const UChar *str, int32_t length); michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: ustr_hashCharsN(const char *str, int32_t length); michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: ustr_hashICharsN(const char *str, int32_t length); michael@0: michael@0: /** michael@0: * NUL-terminate a UChar * string if possible. michael@0: * If length < destCapacity then NUL-terminate. michael@0: * If length == destCapacity then do not terminate but set U_STRING_NOT_TERMINATED_WARNING. michael@0: * If length > destCapacity then do not terminate but set U_BUFFER_OVERFLOW_ERROR. michael@0: * michael@0: * @param dest Destination buffer, can be NULL if destCapacity==0. michael@0: * @param destCapacity Number of UChars available at dest. michael@0: * @param length Number of UChars that were (to be) written to dest. michael@0: * @param pErrorCode ICU error code. michael@0: * @return length michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: u_terminateUChars(UChar *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); michael@0: michael@0: /** michael@0: * NUL-terminate a char * string if possible. michael@0: * Same as u_terminateUChars() but for a different string type. michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: u_terminateChars(char *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); michael@0: michael@0: /** michael@0: * NUL-terminate a UChar32 * string if possible. michael@0: * Same as u_terminateUChars() but for a different string type. michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: u_terminateUChar32s(UChar32 *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); michael@0: michael@0: /** michael@0: * NUL-terminate a wchar_t * string if possible. michael@0: * Same as u_terminateUChars() but for a different string type. michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: u_terminateWChars(wchar_t *dest, int32_t destCapacity, int32_t length, UErrorCode *pErrorCode); michael@0: michael@0: #endif