os/textandloc/fontservices/textshaperplugin/IcuSource/common/unicode/utf.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/unicode/utf.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,221 @@
     1.4 +/*
     1.5 +*******************************************************************************
     1.6 +*
     1.7 +*   Copyright (C) 1999-2005, International Business Machines
     1.8 +*   Corporation and others.  All Rights Reserved.
     1.9 +*
    1.10 +*******************************************************************************
    1.11 +*   file name:  utf.h
    1.12 +*   encoding:   US-ASCII
    1.13 +*   tab size:   8 (not used)
    1.14 +*   indentation:4
    1.15 +*
    1.16 +*   created on: 1999sep09
    1.17 +*   created by: Markus W. Scherer
    1.18 +*/
    1.19 +
    1.20 +/**
    1.21 + * \file
    1.22 + * \brief C API: Code point macros
    1.23 + *
    1.24 + * This file defines macros for checking whether a code point is
    1.25 + * a surrogate or a non-character etc.
    1.26 + *
    1.27 + * The UChar and UChar32 data types for Unicode code units and code points
    1.28 + * are defined in umachines.h because they can be machine-dependent.
    1.29 + *
    1.30 + * utf.h is included by utypes.h and itself includes utf8.h and utf16.h after some
    1.31 + * common definitions. Those files define macros for efficiently getting code points
    1.32 + * in and out of UTF-8/16 strings.
    1.33 + * utf16.h macros have "U16_" prefixes.
    1.34 + * utf8.h defines similar macros with "U8_" prefixes for UTF-8 string handling.
    1.35 + *
    1.36 + * ICU processes 16-bit Unicode strings.
    1.37 + * Most of the time, such strings are well-formed UTF-16.
    1.38 + * Single, unpaired surrogates must be handled as well, and are treated in ICU
    1.39 + * like regular code points where possible.
    1.40 + * (Pairs of surrogate code points are indistinguishable from supplementary
    1.41 + * code points encoded as pairs of supplementary code units.)
    1.42 + *
    1.43 + * In fact, almost all Unicode code points in normal text (>99%)
    1.44 + * are on the BMP (<=U+ffff) and even <=U+d7ff.
    1.45 + * ICU functions handle supplementary code points (U+10000..U+10ffff)
    1.46 + * but are optimized for the much more frequently occurring BMP code points.
    1.47 + *
    1.48 + * utf.h defines UChar to be an unsigned 16-bit integer. If this matches wchar_t, then
    1.49 + * UChar is defined to be exactly wchar_t, otherwise uint16_t.
    1.50 + *
    1.51 + * UChar32 is defined to be a signed 32-bit integer (int32_t), large enough for a 21-bit
    1.52 + * Unicode code point (Unicode scalar value, 0..0x10ffff).
    1.53 + * Before ICU 2.4, the definition of UChar32 was similarly platform-dependent as
    1.54 + * the definition of UChar. For details see the documentation for UChar32 itself.
    1.55 + *
    1.56 + * utf.h also defines a small number of C macros for single Unicode code points.
    1.57 + * These are simple checks for surrogates and non-characters.
    1.58 + * For actual Unicode character properties see uchar.h.
    1.59 + *
    1.60 + * By default, string operations must be done with error checking in case
    1.61 + * a string is not well-formed UTF-16.
    1.62 + * The macros will detect if a surrogate code unit is unpaired
    1.63 + * (lead unit without trail unit or vice versa) and just return the unit itself
    1.64 + * as the code point.
    1.65 + * (It is an accidental property of Unicode and UTF-16 that all
    1.66 + * malformed sequences can be expressed unambiguously with a distinct subrange
    1.67 + * of Unicode code points.)
    1.68 + *
    1.69 + * When it is safe to assume that text is well-formed UTF-16
    1.70 + * (does not contain single, unpaired surrogates), then one can use
    1.71 + * U16_..._UNSAFE macros.
    1.72 + * These do not check for proper code unit sequences or truncated text and may
    1.73 + * yield wrong results or even cause a crash if they are used with "malformed"
    1.74 + * text.
    1.75 + * In practice, U16_..._UNSAFE macros will produce slightly less code but
    1.76 + * should not be faster because the processing is only different when a
    1.77 + * surrogate code unit is detected, which will be rare.
    1.78 + *
    1.79 + * Similarly for UTF-8, there are "safe" macros without a suffix,
    1.80 + * and U8_..._UNSAFE versions.
    1.81 + * The performance differences are much larger here because UTF-8 provides so
    1.82 + * many opportunities for malformed sequences.
    1.83 + * The unsafe UTF-8 macros are entirely implemented inside the macro definitions
    1.84 + * and are fast, while the safe UTF-8 macros call functions for all but the
    1.85 + * trivial (ASCII) cases.
    1.86 + *
    1.87 + * Unlike with UTF-16, malformed sequences cannot be expressed with distinct
    1.88 + * code point values (0..U+10ffff). They are indicated with negative values instead.
    1.89 + *
    1.90 + * For more information see the ICU User Guide Strings chapter
    1.91 + * (http://icu.sourceforge.net/userguide/strings.html).
    1.92 + *
    1.93 + * <em>Usage:</em>
    1.94 + * ICU coding guidelines for if() statements should be followed when using these macros.
    1.95 + * Compound statements (curly braces {}) must be used  for if-else-while... 
    1.96 + * bodies and all macro statements should be terminated with semicolon.
    1.97 + *
    1.98 + * @stable ICU 2.4
    1.99 + */
   1.100 +
   1.101 +#ifndef __UTF_H__
   1.102 +#define __UTF_H__
   1.103 +
   1.104 +#include "unicode/utypes.h"
   1.105 +/* include the utfXX.h after the following definitions */
   1.106 +
   1.107 +/* single-code point definitions -------------------------------------------- */
   1.108 +
   1.109 +/**
   1.110 + * This value is intended for sentinel values for APIs that
   1.111 + * (take or) return single code points (UChar32).
   1.112 + * It is outside of the Unicode code point range 0..0x10ffff.
   1.113 + * 
   1.114 + * For example, a "done" or "error" value in a new API
   1.115 + * could be indicated with U_SENTINEL.
   1.116 + *
   1.117 + * ICU APIs designed before ICU 2.4 usually define service-specific "done"
   1.118 + * values, mostly 0xffff.
   1.119 + * Those may need to be distinguished from
   1.120 + * actual U+ffff text contents by calling functions like
   1.121 + * CharacterIterator::hasNext() or UnicodeString::length().
   1.122 + *
   1.123 + * @return -1
   1.124 + * @see UChar32
   1.125 + * @stable ICU 2.4
   1.126 + */
   1.127 +#define U_SENTINEL (-1)
   1.128 +
   1.129 +/**
   1.130 + * Is this code point a Unicode noncharacter?
   1.131 + * @param c 32-bit code point
   1.132 + * @return TRUE or FALSE
   1.133 + * @stable ICU 2.4
   1.134 + */
   1.135 +#define U_IS_UNICODE_NONCHAR(c) \
   1.136 +    ((c)>=0xfdd0 && \
   1.137 +     ((uint32_t)(c)<=0xfdef || ((c)&0xfffe)==0xfffe) && \
   1.138 +     (uint32_t)(c)<=0x10ffff)
   1.139 +
   1.140 +/**
   1.141 + * Is c a Unicode code point value (0..U+10ffff)
   1.142 + * that can be assigned a character?
   1.143 + *
   1.144 + * Code points that are not characters include:
   1.145 + * - single surrogate code points (U+d800..U+dfff, 2048 code points)
   1.146 + * - the last two code points on each plane (U+__fffe and U+__ffff, 34 code points)
   1.147 + * - U+fdd0..U+fdef (new with Unicode 3.1, 32 code points)
   1.148 + * - the highest Unicode code point value is U+10ffff
   1.149 + *
   1.150 + * This means that all code points below U+d800 are character code points,
   1.151 + * and that boundary is tested first for performance.
   1.152 + *
   1.153 + * @param c 32-bit code point
   1.154 + * @return TRUE or FALSE
   1.155 + * @stable ICU 2.4
   1.156 + */
   1.157 +#define U_IS_UNICODE_CHAR(c) \
   1.158 +    ((uint32_t)(c)<0xd800 || \
   1.159 +        ((uint32_t)(c)>0xdfff && \
   1.160 +         (uint32_t)(c)<=0x10ffff && \
   1.161 +         !U_IS_UNICODE_NONCHAR(c)))
   1.162 +
   1.163 +#ifndef U_HIDE_DRAFT_API
   1.164 +
   1.165 +/**
   1.166 + * Is this code point a BMP code point (U+0000..U+ffff)?
   1.167 + * @param c 32-bit code point
   1.168 + * @return TRUE or FALSE
   1.169 + * @stable ICU 2.8
   1.170 + */
   1.171 +#define U_IS_BMP(c) ((uint32_t)(c)<=0xffff)
   1.172 +
   1.173 +/**
   1.174 + * Is this code point a supplementary code point (U+10000..U+10ffff)?
   1.175 + * @param c 32-bit code point
   1.176 + * @return TRUE or FALSE
   1.177 + * @stable ICU 2.8
   1.178 + */
   1.179 +#define U_IS_SUPPLEMENTARY(c) ((uint32_t)((c)-0x10000)<=0xfffff)
   1.180 +
   1.181 +#endif /*U_HIDE_DRAFT_API*/
   1.182 + 
   1.183 +/**
   1.184 + * Is this code point a lead surrogate (U+d800..U+dbff)?
   1.185 + * @param c 32-bit code point
   1.186 + * @return TRUE or FALSE
   1.187 + * @stable ICU 2.4
   1.188 + */
   1.189 +#define U_IS_LEAD(c) (((c)&0xfffffc00)==0xd800)
   1.190 +
   1.191 +/**
   1.192 + * Is this code point a trail surrogate (U+dc00..U+dfff)?
   1.193 + * @param c 32-bit code point
   1.194 + * @return TRUE or FALSE
   1.195 + * @stable ICU 2.4
   1.196 + */
   1.197 +#define U_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00)
   1.198 +
   1.199 +/**
   1.200 + * Is this code point a surrogate (U+d800..U+dfff)?
   1.201 + * @param c 32-bit code point
   1.202 + * @return TRUE or FALSE
   1.203 + * @stable ICU 2.4
   1.204 + */
   1.205 +#define U_IS_SURROGATE(c) (((c)&0xfffff800)==0xd800)
   1.206 +
   1.207 +/**
   1.208 + * Assuming c is a surrogate code point (U_IS_SURROGATE(c)),
   1.209 + * is it a lead surrogate?
   1.210 + * @param c 32-bit code point
   1.211 + * @return TRUE or FALSE
   1.212 + * @stable ICU 2.4
   1.213 + */
   1.214 +#define U_IS_SURROGATE_LEAD(c) (((c)&0x400)==0)
   1.215 +
   1.216 +/* include the utfXX.h ------------------------------------------------------ */
   1.217 +
   1.218 +#include "unicode/utf8.h"
   1.219 +#include "unicode/utf16.h"
   1.220 +
   1.221 +/* utf_old.h contains deprecated, pre-ICU 2.4 definitions */
   1.222 +#include "unicode/utf_old.h"
   1.223 +
   1.224 +#endif