1/* 2******************************************************************************* 3* 4* Copyright (C) 2004-2010, International Business Machines 5* Corporation and others. All Rights Reserved. 6* 7******************************************************************************* 8* file name: ucase.h 9* encoding: US-ASCII 10* tab size: 8 (not used) 11* indentation:4 12* 13* created on: 2004aug30 14* created by: Markus W. Scherer 15* 16* Low-level Unicode character/string case mapping code. 17*/ 18 19#ifndef __UCASE_H__ 20#define __UCASE_H__ 21 22#include "unicode/utypes.h" 23#include "unicode/uset.h" 24#include "uset_imp.h" 25#include "udataswp.h" 26 27U_CDECL_BEGIN 28 29/* library API -------------------------------------------------------------- */ 30 31struct UCaseProps; 32typedef struct UCaseProps UCaseProps; 33 34U_CAPI const UCaseProps * U_EXPORT2 35ucase_getSingleton(void); 36 37U_CFUNC void U_EXPORT2 38ucase_addPropertyStarts(const UCaseProps *csp, const USetAdder *sa, UErrorCode *pErrorCode); 39 40/** 41 * Requires non-NULL locale ID but otherwise does the equivalent of 42 * checking for language codes as if uloc_getLanguage() were called: 43 * Accepts both 2- and 3-letter codes and accepts case variants. 44 */ 45U_CFUNC int32_t 46ucase_getCaseLocale(const char *locale, int32_t *locCache); 47 48/* Casing locale types for ucase_getCaseLocale */ 49enum { 50 UCASE_LOC_UNKNOWN, 51 UCASE_LOC_ROOT, 52 UCASE_LOC_TURKISH, 53 UCASE_LOC_LITHUANIAN, 54 UCASE_LOC_DUTCH 55}; 56 57/** 58 * Bit mask for getting just the options from a string compare options word 59 * that are relevant for case-insensitive string comparison. 60 * See uchar.h. Also include _STRNCMP_STYLE and U_COMPARE_CODE_POINT_ORDER. 61 * @internal 62 */ 63#define _STRCASECMP_OPTIONS_MASK 0xffff 64 65/** 66 * Bit mask for getting just the options from a string compare options word 67 * that are relevant for case folding (of a single string or code point). 68 * See uchar.h. 69 * @internal 70 */ 71#define _FOLD_CASE_OPTIONS_MASK 0xff 72 73/* single-code point functions */ 74 75U_CAPI UChar32 U_EXPORT2 76ucase_tolower(const UCaseProps *csp, UChar32 c); 77 78U_CAPI UChar32 U_EXPORT2 79ucase_toupper(const UCaseProps *csp, UChar32 c); 80 81U_CAPI UChar32 U_EXPORT2 82ucase_totitle(const UCaseProps *csp, UChar32 c); 83 84U_CAPI UChar32 U_EXPORT2 85ucase_fold(const UCaseProps *csp, UChar32 c, uint32_t options); 86 87/** 88 * Adds all simple case mappings and the full case folding for c to sa, 89 * and also adds special case closure mappings. 90 * c itself is not added. 91 * For example, the mappings 92 * - for s include long s 93 * - for sharp s include ss 94 * - for k include the Kelvin sign 95 */ 96U_CFUNC void U_EXPORT2 97ucase_addCaseClosure(const UCaseProps *csp, UChar32 c, const USetAdder *sa); 98 99/** 100 * Maps the string to single code points and adds the associated case closure 101 * mappings. 102 * The string is mapped to code points if it is their full case folding string. 103 * In other words, this performs a reverse full case folding and then 104 * adds the case closure items of the resulting code points. 105 * If the string is found and its closure applied, then 106 * the string itself is added as well as part of its code points' closure. 107 * It must be length>=0. 108 * 109 * @return TRUE if the string was found 110 */ 111U_CFUNC UBool U_EXPORT2 112ucase_addStringCaseClosure(const UCaseProps *csp, const UChar *s, int32_t length, const USetAdder *sa); 113 114/** @return UCASE_NONE, UCASE_LOWER, UCASE_UPPER, UCASE_TITLE */ 115U_CAPI int32_t U_EXPORT2 116ucase_getType(const UCaseProps *csp, UChar32 c); 117 118/** @return same as ucase_getType(), or <0 if c is case-ignorable */ 119U_CAPI int32_t U_EXPORT2 120ucase_getTypeOrIgnorable(const UCaseProps *csp, UChar32 c); 121 122U_CAPI UBool U_EXPORT2 123ucase_isSoftDotted(const UCaseProps *csp, UChar32 c); 124 125U_CAPI UBool U_EXPORT2 126ucase_isCaseSensitive(const UCaseProps *csp, UChar32 c); 127 128/* string case mapping functions */ 129 130/** 131 * Iterator function for string case mappings, which need to look at the 132 * context (surrounding text) of a given character for conditional mappings. 133 * 134 * The iterator only needs to go backward or forward away from the 135 * character in question. It does not use any indexes on this interface. 136 * It does not support random access or an arbitrary change of 137 * iteration direction. 138 * 139 * The code point being case-mapped itself is never returned by 140 * this iterator. 141 * 142 * @param context A pointer to the iterator's working data. 143 * @param dir If <0 then start iterating backward from the character; 144 * if >0 then start iterating forward from the character; 145 * if 0 then continue iterating in the current direction. 146 * @return Next code point, or <0 when the iteration is done. 147 */ 148typedef UChar32 U_CALLCONV 149UCaseContextIterator(void *context, int8_t dir); 150 151/** 152 * Sample struct which may be used by some implementations of 153 * UCaseContextIterator. 154 */ 155struct UCaseContext { 156 void *p; 157 int32_t start, index, limit; 158 int32_t cpStart, cpLimit; 159 int8_t dir; 160 int8_t b1, b2, b3; 161}; 162typedef struct UCaseContext UCaseContext; 163 164enum { 165 /** 166 * For string case mappings, a single character (a code point) is mapped 167 * either to itself (in which case in-place mapping functions do nothing), 168 * or to another single code point, or to a string. 169 * Aside from the string contents, these are indicated with a single int32_t 170 * value as follows: 171 * 172 * Mapping to self: Negative values (~self instead of -self to support U+0000) 173 * 174 * Mapping to another code point: Positive values >UCASE_MAX_STRING_LENGTH 175 * 176 * Mapping to a string: The string length (0..UCASE_MAX_STRING_LENGTH) is 177 * returned. Note that the string result may indeed have zero length. 178 */ 179 UCASE_MAX_STRING_LENGTH=0x1f 180}; 181 182/** 183 * Get the full lowercase mapping for c. 184 * 185 * @param csp Case mapping properties. 186 * @param c Character to be mapped. 187 * @param iter Character iterator, used for context-sensitive mappings. 188 * See UCaseContextIterator for details. 189 * If iter==NULL then a context-independent result is returned. 190 * @param context Pointer to be passed into iter. 191 * @param pString If the mapping result is a string, then the pointer is 192 * written to *pString. 193 * @param locale Locale ID for locale-dependent mappings. 194 * @param locCache Initialize to 0; may be used to cache the result of parsing 195 * the locale ID for subsequent calls. 196 * Can be NULL. 197 * @return Output code point or string length, see UCASE_MAX_STRING_LENGTH. 198 * 199 * @see UCaseContextIterator 200 * @see UCASE_MAX_STRING_LENGTH 201 * @internal 202 */ 203U_CAPI int32_t U_EXPORT2 204ucase_toFullLower(const UCaseProps *csp, UChar32 c, 205 UCaseContextIterator *iter, void *context, 206 const UChar **pString, 207 const char *locale, int32_t *locCache); 208 209U_CAPI int32_t U_EXPORT2 210ucase_toFullUpper(const UCaseProps *csp, UChar32 c, 211 UCaseContextIterator *iter, void *context, 212 const UChar **pString, 213 const char *locale, int32_t *locCache); 214 215U_CAPI int32_t U_EXPORT2 216ucase_toFullTitle(const UCaseProps *csp, UChar32 c, 217 UCaseContextIterator *iter, void *context, 218 const UChar **pString, 219 const char *locale, int32_t *locCache); 220 221U_CAPI int32_t U_EXPORT2 222ucase_toFullFolding(const UCaseProps *csp, UChar32 c, 223 const UChar **pString, 224 uint32_t options); 225 226U_CFUNC int32_t U_EXPORT2 227ucase_hasBinaryProperty(UChar32 c, UProperty which); 228 229 230U_CDECL_BEGIN 231 232/** 233 * @internal 234 */ 235typedef int32_t U_CALLCONV 236UCaseMapFull(const UCaseProps *csp, UChar32 c, 237 UCaseContextIterator *iter, void *context, 238 const UChar **pString, 239 const char *locale, int32_t *locCache); 240 241U_CDECL_END 242 243/* file definitions --------------------------------------------------------- */ 244 245#define UCASE_DATA_NAME "ucase" 246#define UCASE_DATA_TYPE "icu" 247 248/* format "cAsE" */ 249#define UCASE_FMT_0 0x63 250#define UCASE_FMT_1 0x41 251#define UCASE_FMT_2 0x53 252#define UCASE_FMT_3 0x45 253 254/* indexes into indexes[] */ 255enum { 256 UCASE_IX_INDEX_TOP, 257 UCASE_IX_LENGTH, 258 UCASE_IX_TRIE_SIZE, 259 UCASE_IX_EXC_LENGTH, 260 UCASE_IX_UNFOLD_LENGTH, 261 262 UCASE_IX_MAX_FULL_LENGTH=15, 263 UCASE_IX_TOP=16 264}; 265 266/* definitions for 16-bit case properties word ------------------------------ */ 267 268/* 2-bit constants for types of cased characters */ 269#define UCASE_TYPE_MASK 3 270enum { 271 UCASE_NONE, 272 UCASE_LOWER, 273 UCASE_UPPER, 274 UCASE_TITLE 275}; 276 277#define UCASE_GET_TYPE(props) ((props)&UCASE_TYPE_MASK) 278 279#define UCASE_SENSITIVE 4 280#define UCASE_EXCEPTION 8 281 282#define UCASE_DOT_MASK 0x30 283enum { 284 UCASE_NO_DOT=0, /* normal characters with cc=0 */ 285 UCASE_SOFT_DOTTED=0x10, /* soft-dotted characters with cc=0 */ 286 UCASE_ABOVE=0x20, /* "above" accents with cc=230 */ 287 UCASE_OTHER_ACCENT=0x30 /* other accent character (0<cc!=230) */ 288}; 289 290/* no exception: bits 15..6 are a 10-bit signed case mapping delta */ 291#define UCASE_DELTA_SHIFT 6 292#define UCASE_DELTA_MASK 0xffc0 293#define UCASE_MAX_DELTA 0x1ff 294#define UCASE_MIN_DELTA (-UCASE_MAX_DELTA-1) 295 296#define UCASE_GET_DELTA(props) ((int16_t)(props)>>UCASE_DELTA_SHIFT) 297 298/* case-ignorable uses one of the delta bits, see gencase/store.c */ 299#define UCASE_CASE_IGNORABLE 0x40 300 301/* exception: bits 15..4 are an unsigned 12-bit index into the exceptions array */ 302#define UCASE_EXC_SHIFT 4 303#define UCASE_EXC_MASK 0xfff0 304#define UCASE_MAX_EXCEPTIONS 0x1000 305 306/* definitions for 16-bit main exceptions word ------------------------------ */ 307 308/* first 8 bits indicate values in optional slots */ 309enum { 310 UCASE_EXC_LOWER, 311 UCASE_EXC_FOLD, 312 UCASE_EXC_UPPER, 313 UCASE_EXC_TITLE, 314 UCASE_EXC_4, /* reserved */ 315 UCASE_EXC_5, /* reserved */ 316 UCASE_EXC_CLOSURE, 317 UCASE_EXC_FULL_MAPPINGS, 318 UCASE_EXC_ALL_SLOTS /* one past the last slot */ 319}; 320 321/* each slot is 2 uint16_t instead of 1 */ 322#define UCASE_EXC_DOUBLE_SLOTS 0x100 323 324/* reserved: exception bits 10..9 */ 325 326#define UCASE_EXC_CASE_IGNORABLE 0x800 327 328/* UCASE_EXC_DOT_MASK=UCASE_DOT_MASK<<UCASE_EXC_DOT_SHIFT */ 329#define UCASE_EXC_DOT_SHIFT 8 330 331/* normally stored in the main word, but pushed out for larger exception indexes */ 332#define UCASE_EXC_DOT_MASK 0x3000 333enum { 334 UCASE_EXC_NO_DOT=0, 335 UCASE_EXC_SOFT_DOTTED=0x1000, 336 UCASE_EXC_ABOVE=0x2000, /* "above" accents with cc=230 */ 337 UCASE_EXC_OTHER_ACCENT=0x3000 /* other character (0<cc!=230) */ 338}; 339 340/* complex/conditional mappings */ 341#define UCASE_EXC_CONDITIONAL_SPECIAL 0x4000 342#define UCASE_EXC_CONDITIONAL_FOLD 0x8000 343 344/* definitions for lengths word for full case mappings */ 345#define UCASE_FULL_LOWER 0xf 346#define UCASE_FULL_FOLDING 0xf0 347#define UCASE_FULL_UPPER 0xf00 348#define UCASE_FULL_TITLE 0xf000 349 350/* maximum lengths */ 351#define UCASE_FULL_MAPPINGS_MAX_LENGTH (4*0xf) 352#define UCASE_CLOSURE_MAX_LENGTH 0xf 353 354/* constants for reverse case folding ("unfold") data */ 355enum { 356 UCASE_UNFOLD_ROWS, 357 UCASE_UNFOLD_ROW_WIDTH, 358 UCASE_UNFOLD_STRING_WIDTH 359}; 360 361U_CDECL_END 362 363#endif 364