os/textandloc/fontservices/textshaperplugin/IcuSource/common/ucase.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/textshaperplugin/IcuSource/common/ucase.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,359 @@
     1.4 +/*
     1.5 +*******************************************************************************
     1.6 +*
     1.7 +*   Copyright (C) 2004-2005, International Business Machines
     1.8 +*   Corporation and others.  All Rights Reserved.
     1.9 +*
    1.10 +*******************************************************************************
    1.11 +*   file name:  ucase.h
    1.12 +*   encoding:   US-ASCII
    1.13 +*   tab size:   8 (not used)
    1.14 +*   indentation:4
    1.15 +*
    1.16 +*   created on: 2004aug30
    1.17 +*   created by: Markus W. Scherer
    1.18 +*
    1.19 +*   Low-level Unicode character/string case mapping code.
    1.20 +*/
    1.21 +
    1.22 +#ifndef __UCASE_H__
    1.23 +#define __UCASE_H__
    1.24 +
    1.25 +#include "unicode/utypes.h"
    1.26 +#include "unicode/uset.h"
    1.27 +#include "uset_imp.h"
    1.28 +#include "udataswp.h"
    1.29 +
    1.30 +U_CDECL_BEGIN
    1.31 +
    1.32 +/* library API -------------------------------------------------------------- */
    1.33 +
    1.34 +struct UCaseProps;
    1.35 +typedef struct UCaseProps UCaseProps;
    1.36 +
    1.37 +U_CAPI UCaseProps * U_EXPORT2
    1.38 +ucase_open(UErrorCode *pErrorCode);
    1.39 +
    1.40 +U_CAPI UCaseProps * U_EXPORT2
    1.41 +ucase_openBinary(const uint8_t *bin, int32_t length, UErrorCode *pErrorCode);
    1.42 +
    1.43 +U_CAPI void U_EXPORT2
    1.44 +ucase_close(UCaseProps *csp);
    1.45 +
    1.46 +
    1.47 +U_CAPI const UCaseProps * U_EXPORT2
    1.48 +ucase_getSingleton(UErrorCode *pErrorCode);
    1.49 +
    1.50 +/**
    1.51 + * Get a singleton dummy object, one that works with no real data.
    1.52 + * This can be used when the real data is not available.
    1.53 + * Using the dummy can reduce checks for available data after an initial failure.
    1.54 + */
    1.55 +U_CAPI const UCaseProps * U_EXPORT2
    1.56 +ucase_getDummy(UErrorCode *pErrorCode);
    1.57 +
    1.58 +
    1.59 +U_CAPI int32_t U_EXPORT2
    1.60 +ucase_swap(const UDataSwapper *ds,
    1.61 +           const void *inData, int32_t length, void *outData,
    1.62 +           UErrorCode *pErrorCode);
    1.63 +
    1.64 +U_CAPI void U_EXPORT2
    1.65 +ucase_addPropertyStarts(const UCaseProps *csp, const USetAdder *sa, UErrorCode *pErrorCode);
    1.66 +
    1.67 +/**
    1.68 + * Requires non-NULL locale ID but otherwise does the equivalent of
    1.69 + * checking for language codes as if uloc_getLanguage() were called:
    1.70 + * Accepts both 2- and 3-letter codes and accepts case variants.
    1.71 + */
    1.72 +U_CFUNC int32_t
    1.73 +ucase_getCaseLocale(const char *locale, int32_t *locCache);
    1.74 +
    1.75 +/**
    1.76 + * Bit mask for getting just the options from a string compare options word
    1.77 + * that are relevant for case-insensitive string comparison.
    1.78 + * See uchar.h. Also include _STRNCMP_STYLE and U_COMPARE_CODE_POINT_ORDER.
    1.79 + * @internal
    1.80 + */
    1.81 +#define _STRCASECMP_OPTIONS_MASK 0xffff
    1.82 +
    1.83 +/**
    1.84 + * Bit mask for getting just the options from a string compare options word
    1.85 + * that are relevant for case folding (of a single string or code point).
    1.86 + * See uchar.h.
    1.87 + * @internal
    1.88 + */
    1.89 +#define _FOLD_CASE_OPTIONS_MASK 0xff
    1.90 +
    1.91 +/* single-code point functions */
    1.92 +
    1.93 +U_CAPI UChar32 U_EXPORT2
    1.94 +ucase_tolower(const UCaseProps *csp, UChar32 c);
    1.95 +
    1.96 +U_CAPI UChar32 U_EXPORT2
    1.97 +ucase_toupper(const UCaseProps *csp, UChar32 c);
    1.98 +
    1.99 +U_CAPI UChar32 U_EXPORT2
   1.100 +ucase_totitle(const UCaseProps *csp, UChar32 c);
   1.101 +
   1.102 +U_CAPI UChar32 U_EXPORT2
   1.103 +ucase_fold(const UCaseProps *csp, UChar32 c, uint32_t options);
   1.104 +
   1.105 +/**
   1.106 + * Adds all simple case mappings and the full case folding for c to sa,
   1.107 + * and also adds special case closure mappings.
   1.108 + * c itself is not added.
   1.109 + * For example, the mappings
   1.110 + * - for s include long s
   1.111 + * - for sharp s include ss
   1.112 + * - for k include the Kelvin sign
   1.113 + */
   1.114 +U_CAPI void U_EXPORT2
   1.115 +ucase_addCaseClosure(const UCaseProps *csp, UChar32 c, const USetAdder *sa);
   1.116 +
   1.117 +/**
   1.118 + * Maps the string to single code points and adds the associated case closure
   1.119 + * mappings.
   1.120 + * The string is mapped to code points if it is their full case folding string.
   1.121 + * In other words, this performs a reverse full case folding and then
   1.122 + * adds the case closure items of the resulting code points.
   1.123 + * If the string is found and its closure applied, then
   1.124 + * the string itself is added as well as part of its code points' closure.
   1.125 + * It must be length>=0.
   1.126 + *
   1.127 + * @return TRUE if the string was found
   1.128 + */
   1.129 +U_CAPI UBool U_EXPORT2
   1.130 +ucase_addStringCaseClosure(const UCaseProps *csp, const UChar *s, int32_t length, const USetAdder *sa);
   1.131 +
   1.132 +/** @return UCASE_NONE, UCASE_LOWER, UCASE_UPPER, UCASE_TITLE */
   1.133 +U_CAPI int32_t U_EXPORT2
   1.134 +ucase_getType(const UCaseProps *csp, UChar32 c);
   1.135 +
   1.136 +/** @return same as ucase_getType(), or <0 if c is case-ignorable */
   1.137 +U_CAPI int32_t U_EXPORT2
   1.138 +ucase_getTypeOrIgnorable(const UCaseProps *csp, UChar32 c);
   1.139 +
   1.140 +U_CAPI UBool U_EXPORT2
   1.141 +ucase_isSoftDotted(const UCaseProps *csp, UChar32 c);
   1.142 +
   1.143 +U_CAPI UBool U_EXPORT2
   1.144 +ucase_isCaseSensitive(const UCaseProps *csp, UChar32 c);
   1.145 +
   1.146 +/* string case mapping functions */
   1.147 +
   1.148 +/**
   1.149 + * Iterator function for string case mappings, which need to look at the
   1.150 + * context (surrounding text) of a given character for conditional mappings.
   1.151 + *
   1.152 + * The iterator only needs to go backward or forward away from the
   1.153 + * character in question. It does not use any indexes on this interface.
   1.154 + * It does not support random access or an arbitrary change of
   1.155 + * iteration direction.
   1.156 + *
   1.157 + * The code point being case-mapped itself is never returned by
   1.158 + * this iterator.
   1.159 + *
   1.160 + * @param context A pointer to the iterator's working data.
   1.161 + * @param dir If <0 then start iterating backward from the character;
   1.162 + *            if >0 then start iterating forward from the character;
   1.163 + *            if 0 then continue iterating in the current direction.
   1.164 + * @return Next code point, or <0 when the iteration is done.
   1.165 + */
   1.166 +typedef UChar32 U_CALLCONV
   1.167 +UCaseContextIterator(void *context, int8_t dir);
   1.168 +
   1.169 +/**
   1.170 + * Sample struct which may be used by some implementations of
   1.171 + * UCaseContextIterator.
   1.172 + */
   1.173 +struct UCaseContext {
   1.174 +    void *p;
   1.175 +    int32_t start, index, limit;
   1.176 +    int32_t cpStart, cpLimit;
   1.177 +    int8_t dir;
   1.178 +    int8_t b1, b2, b3;
   1.179 +};
   1.180 +typedef struct UCaseContext UCaseContext;
   1.181 +
   1.182 +enum {
   1.183 +    /**
   1.184 +     * For string case mappings, a single character (a code point) is mapped
   1.185 +     * either to itself (in which case in-place mapping functions do nothing),
   1.186 +     * or to another single code point, or to a string.
   1.187 +     * Aside from the string contents, these are indicated with a single int32_t
   1.188 +     * value as follows:
   1.189 +     *
   1.190 +     * Mapping to self: Negative values (~self instead of -self to support U+0000)
   1.191 +     *
   1.192 +     * Mapping to another code point: Positive values >UCASE_MAX_STRING_LENGTH
   1.193 +     *
   1.194 +     * Mapping to a string: The string length (0..UCASE_MAX_STRING_LENGTH) is
   1.195 +     * returned. Note that the string result may indeed have zero length.
   1.196 +     */
   1.197 +    UCASE_MAX_STRING_LENGTH=0x1f
   1.198 +};
   1.199 +
   1.200 +/**
   1.201 + * Get the full lowercase mapping for c.
   1.202 + *
   1.203 + * @param csp Case mapping properties.
   1.204 + * @param c Character to be mapped.
   1.205 + * @param iter Character iterator, used for context-sensitive mappings.
   1.206 + *             See UCaseContextIterator for details.
   1.207 + *             If iter==NULL then a context-independent result is returned.
   1.208 + * @param context Pointer to be passed into iter.
   1.209 + * @param pString If the mapping result is a string, then the pointer is
   1.210 + *                written to *pString.
   1.211 + * @param locale Locale ID for locale-dependent mappings.
   1.212 + * @param locCache Initialize to 0; may be used to cache the result of parsing
   1.213 + *                 the locale ID for subsequent calls.
   1.214 + *                 Can be NULL.
   1.215 + * @return Output code point or string length, see UCASE_MAX_STRING_LENGTH.
   1.216 + *
   1.217 + * @see UCaseContextIterator
   1.218 + * @see UCASE_MAX_STRING_LENGTH
   1.219 + * @internal
   1.220 + */
   1.221 +U_CAPI int32_t U_EXPORT2
   1.222 +ucase_toFullLower(const UCaseProps *csp, UChar32 c,
   1.223 +                  UCaseContextIterator *iter, void *context,
   1.224 +                  const UChar **pString,
   1.225 +                  const char *locale, int32_t *locCache);
   1.226 +
   1.227 +U_CAPI int32_t U_EXPORT2
   1.228 +ucase_toFullUpper(const UCaseProps *csp, UChar32 c,
   1.229 +                  UCaseContextIterator *iter, void *context,
   1.230 +                  const UChar **pString,
   1.231 +                  const char *locale, int32_t *locCache);
   1.232 +
   1.233 +U_CAPI int32_t U_EXPORT2
   1.234 +ucase_toFullTitle(const UCaseProps *csp, UChar32 c,
   1.235 +                  UCaseContextIterator *iter, void *context,
   1.236 +                  const UChar **pString,
   1.237 +                  const char *locale, int32_t *locCache);
   1.238 +
   1.239 +U_CAPI int32_t U_EXPORT2
   1.240 +ucase_toFullFolding(const UCaseProps *csp, UChar32 c,
   1.241 +                    const UChar **pString,
   1.242 +                    uint32_t options);
   1.243 +
   1.244 +/* file definitions --------------------------------------------------------- */
   1.245 +
   1.246 +#define UCASE_DATA_NAME "ucase"
   1.247 +#define UCASE_DATA_TYPE "icu"
   1.248 +
   1.249 +/* format "cAsE" */
   1.250 +#define UCASE_FMT_0 0x63
   1.251 +#define UCASE_FMT_1 0x41
   1.252 +#define UCASE_FMT_2 0x53
   1.253 +#define UCASE_FMT_3 0x45
   1.254 +
   1.255 +/* indexes into indexes[] */
   1.256 +enum {
   1.257 +    UCASE_IX_INDEX_TOP,
   1.258 +    UCASE_IX_LENGTH,
   1.259 +    UCASE_IX_TRIE_SIZE,
   1.260 +    UCASE_IX_EXC_LENGTH,
   1.261 +    UCASE_IX_UNFOLD_LENGTH,
   1.262 +
   1.263 +    UCASE_IX_MAX_FULL_LENGTH=15,
   1.264 +    UCASE_IX_TOP=16
   1.265 +};
   1.266 +
   1.267 +/* definitions for 16-bit case properties word ------------------------------ */
   1.268 +
   1.269 +/* 2-bit constants for types of cased characters */
   1.270 +#define UCASE_TYPE_MASK     3
   1.271 +enum {
   1.272 +    UCASE_NONE,
   1.273 +    UCASE_LOWER,
   1.274 +    UCASE_UPPER,
   1.275 +    UCASE_TITLE
   1.276 +};
   1.277 +
   1.278 +#define UCASE_GET_TYPE(props) ((props)&UCASE_TYPE_MASK)
   1.279 +
   1.280 +#define UCASE_SENSITIVE     4
   1.281 +#define UCASE_EXCEPTION     8
   1.282 +
   1.283 +#define UCASE_DOT_MASK      0x30
   1.284 +enum {
   1.285 +    UCASE_NO_DOT=0,         /* normal characters with cc=0 */
   1.286 +    UCASE_SOFT_DOTTED=0x10, /* soft-dotted characters with cc=0 */
   1.287 +    UCASE_ABOVE=0x20,       /* "above" accents with cc=230 */
   1.288 +    UCASE_OTHER_ACCENT=0x30 /* other accent character (0<cc!=230) */
   1.289 +};
   1.290 +
   1.291 +/* no exception: bits 15..6 are a 10-bit signed case mapping delta */
   1.292 +#define UCASE_DELTA_SHIFT   6
   1.293 +#define UCASE_DELTA_MASK    0xffc0
   1.294 +#define UCASE_MAX_DELTA     0x1ff
   1.295 +#define UCASE_MIN_DELTA     (-UCASE_MAX_DELTA-1)
   1.296 +
   1.297 +#define UCASE_GET_DELTA(props) ((int16_t)(props)>>UCASE_DELTA_SHIFT)
   1.298 +
   1.299 +/* case-ignorable uses one of the delta bits, see gencase/store.c */
   1.300 +#define UCASE_CASE_IGNORABLE 0x40
   1.301 +
   1.302 +/* exception: bits 15..4 are an unsigned 12-bit index into the exceptions array */
   1.303 +#define UCASE_EXC_SHIFT     4
   1.304 +#define UCASE_EXC_MASK      0xfff0
   1.305 +#define UCASE_MAX_EXCEPTIONS 0x1000
   1.306 +
   1.307 +/* definitions for 16-bit main exceptions word ------------------------------ */
   1.308 +
   1.309 +/* first 8 bits indicate values in optional slots */
   1.310 +enum {
   1.311 +    UCASE_EXC_LOWER,
   1.312 +    UCASE_EXC_FOLD,
   1.313 +    UCASE_EXC_UPPER,
   1.314 +    UCASE_EXC_TITLE,
   1.315 +    UCASE_EXC_4,            /* reserved */
   1.316 +    UCASE_EXC_5,            /* reserved */
   1.317 +    UCASE_EXC_CLOSURE,
   1.318 +    UCASE_EXC_FULL_MAPPINGS,
   1.319 +    UCASE_EXC_ALL_SLOTS     /* one past the last slot */
   1.320 +};
   1.321 +
   1.322 +/* each slot is 2 uint16_t instead of 1 */
   1.323 +#define UCASE_EXC_DOUBLE_SLOTS      0x100
   1.324 +
   1.325 +/* reserved: exception bits 11..9 */
   1.326 +
   1.327 +/* UCASE_EXC_DOT_MASK=UCASE_DOT_MASK<<UCASE_EXC_DOT_SHIFT */
   1.328 +#define UCASE_EXC_DOT_SHIFT     8
   1.329 +
   1.330 +/* normally stored in the main word, but pushed out for larger exception indexes */
   1.331 +#define UCASE_EXC_DOT_MASK      0x3000
   1.332 +enum {
   1.333 +    UCASE_EXC_NO_DOT=0,
   1.334 +    UCASE_EXC_SOFT_DOTTED=0x1000,
   1.335 +    UCASE_EXC_ABOVE=0x2000,         /* "above" accents with cc=230 */
   1.336 +    UCASE_EXC_OTHER_ACCENT=0x3000   /* other character (0<cc!=230) */
   1.337 +};
   1.338 +
   1.339 +/* complex/conditional mappings */
   1.340 +#define UCASE_EXC_CONDITIONAL_SPECIAL   0x4000
   1.341 +#define UCASE_EXC_CONDITIONAL_FOLD      0x8000
   1.342 +
   1.343 +/* definitions for lengths word for full case mappings */
   1.344 +#define UCASE_FULL_LOWER    0xf
   1.345 +#define UCASE_FULL_FOLDING  0xf0
   1.346 +#define UCASE_FULL_UPPER    0xf00
   1.347 +#define UCASE_FULL_TITLE    0xf000
   1.348 +
   1.349 +/* maximum lengths */
   1.350 +#define UCASE_FULL_MAPPINGS_MAX_LENGTH (4*0xf)
   1.351 +#define UCASE_CLOSURE_MAX_LENGTH 0xf
   1.352 +
   1.353 +/* constants for reverse case folding ("unfold") data */
   1.354 +enum {
   1.355 +    UCASE_UNFOLD_ROWS,
   1.356 +    UCASE_UNFOLD_ROW_WIDTH,
   1.357 +    UCASE_UNFOLD_STRING_WIDTH
   1.358 +};
   1.359 +
   1.360 +U_CDECL_END
   1.361 +
   1.362 +#endif