jpayne@69: // © 2016 and later: Unicode, Inc. and others.
jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html
jpayne@69: /*
jpayne@69: *******************************************************************************
jpayne@69: *
jpayne@69: * Copyright (C) 2002-2012, International Business Machines
jpayne@69: * Corporation and others. All Rights Reserved.
jpayne@69: *
jpayne@69: *******************************************************************************
jpayne@69: * file name: utf_old.h
jpayne@69: * encoding: UTF-8
jpayne@69: * tab size: 8 (not used)
jpayne@69: * indentation:4
jpayne@69: *
jpayne@69: * created on: 2002sep21
jpayne@69: * created by: Markus W. Scherer
jpayne@69: */
jpayne@69:
jpayne@69: /**
jpayne@69: * \file
jpayne@69: * \brief C API: Deprecated macros for Unicode string handling
jpayne@69: *
jpayne@69: * The macros in utf_old.h are all deprecated and their use discouraged.
jpayne@69: * Some of the design principles behind the set of UTF macros
jpayne@69: * have changed or proved impractical.
jpayne@69: * Almost all of the old "UTF macros" are at least renamed.
jpayne@69: * If you are looking for a new equivalent to an old macro, please see the
jpayne@69: * comment at the old one.
jpayne@69: *
jpayne@69: * Brief summary of reasons for deprecation:
jpayne@69: * - Switch on UTF_SIZE (selection of UTF-8/16/32 default string processing)
jpayne@69: * was impractical.
jpayne@69: * - Switch on UTF_SAFE etc. (selection of unsafe/safe/strict default string processing)
jpayne@69: * was of little use and impractical.
jpayne@69: * - Whole classes of macros became obsolete outside of the UTF_SIZE/UTF_SAFE
jpayne@69: * selection framework: UTF32_ macros (all trivial)
jpayne@69: * and UTF_ default and intermediate macros (all aliases).
jpayne@69: * - The selection framework also caused many macro aliases.
jpayne@69: * - Change in Unicode standard: "irregular" sequences (3.0) became illegal (3.2).
jpayne@69: * - Change of language in Unicode standard:
jpayne@69: * Growing distinction between internal x-bit Unicode strings and external UTF-x
jpayne@69: * forms, with the former more lenient.
jpayne@69: * Suggests renaming of UTF16_ macros to U16_.
jpayne@69: * - The prefix "UTF_" without a width number confused some users.
jpayne@69: * - "Safe" append macros needed the addition of an error indicator output.
jpayne@69: * - "Safe" UTF-8 macros used legitimate (if rarely used) code point values
jpayne@69: * to indicate error conditions.
jpayne@69: * - The use of the "_CHAR" infix for code point operations confused some users.
jpayne@69: *
jpayne@69: * More details:
jpayne@69: *
jpayne@69: * Until ICU 2.2, utf.h theoretically allowed to choose among UTF-8/16/32
jpayne@69: * for string processing, and among unsafe/safe/strict default macros for that.
jpayne@69: *
jpayne@69: * It proved nearly impossible to write non-trivial, high-performance code
jpayne@69: * that is UTF-generic.
jpayne@69: * Unsafe default macros would be dangerous for default string processing,
jpayne@69: * and the main reason for the "strict" versions disappeared:
jpayne@69: * Between Unicode 3.0 and 3.2 all "irregular" UTF-8 sequences became illegal.
jpayne@69: * The only other conditions that "strict" checked for were non-characters,
jpayne@69: * which are valid during processing. Only during text input/output should they
jpayne@69: * be checked, and at that time other well-formedness checks may be
jpayne@69: * necessary or useful as well.
jpayne@69: * This can still be done by using U16_NEXT and U_IS_UNICODE_NONCHAR
jpayne@69: * or U_IS_UNICODE_CHAR.
jpayne@69: *
jpayne@69: * The old UTF8_..._SAFE macros also used some normal Unicode code points
jpayne@69: * to indicate malformed sequences.
jpayne@69: * The new UTF8_ macros without suffix use negative values instead.
jpayne@69: *
jpayne@69: * The entire contents of utf32.h was moved here without replacement
jpayne@69: * because all those macros were trivial and
jpayne@69: * were meaningful only in the framework of choosing the UTF size.
jpayne@69: *
jpayne@69: * See Jitterbug 2150 and its discussion on the ICU mailing list
jpayne@69: * in September 2002.
jpayne@69: *
jpayne@69: *
jpayne@69: *
jpayne@69: * Obsolete part of pre-ICU 2.4 utf.h file documentation:
jpayne@69: *
jpayne@69: * The original concept for these files was for ICU to allow
jpayne@69: * in principle to set which UTF (UTF-8/16/32) is used internally
jpayne@69: * by defining UTF_SIZE to either 8, 16, or 32. utf.h would then define the UChar type
jpayne@69: * accordingly. UTF-16 was the default.
jpayne@69: *
jpayne@69: * This concept has been abandoned.
jpayne@69: * A lot of the ICU source code assumes UChar strings are in UTF-16.
jpayne@69: * This is especially true for low-level code like
jpayne@69: * conversion, normalization, and collation.
jpayne@69: * The utf.h header enforces the default of UTF-16.
jpayne@69: * The UTF-8 and UTF-32 macros remain for now for completeness and backward compatibility.
jpayne@69: *
jpayne@69: * Accordingly, utf.h defines UChar to be an unsigned 16-bit integer. If this matches wchar_t, then
jpayne@69: * UChar is defined to be exactly wchar_t, otherwise uint16_t.
jpayne@69: *
jpayne@69: * UChar32 is defined to be a signed 32-bit integer (int32_t), large enough for a 21-bit
jpayne@69: * Unicode code point (Unicode scalar value, 0..0x10ffff).
jpayne@69: * Before ICU 2.4, the definition of UChar32 was similarly platform-dependent as
jpayne@69: * the definition of UChar. For details see the documentation for UChar32 itself.
jpayne@69: *
jpayne@69: * utf.h also defines a number of C macros for handling single Unicode code points and
jpayne@69: * for using UTF Unicode strings. It includes utf8.h, utf16.h, and utf32.h for the actual
jpayne@69: * implementations of those macros and then aliases one set of them (for UTF-16) for general use.
jpayne@69: * The UTF-specific macros have the UTF size in the macro name prefixes (UTF16_...), while
jpayne@69: * the general alias macros always begin with UTF_...
jpayne@69: *
jpayne@69: * Many string operations can be done with or without error checking.
jpayne@69: * Where such a distinction is useful, there are two versions of the macros, "unsafe" and "safe"
jpayne@69: * ones with ..._UNSAFE and ..._SAFE suffixes. The unsafe macros are fast but may cause
jpayne@69: * program failures if the strings are not well-formed. The safe macros have an additional, boolean
jpayne@69: * parameter "strict". If strict is FALSE, then only illegal sequences are detected.
jpayne@69: * Otherwise, irregular sequences and non-characters are detected as well (like single surrogates).
jpayne@69: * Safe macros return special error code points for illegal/irregular sequences:
jpayne@69: * Typically, U+ffff, or values that would result in a code unit sequence of the same length
jpayne@69: * as the erroneous input sequence.
jpayne@69: * Note that _UNSAFE macros have fewer parameters: They do not have the strictness parameter, and
jpayne@69: * they do not have start/length parameters for boundary checking.
jpayne@69: *
jpayne@69: * Here, the macros are aliased in two steps:
jpayne@69: * In the first step, the UTF-specific macros with UTF16_ prefix and _UNSAFE and _SAFE suffixes are
jpayne@69: * aliased according to the UTF_SIZE to macros with UTF_ prefix and the same suffixes and signatures.
jpayne@69: * Then, in a second step, the default, general alias macros are set to use either the unsafe or
jpayne@69: * the safe/not strict (default) or the safe/strict macro;
jpayne@69: * these general macros do not have a strictness parameter.
jpayne@69: *
jpayne@69: * It is possible to change the default choice for the general alias macros to be unsafe, safe/not strict or safe/strict.
jpayne@69: * The default is safe/not strict. It is not recommended to select the unsafe macros as the basis for
jpayne@69: * Unicode string handling in ICU! To select this, define UTF_SAFE, UTF_STRICT, or UTF_UNSAFE.
jpayne@69: *
jpayne@69: * For general use, one should use the default, general macros with UTF_ prefix and no _SAFE/_UNSAFE suffix.
jpayne@69: * Only in some cases it may be necessary to control the choice of macro directly and use a less generic alias.
jpayne@69: * For example, if it can be assumed that a string is well-formed and the index will stay within the bounds,
jpayne@69: * then the _UNSAFE version may be used.
jpayne@69: * If a UTF-8 string is to be processed, then the macros with UTF8_ prefixes need to be used.
jpayne@69: *
jpayne@69: *
jpayne@69: *
jpayne@69: * Deprecated ICU 2.4. Use the macros in utf.h, utf16.h, utf8.h instead.
jpayne@69: */
jpayne@69:
jpayne@69: #ifndef __UTF_OLD_H__
jpayne@69: #define __UTF_OLD_H__
jpayne@69:
jpayne@69: #include "unicode/utf.h"
jpayne@69: #include "unicode/utf8.h"
jpayne@69: #include "unicode/utf16.h"
jpayne@69:
jpayne@69: /**
jpayne@69: * \def U_HIDE_OBSOLETE_UTF_OLD_H
jpayne@69: *
jpayne@69: * Hides the obsolete definitions in unicode/utf_old.h.
jpayne@69: * Recommended to be set to 1 at compile time to make sure
jpayne@69: * the long-deprecated macros are no longer used.
jpayne@69: *
jpayne@69: * For reasons for the deprecation see the utf_old.h file comments.
jpayne@69: *
jpayne@69: * @internal
jpayne@69: */
jpayne@69: #ifndef U_HIDE_OBSOLETE_UTF_OLD_H
jpayne@69: # define U_HIDE_OBSOLETE_UTF_OLD_H 0
jpayne@69: #endif
jpayne@69:
jpayne@69: #if !defined(U_HIDE_DEPRECATED_API) && !U_HIDE_OBSOLETE_UTF_OLD_H
jpayne@69:
jpayne@69: /* Formerly utf.h, part 1 --------------------------------------------------- */
jpayne@69:
jpayne@69: #ifdef U_USE_UTF_DEPRECATES
jpayne@69: /**
jpayne@69: * Unicode string and array offset and index type.
jpayne@69: * ICU always counts Unicode code units (UChars) for
jpayne@69: * string offsets, indexes, and lengths, not Unicode code points.
jpayne@69: *
jpayne@69: * @obsolete ICU 2.6. Use int32_t directly instead since this API will be removed in that release.
jpayne@69: */
jpayne@69: typedef int32_t UTextOffset;
jpayne@69: #endif
jpayne@69:
jpayne@69: /** Number of bits in a Unicode string code unit - ICU uses 16-bit Unicode. @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF_SIZE 16
jpayne@69:
jpayne@69: /**
jpayne@69: * The default choice for general Unicode string macros is to use the ..._SAFE macro implementations
jpayne@69: * with strict=FALSE.
jpayne@69: *
jpayne@69: * @deprecated ICU 2.4. Obsolete, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF_SAFE
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #undef UTF_UNSAFE
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #undef UTF_STRICT
jpayne@69:
jpayne@69: /**
jpayne@69: * UTF8_ERROR_VALUE_1 and UTF8_ERROR_VALUE_2 are special error values for UTF-8,
jpayne@69: * which need 1 or 2 bytes in UTF-8:
jpayne@69: * \code
jpayne@69: * U+0015 = NAK = Negative Acknowledge, C0 control character
jpayne@69: * U+009f = highest C1 control character
jpayne@69: * \endcode
jpayne@69: *
jpayne@69: * These are used by UTF8_..._SAFE macros so that they can return an error value
jpayne@69: * that needs the same number of code units (bytes) as were seen by
jpayne@69: * a macro. They should be tested with UTF_IS_ERROR() or UTF_IS_VALID().
jpayne@69: *
jpayne@69: * @deprecated ICU 2.4. Obsolete, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF8_ERROR_VALUE_1 0x15
jpayne@69:
jpayne@69: /**
jpayne@69: * See documentation on UTF8_ERROR_VALUE_1 for details.
jpayne@69: *
jpayne@69: * @deprecated ICU 2.4. Obsolete, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF8_ERROR_VALUE_2 0x9f
jpayne@69:
jpayne@69: /**
jpayne@69: * Error value for all UTFs. This code point value will be set by macros with error
jpayne@69: * checking if an error is detected.
jpayne@69: *
jpayne@69: * @deprecated ICU 2.4. Obsolete, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF_ERROR_VALUE 0xffff
jpayne@69:
jpayne@69: /**
jpayne@69: * Is a given 32-bit code an error value
jpayne@69: * as returned by one of the macros for any UTF?
jpayne@69: *
jpayne@69: * @deprecated ICU 2.4. Obsolete, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF_IS_ERROR(c) \
jpayne@69: (((c)&0xfffe)==0xfffe || (c)==UTF8_ERROR_VALUE_1 || (c)==UTF8_ERROR_VALUE_2)
jpayne@69:
jpayne@69: /**
jpayne@69: * This is a combined macro: Is c a valid Unicode value _and_ not an error code?
jpayne@69: *
jpayne@69: * @deprecated ICU 2.4. Obsolete, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF_IS_VALID(c) \
jpayne@69: (UTF_IS_UNICODE_CHAR(c) && \
jpayne@69: (c)!=UTF8_ERROR_VALUE_1 && (c)!=UTF8_ERROR_VALUE_2)
jpayne@69:
jpayne@69: /**
jpayne@69: * Is this code unit or code point a surrogate (U+d800..U+dfff)?
jpayne@69: * @deprecated ICU 2.4. Renamed to U_IS_SURROGATE and U16_IS_SURROGATE, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF_IS_SURROGATE(uchar) (((uchar)&0xfffff800)==0xd800)
jpayne@69:
jpayne@69: /**
jpayne@69: * Is a given 32-bit code point a Unicode noncharacter?
jpayne@69: *
jpayne@69: * @deprecated ICU 2.4. Renamed to U_IS_UNICODE_NONCHAR, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF_IS_UNICODE_NONCHAR(c) \
jpayne@69: ((c)>=0xfdd0 && \
jpayne@69: ((uint32_t)(c)<=0xfdef || ((c)&0xfffe)==0xfffe) && \
jpayne@69: (uint32_t)(c)<=0x10ffff)
jpayne@69:
jpayne@69: /**
jpayne@69: * Is a given 32-bit value a Unicode code point value (0..U+10ffff)
jpayne@69: * that can be assigned a character?
jpayne@69: *
jpayne@69: * Code points that are not characters include:
jpayne@69: * - single surrogate code points (U+d800..U+dfff, 2048 code points)
jpayne@69: * - the last two code points on each plane (U+__fffe and U+__ffff, 34 code points)
jpayne@69: * - U+fdd0..U+fdef (new with Unicode 3.1, 32 code points)
jpayne@69: * - the highest Unicode code point value is U+10ffff
jpayne@69: *
jpayne@69: * This means that all code points below U+d800 are character code points,
jpayne@69: * and that boundary is tested first for performance.
jpayne@69: *
jpayne@69: * @deprecated ICU 2.4. Renamed to U_IS_UNICODE_CHAR, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF_IS_UNICODE_CHAR(c) \
jpayne@69: ((uint32_t)(c)<0xd800 || \
jpayne@69: ((uint32_t)(c)>0xdfff && \
jpayne@69: (uint32_t)(c)<=0x10ffff && \
jpayne@69: !UTF_IS_UNICODE_NONCHAR(c)))
jpayne@69:
jpayne@69: /* Formerly utf8.h ---------------------------------------------------------- */
jpayne@69:
jpayne@69: /**
jpayne@69: * \var utf8_countTrailBytes
jpayne@69: * Internal array with numbers of trail bytes for any given byte used in
jpayne@69: * lead byte position.
jpayne@69: *
jpayne@69: * This is internal since it is not meant to be called directly by external clients;
jpayne@69: * however it is called by public macros in this file and thus must remain stable,
jpayne@69: * and should not be hidden when other internal functions are hidden (otherwise
jpayne@69: * public macros would fail to compile).
jpayne@69: * @internal
jpayne@69: */
jpayne@69: #ifdef U_UTF8_IMPL
jpayne@69: // No forward declaration if compiling utf_impl.cpp, which defines utf8_countTrailBytes.
jpayne@69: #elif defined(U_STATIC_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION)
jpayne@69: U_CFUNC const uint8_t utf8_countTrailBytes[];
jpayne@69: #else
jpayne@69: U_CFUNC U_IMPORT const uint8_t utf8_countTrailBytes[]; /* U_IMPORT2? */ /*U_IMPORT*/
jpayne@69: #endif
jpayne@69:
jpayne@69: /**
jpayne@69: * Count the trail bytes for a UTF-8 lead byte.
jpayne@69: * @deprecated ICU 2.4. Renamed to U8_COUNT_TRAIL_BYTES, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF8_COUNT_TRAIL_BYTES(leadByte) (utf8_countTrailBytes[(uint8_t)leadByte])
jpayne@69:
jpayne@69: /**
jpayne@69: * Mask a UTF-8 lead byte, leave only the lower bits that form part of the code point value.
jpayne@69: * @deprecated ICU 2.4. Renamed to U8_MASK_LEAD_BYTE, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF8_MASK_LEAD_BYTE(leadByte, countTrailBytes) ((leadByte)&=(1<<(6-(countTrailBytes)))-1)
jpayne@69:
jpayne@69: /** Is this this code point a single code unit (byte)? @deprecated ICU 2.4. Renamed to U8_IS_SINGLE, see utf_old.h. */
jpayne@69: #define UTF8_IS_SINGLE(uchar) (((uchar)&0x80)==0)
jpayne@69: /** Is this this code unit the lead code unit (byte) of a code point? @deprecated ICU 2.4. Renamed to U8_IS_LEAD, see utf_old.h. */
jpayne@69: #define UTF8_IS_LEAD(uchar) ((uint8_t)((uchar)-0xc0)<0x3e)
jpayne@69: /** Is this this code unit a trailing code unit (byte) of a code point? @deprecated ICU 2.4. Renamed to U8_IS_TRAIL, see utf_old.h. */
jpayne@69: #define UTF8_IS_TRAIL(uchar) (((uchar)&0xc0)==0x80)
jpayne@69:
jpayne@69: /** Does this scalar Unicode value need multiple code units for storage? @deprecated ICU 2.4. Use U8_LENGTH or test ((uint32_t)(c)>0x7f) instead, see utf_old.h. */
jpayne@69: #define UTF8_NEED_MULTIPLE_UCHAR(c) ((uint32_t)(c)>0x7f)
jpayne@69:
jpayne@69: /**
jpayne@69: * Given the lead character, how many bytes are taken by this code point.
jpayne@69: * ICU does not deal with code points >0x10ffff
jpayne@69: * unless necessary for advancing in the byte stream.
jpayne@69: *
jpayne@69: * These length macros take into account that for values >0x10ffff
jpayne@69: * the UTF8_APPEND_CHAR_SAFE macros would write the error code point 0xffff
jpayne@69: * with 3 bytes.
jpayne@69: * Code point comparisons need to be in uint32_t because UChar32
jpayne@69: * may be a signed type, and negative values must be recognized.
jpayne@69: *
jpayne@69: * @deprecated ICU 2.4. Use U8_LENGTH instead, see utf.h.
jpayne@69: */
jpayne@69: #if 1
jpayne@69: # define UTF8_CHAR_LENGTH(c) \
jpayne@69: ((uint32_t)(c)<=0x7f ? 1 : \
jpayne@69: ((uint32_t)(c)<=0x7ff ? 2 : \
jpayne@69: ((uint32_t)((c)-0x10000)>0xfffff ? 3 : 4) \
jpayne@69: ) \
jpayne@69: )
jpayne@69: #else
jpayne@69: # define UTF8_CHAR_LENGTH(c) \
jpayne@69: ((uint32_t)(c)<=0x7f ? 1 : \
jpayne@69: ((uint32_t)(c)<=0x7ff ? 2 : \
jpayne@69: ((uint32_t)(c)<=0xffff ? 3 : \
jpayne@69: ((uint32_t)(c)<=0x10ffff ? 4 : \
jpayne@69: ((uint32_t)(c)<=0x3ffffff ? 5 : \
jpayne@69: ((uint32_t)(c)<=0x7fffffff ? 6 : 3) \
jpayne@69: ) \
jpayne@69: ) \
jpayne@69: ) \
jpayne@69: ) \
jpayne@69: )
jpayne@69: #endif
jpayne@69:
jpayne@69: /** The maximum number of bytes per code point. @deprecated ICU 2.4. Renamed to U8_MAX_LENGTH, see utf_old.h. */
jpayne@69: #define UTF8_MAX_CHAR_LENGTH 4
jpayne@69:
jpayne@69: /** Average number of code units compared to UTF-16. @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF8_ARRAY_SIZE(size) ((5*(size))/2)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_GET_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF8_GET_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: int32_t _utf8_get_char_unsafe_index=(int32_t)(i); \
jpayne@69: UTF8_SET_CHAR_START_UNSAFE(s, _utf8_get_char_unsafe_index); \
jpayne@69: UTF8_NEXT_CHAR_UNSAFE(s, _utf8_get_char_unsafe_index, c); \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Use U8_GET instead, see utf_old.h. */
jpayne@69: #define UTF8_GET_CHAR_SAFE(s, start, i, length, c, strict) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: int32_t _utf8_get_char_safe_index=(int32_t)(i); \
jpayne@69: UTF8_SET_CHAR_START_SAFE(s, start, _utf8_get_char_safe_index); \
jpayne@69: UTF8_NEXT_CHAR_SAFE(s, _utf8_get_char_safe_index, length, c, strict); \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_NEXT_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF8_NEXT_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (c)=(s)[(i)++]; \
jpayne@69: if((uint8_t)((c)-0xc0)<0x35) { \
jpayne@69: uint8_t __count=UTF8_COUNT_TRAIL_BYTES(c); \
jpayne@69: UTF8_MASK_LEAD_BYTE(c, __count); \
jpayne@69: switch(__count) { \
jpayne@69: /* each following branch falls through to the next one */ \
jpayne@69: case 3: \
jpayne@69: (c)=((c)<<6)|((s)[(i)++]&0x3f); \
jpayne@69: case 2: \
jpayne@69: (c)=((c)<<6)|((s)[(i)++]&0x3f); \
jpayne@69: case 1: \
jpayne@69: (c)=((c)<<6)|((s)[(i)++]&0x3f); \
jpayne@69: /* no other branches to optimize switch() */ \
jpayne@69: break; \
jpayne@69: } \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_APPEND_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF8_APPEND_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: if((uint32_t)(c)<=0x7f) { \
jpayne@69: (s)[(i)++]=(uint8_t)(c); \
jpayne@69: } else { \
jpayne@69: if((uint32_t)(c)<=0x7ff) { \
jpayne@69: (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \
jpayne@69: } else { \
jpayne@69: if((uint32_t)(c)<=0xffff) { \
jpayne@69: (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \
jpayne@69: } else { \
jpayne@69: (s)[(i)++]=(uint8_t)(((c)>>18)|0xf0); \
jpayne@69: (s)[(i)++]=(uint8_t)((((c)>>12)&0x3f)|0x80); \
jpayne@69: } \
jpayne@69: (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \
jpayne@69: } \
jpayne@69: (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_FWD_1_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF8_FWD_1_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (i)+=1+UTF8_COUNT_TRAIL_BYTES((s)[i]); \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_FWD_N_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF8_FWD_N_UNSAFE(s, i, n) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: int32_t __N=(n); \
jpayne@69: while(__N>0) { \
jpayne@69: UTF8_FWD_1_UNSAFE(s, i); \
jpayne@69: --__N; \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_SET_CP_START_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF8_SET_CHAR_START_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: while(UTF8_IS_TRAIL((s)[i])) { --(i); } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Use U8_NEXT instead, see utf_old.h. */
jpayne@69: #define UTF8_NEXT_CHAR_SAFE(s, i, length, c, strict) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (c)=(s)[(i)++]; \
jpayne@69: if((c)>=0x80) { \
jpayne@69: if(UTF8_IS_LEAD(c)) { \
jpayne@69: (c)=utf8_nextCharSafeBody(s, &(i), (int32_t)(length), c, strict); \
jpayne@69: } else { \
jpayne@69: (c)=UTF8_ERROR_VALUE_1; \
jpayne@69: } \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Use U8_APPEND instead, see utf_old.h. */
jpayne@69: #define UTF8_APPEND_CHAR_SAFE(s, i, length, c) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: if((uint32_t)(c)<=0x7f) { \
jpayne@69: (s)[(i)++]=(uint8_t)(c); \
jpayne@69: } else { \
jpayne@69: (i)=utf8_appendCharSafeBody(s, (int32_t)(i), (int32_t)(length), c, NULL); \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_FWD_1, see utf_old.h. */
jpayne@69: #define UTF8_FWD_1_SAFE(s, i, length) U8_FWD_1(s, i, length)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_FWD_N, see utf_old.h. */
jpayne@69: #define UTF8_FWD_N_SAFE(s, i, length, n) U8_FWD_N(s, i, length, n)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_SET_CP_START, see utf_old.h. */
jpayne@69: #define UTF8_SET_CHAR_START_SAFE(s, start, i) U8_SET_CP_START(s, start, i)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_PREV_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF8_PREV_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (c)=(s)[--(i)]; \
jpayne@69: if(UTF8_IS_TRAIL(c)) { \
jpayne@69: uint8_t __b, __count=1, __shift=6; \
jpayne@69: \
jpayne@69: /* c is a trail byte */ \
jpayne@69: (c)&=0x3f; \
jpayne@69: for(;;) { \
jpayne@69: __b=(s)[--(i)]; \
jpayne@69: if(__b>=0xc0) { \
jpayne@69: UTF8_MASK_LEAD_BYTE(__b, __count); \
jpayne@69: (c)|=(UChar32)__b<<__shift; \
jpayne@69: break; \
jpayne@69: } else { \
jpayne@69: (c)|=(UChar32)(__b&0x3f)<<__shift; \
jpayne@69: ++__count; \
jpayne@69: __shift+=6; \
jpayne@69: } \
jpayne@69: } \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_BACK_1_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF8_BACK_1_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: while(UTF8_IS_TRAIL((s)[--(i)])) {} \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_BACK_N_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF8_BACK_N_UNSAFE(s, i, n) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: int32_t __N=(n); \
jpayne@69: while(__N>0) { \
jpayne@69: UTF8_BACK_1_UNSAFE(s, i); \
jpayne@69: --__N; \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_SET_CP_LIMIT_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF8_SET_CHAR_LIMIT_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: UTF8_BACK_1_UNSAFE(s, i); \
jpayne@69: UTF8_FWD_1_UNSAFE(s, i); \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Use U8_PREV instead, see utf_old.h. */
jpayne@69: #define UTF8_PREV_CHAR_SAFE(s, start, i, c, strict) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (c)=(s)[--(i)]; \
jpayne@69: if((c)>=0x80) { \
jpayne@69: if((c)<=0xbf) { \
jpayne@69: (c)=utf8_prevCharSafeBody(s, start, &(i), c, strict); \
jpayne@69: } else { \
jpayne@69: (c)=UTF8_ERROR_VALUE_1; \
jpayne@69: } \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_BACK_1, see utf_old.h. */
jpayne@69: #define UTF8_BACK_1_SAFE(s, start, i) U8_BACK_1(s, start, i)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_BACK_N, see utf_old.h. */
jpayne@69: #define UTF8_BACK_N_SAFE(s, start, i, n) U8_BACK_N(s, start, i, n)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U8_SET_CP_LIMIT, see utf_old.h. */
jpayne@69: #define UTF8_SET_CHAR_LIMIT_SAFE(s, start, i, length) U8_SET_CP_LIMIT(s, start, i, length)
jpayne@69:
jpayne@69: /* Formerly utf16.h --------------------------------------------------------- */
jpayne@69:
jpayne@69: /** Is uchar a first/lead surrogate? @deprecated ICU 2.4. Renamed to U_IS_LEAD and U16_IS_LEAD, see utf_old.h. */
jpayne@69: #define UTF_IS_FIRST_SURROGATE(uchar) (((uchar)&0xfffffc00)==0xd800)
jpayne@69:
jpayne@69: /** Is uchar a second/trail surrogate? @deprecated ICU 2.4. Renamed to U_IS_TRAIL and U16_IS_TRAIL, see utf_old.h. */
jpayne@69: #define UTF_IS_SECOND_SURROGATE(uchar) (((uchar)&0xfffffc00)==0xdc00)
jpayne@69:
jpayne@69: /** Assuming c is a surrogate, is it a first/lead surrogate? @deprecated ICU 2.4. Renamed to U_IS_SURROGATE_LEAD and U16_IS_SURROGATE_LEAD, see utf_old.h. */
jpayne@69: #define UTF_IS_SURROGATE_FIRST(c) (((c)&0x400)==0)
jpayne@69:
jpayne@69: /** Helper constant for UTF16_GET_PAIR_VALUE. @deprecated ICU 2.4. Renamed to U16_SURROGATE_OFFSET, see utf_old.h. */
jpayne@69: #define UTF_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000)
jpayne@69:
jpayne@69: /** Get the UTF-32 value from the surrogate code units. @deprecated ICU 2.4. Renamed to U16_GET_SUPPLEMENTARY, see utf_old.h. */
jpayne@69: #define UTF16_GET_PAIR_VALUE(first, second) \
jpayne@69: (((first)<<10UL)+(second)-UTF_SURROGATE_OFFSET)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_LEAD, see utf_old.h. */
jpayne@69: #define UTF_FIRST_SURROGATE(supplementary) (UChar)(((supplementary)>>10)+0xd7c0)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_TRAIL, see utf_old.h. */
jpayne@69: #define UTF_SECOND_SURROGATE(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_LEAD, see utf_old.h. */
jpayne@69: #define UTF16_LEAD(supplementary) UTF_FIRST_SURROGATE(supplementary)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_TRAIL, see utf_old.h. */
jpayne@69: #define UTF16_TRAIL(supplementary) UTF_SECOND_SURROGATE(supplementary)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_IS_SINGLE, see utf_old.h. */
jpayne@69: #define UTF16_IS_SINGLE(uchar) !UTF_IS_SURROGATE(uchar)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_IS_LEAD, see utf_old.h. */
jpayne@69: #define UTF16_IS_LEAD(uchar) UTF_IS_FIRST_SURROGATE(uchar)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_IS_TRAIL, see utf_old.h. */
jpayne@69: #define UTF16_IS_TRAIL(uchar) UTF_IS_SECOND_SURROGATE(uchar)
jpayne@69:
jpayne@69: /** Does this scalar Unicode value need multiple code units for storage? @deprecated ICU 2.4. Use U16_LENGTH or test ((uint32_t)(c)>0xffff) instead, see utf_old.h. */
jpayne@69: #define UTF16_NEED_MULTIPLE_UCHAR(c) ((uint32_t)(c)>0xffff)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_LENGTH, see utf_old.h. */
jpayne@69: #define UTF16_CHAR_LENGTH(c) ((uint32_t)(c)<=0xffff ? 1 : 2)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_MAX_LENGTH, see utf_old.h. */
jpayne@69: #define UTF16_MAX_CHAR_LENGTH 2
jpayne@69:
jpayne@69: /** Average number of code units compared to UTF-16. @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF16_ARRAY_SIZE(size) (size)
jpayne@69:
jpayne@69: /**
jpayne@69: * Get a single code point from an offset that points to any
jpayne@69: * of the code units that belong to that code point.
jpayne@69: * Assume 0<=i=(start) && UTF_IS_FIRST_SURROGATE(__c2=(s)[(i)-1])) { \
jpayne@69: (c)=UTF16_GET_PAIR_VALUE(__c2, (c)); \
jpayne@69: /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \
jpayne@69: } else if(strict) {\
jpayne@69: /* unmatched second surrogate */ \
jpayne@69: (c)=UTF_ERROR_VALUE; \
jpayne@69: } \
jpayne@69: } \
jpayne@69: } else if((strict) && !UTF_IS_UNICODE_CHAR(c)) { \
jpayne@69: (c)=UTF_ERROR_VALUE; \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_NEXT_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF16_NEXT_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (c)=(s)[(i)++]; \
jpayne@69: if(UTF_IS_FIRST_SURROGATE(c)) { \
jpayne@69: (c)=UTF16_GET_PAIR_VALUE((c), (s)[(i)++]); \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_APPEND_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF16_APPEND_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: if((uint32_t)(c)<=0xffff) { \
jpayne@69: (s)[(i)++]=(uint16_t)(c); \
jpayne@69: } else { \
jpayne@69: (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
jpayne@69: (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_FWD_1_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF16_FWD_1_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: if(UTF_IS_FIRST_SURROGATE((s)[(i)++])) { \
jpayne@69: ++(i); \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_FWD_N_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF16_FWD_N_UNSAFE(s, i, n) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: int32_t __N=(n); \
jpayne@69: while(__N>0) { \
jpayne@69: UTF16_FWD_1_UNSAFE(s, i); \
jpayne@69: --__N; \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_SET_CP_START_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF16_SET_CHAR_START_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: if(UTF_IS_SECOND_SURROGATE((s)[i])) { \
jpayne@69: --(i); \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Use U16_NEXT instead, see utf_old.h. */
jpayne@69: #define UTF16_NEXT_CHAR_SAFE(s, i, length, c, strict) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (c)=(s)[(i)++]; \
jpayne@69: if(UTF_IS_FIRST_SURROGATE(c)) { \
jpayne@69: uint16_t __c2; \
jpayne@69: if((i)<(length) && UTF_IS_SECOND_SURROGATE(__c2=(s)[(i)])) { \
jpayne@69: ++(i); \
jpayne@69: (c)=UTF16_GET_PAIR_VALUE((c), __c2); \
jpayne@69: /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \
jpayne@69: } else if(strict) {\
jpayne@69: /* unmatched first surrogate */ \
jpayne@69: (c)=UTF_ERROR_VALUE; \
jpayne@69: } \
jpayne@69: } else if((strict) && !UTF_IS_UNICODE_CHAR(c)) { \
jpayne@69: /* unmatched second surrogate or other non-character */ \
jpayne@69: (c)=UTF_ERROR_VALUE; \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Use U16_APPEND instead, see utf_old.h. */
jpayne@69: #define UTF16_APPEND_CHAR_SAFE(s, i, length, c) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: if((uint32_t)(c)<=0xffff) { \
jpayne@69: (s)[(i)++]=(uint16_t)(c); \
jpayne@69: } else if((uint32_t)(c)<=0x10ffff) { \
jpayne@69: if((i)+1<(length)) { \
jpayne@69: (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
jpayne@69: (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
jpayne@69: } else /* not enough space */ { \
jpayne@69: (s)[(i)++]=UTF_ERROR_VALUE; \
jpayne@69: } \
jpayne@69: } else /* c>0x10ffff, write error value */ { \
jpayne@69: (s)[(i)++]=UTF_ERROR_VALUE; \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_FWD_1, see utf_old.h. */
jpayne@69: #define UTF16_FWD_1_SAFE(s, i, length) U16_FWD_1(s, i, length)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_FWD_N, see utf_old.h. */
jpayne@69: #define UTF16_FWD_N_SAFE(s, i, length, n) U16_FWD_N(s, i, length, n)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_SET_CP_START, see utf_old.h. */
jpayne@69: #define UTF16_SET_CHAR_START_SAFE(s, start, i) U16_SET_CP_START(s, start, i)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_PREV_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF16_PREV_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (c)=(s)[--(i)]; \
jpayne@69: if(UTF_IS_SECOND_SURROGATE(c)) { \
jpayne@69: (c)=UTF16_GET_PAIR_VALUE((s)[--(i)], (c)); \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_BACK_1_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF16_BACK_1_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: if(UTF_IS_SECOND_SURROGATE((s)[--(i)])) { \
jpayne@69: --(i); \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_BACK_N_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF16_BACK_N_UNSAFE(s, i, n) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: int32_t __N=(n); \
jpayne@69: while(__N>0) { \
jpayne@69: UTF16_BACK_1_UNSAFE(s, i); \
jpayne@69: --__N; \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_SET_CP_LIMIT_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF16_SET_CHAR_LIMIT_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: if(UTF_IS_FIRST_SURROGATE((s)[(i)-1])) { \
jpayne@69: ++(i); \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Use U16_PREV instead, see utf_old.h. */
jpayne@69: #define UTF16_PREV_CHAR_SAFE(s, start, i, c, strict) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (c)=(s)[--(i)]; \
jpayne@69: if(UTF_IS_SECOND_SURROGATE(c)) { \
jpayne@69: uint16_t __c2; \
jpayne@69: if((i)>(start) && UTF_IS_FIRST_SURROGATE(__c2=(s)[(i)-1])) { \
jpayne@69: --(i); \
jpayne@69: (c)=UTF16_GET_PAIR_VALUE(__c2, (c)); \
jpayne@69: /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \
jpayne@69: } else if(strict) {\
jpayne@69: /* unmatched second surrogate */ \
jpayne@69: (c)=UTF_ERROR_VALUE; \
jpayne@69: } \
jpayne@69: } else if((strict) && !UTF_IS_UNICODE_CHAR(c)) { \
jpayne@69: /* unmatched first surrogate or other non-character */ \
jpayne@69: (c)=UTF_ERROR_VALUE; \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_BACK_1, see utf_old.h. */
jpayne@69: #define UTF16_BACK_1_SAFE(s, start, i) U16_BACK_1(s, start, i)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_BACK_N, see utf_old.h. */
jpayne@69: #define UTF16_BACK_N_SAFE(s, start, i, n) U16_BACK_N(s, start, i, n)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_SET_CP_LIMIT, see utf_old.h. */
jpayne@69: #define UTF16_SET_CHAR_LIMIT_SAFE(s, start, i, length) U16_SET_CP_LIMIT(s, start, i, length)
jpayne@69:
jpayne@69: /* Formerly utf32.h --------------------------------------------------------- */
jpayne@69:
jpayne@69: /*
jpayne@69: * Old documentation:
jpayne@69: *
jpayne@69: * This file defines macros to deal with UTF-32 code units and code points.
jpayne@69: * Signatures and semantics are the same as for the similarly named macros
jpayne@69: * in utf16.h.
jpayne@69: * utf32.h is included by utf.h after unicode/umachine.h
jpayne@69: * and some common definitions.
jpayne@69: * Usage: ICU coding guidelines for if() statements should be followed when using these macros.
jpayne@69: * Compound statements (curly braces {}) must be used for if-else-while...
jpayne@69: * bodies and all macro statements should be terminated with semicolon.
jpayne@69: */
jpayne@69:
jpayne@69: /* internal definitions ----------------------------------------------------- */
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_IS_SAFE(c, strict) \
jpayne@69: (!(strict) ? \
jpayne@69: (uint32_t)(c)<=0x10ffff : \
jpayne@69: UTF_IS_UNICODE_CHAR(c))
jpayne@69:
jpayne@69: /*
jpayne@69: * For the semantics of all of these macros, see utf16.h.
jpayne@69: * The UTF-32 versions are trivial because any code point is
jpayne@69: * encoded using exactly one code unit.
jpayne@69: */
jpayne@69:
jpayne@69: /* single-code point definitions -------------------------------------------- */
jpayne@69:
jpayne@69: /* classes of code unit values */
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_IS_SINGLE(uchar) 1
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_IS_LEAD(uchar) 0
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_IS_TRAIL(uchar) 0
jpayne@69:
jpayne@69: /* number of code units per code point */
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_NEED_MULTIPLE_UCHAR(c) 0
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_CHAR_LENGTH(c) 1
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_MAX_CHAR_LENGTH 1
jpayne@69:
jpayne@69: /* average number of code units compared to UTF-16 */
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_ARRAY_SIZE(size) (size)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_GET_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (c)=(s)[i]; \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_GET_CHAR_SAFE(s, start, i, length, c, strict) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (c)=(s)[i]; \
jpayne@69: if(!UTF32_IS_SAFE(c, strict)) { \
jpayne@69: (c)=UTF_ERROR_VALUE; \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /* definitions with forward iteration --------------------------------------- */
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_NEXT_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (c)=(s)[(i)++]; \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_APPEND_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (s)[(i)++]=(c); \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_FWD_1_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: ++(i); \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_FWD_N_UNSAFE(s, i, n) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (i)+=(n); \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_SET_CHAR_START_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_NEXT_CHAR_SAFE(s, i, length, c, strict) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (c)=(s)[(i)++]; \
jpayne@69: if(!UTF32_IS_SAFE(c, strict)) { \
jpayne@69: (c)=UTF_ERROR_VALUE; \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_APPEND_CHAR_SAFE(s, i, length, c) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: if((uint32_t)(c)<=0x10ffff) { \
jpayne@69: (s)[(i)++]=(c); \
jpayne@69: } else /* c>0x10ffff, write 0xfffd */ { \
jpayne@69: (s)[(i)++]=0xfffd; \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_FWD_1_SAFE(s, i, length) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: ++(i); \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_FWD_N_SAFE(s, i, length, n) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: if(((i)+=(n))>(length)) { \
jpayne@69: (i)=(length); \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_SET_CHAR_START_SAFE(s, start, i) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /* definitions with backward iteration -------------------------------------- */
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_PREV_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (c)=(s)[--(i)]; \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_BACK_1_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: --(i); \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_BACK_N_UNSAFE(s, i, n) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (i)-=(n); \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_SET_CHAR_LIMIT_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_PREV_CHAR_SAFE(s, start, i, c, strict) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (c)=(s)[--(i)]; \
jpayne@69: if(!UTF32_IS_SAFE(c, strict)) { \
jpayne@69: (c)=UTF_ERROR_VALUE; \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_BACK_1_SAFE(s, start, i) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: --(i); \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_BACK_N_SAFE(s, start, i, n) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: (i)-=(n); \
jpayne@69: if((i)<(start)) { \
jpayne@69: (i)=(start); \
jpayne@69: } \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Obsolete, see utf_old.h. */
jpayne@69: #define UTF32_SET_CHAR_LIMIT_SAFE(s, i, length) UPRV_BLOCK_MACRO_BEGIN { \
jpayne@69: } UPRV_BLOCK_MACRO_END
jpayne@69:
jpayne@69: /* Formerly utf.h, part 2 --------------------------------------------------- */
jpayne@69:
jpayne@69: /**
jpayne@69: * Estimate the number of code units for a string based on the number of UTF-16 code units.
jpayne@69: *
jpayne@69: * @deprecated ICU 2.4. Obsolete, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF_ARRAY_SIZE(size) UTF16_ARRAY_SIZE(size)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_GET_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF_GET_CHAR_UNSAFE(s, i, c) UTF16_GET_CHAR_UNSAFE(s, i, c)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Use U16_GET instead, see utf_old.h. */
jpayne@69: #define UTF_GET_CHAR_SAFE(s, start, i, length, c, strict) UTF16_GET_CHAR_SAFE(s, start, i, length, c, strict)
jpayne@69:
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_NEXT_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF_NEXT_CHAR_UNSAFE(s, i, c) UTF16_NEXT_CHAR_UNSAFE(s, i, c)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Use U16_NEXT instead, see utf_old.h. */
jpayne@69: #define UTF_NEXT_CHAR_SAFE(s, i, length, c, strict) UTF16_NEXT_CHAR_SAFE(s, i, length, c, strict)
jpayne@69:
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_APPEND_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF_APPEND_CHAR_UNSAFE(s, i, c) UTF16_APPEND_CHAR_UNSAFE(s, i, c)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Use U16_APPEND instead, see utf_old.h. */
jpayne@69: #define UTF_APPEND_CHAR_SAFE(s, i, length, c) UTF16_APPEND_CHAR_SAFE(s, i, length, c)
jpayne@69:
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_FWD_1_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF_FWD_1_UNSAFE(s, i) UTF16_FWD_1_UNSAFE(s, i)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_FWD_1, see utf_old.h. */
jpayne@69: #define UTF_FWD_1_SAFE(s, i, length) UTF16_FWD_1_SAFE(s, i, length)
jpayne@69:
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_FWD_N_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF_FWD_N_UNSAFE(s, i, n) UTF16_FWD_N_UNSAFE(s, i, n)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_FWD_N, see utf_old.h. */
jpayne@69: #define UTF_FWD_N_SAFE(s, i, length, n) UTF16_FWD_N_SAFE(s, i, length, n)
jpayne@69:
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_SET_CP_START_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF_SET_CHAR_START_UNSAFE(s, i) UTF16_SET_CHAR_START_UNSAFE(s, i)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_SET_CP_START, see utf_old.h. */
jpayne@69: #define UTF_SET_CHAR_START_SAFE(s, start, i) UTF16_SET_CHAR_START_SAFE(s, start, i)
jpayne@69:
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_PREV_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF_PREV_CHAR_UNSAFE(s, i, c) UTF16_PREV_CHAR_UNSAFE(s, i, c)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Use U16_PREV instead, see utf_old.h. */
jpayne@69: #define UTF_PREV_CHAR_SAFE(s, start, i, c, strict) UTF16_PREV_CHAR_SAFE(s, start, i, c, strict)
jpayne@69:
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_BACK_1_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF_BACK_1_UNSAFE(s, i) UTF16_BACK_1_UNSAFE(s, i)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_BACK_1, see utf_old.h. */
jpayne@69: #define UTF_BACK_1_SAFE(s, start, i) UTF16_BACK_1_SAFE(s, start, i)
jpayne@69:
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_BACK_N_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF_BACK_N_UNSAFE(s, i, n) UTF16_BACK_N_UNSAFE(s, i, n)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_BACK_N, see utf_old.h. */
jpayne@69: #define UTF_BACK_N_SAFE(s, start, i, n) UTF16_BACK_N_SAFE(s, start, i, n)
jpayne@69:
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_SET_CP_LIMIT_UNSAFE, see utf_old.h. */
jpayne@69: #define UTF_SET_CHAR_LIMIT_UNSAFE(s, i) UTF16_SET_CHAR_LIMIT_UNSAFE(s, i)
jpayne@69:
jpayne@69: /** @deprecated ICU 2.4. Renamed to U16_SET_CP_LIMIT, see utf_old.h. */
jpayne@69: #define UTF_SET_CHAR_LIMIT_SAFE(s, start, i, length) UTF16_SET_CHAR_LIMIT_SAFE(s, start, i, length)
jpayne@69:
jpayne@69: /* Define default macros (UTF-16 "safe") ------------------------------------ */
jpayne@69:
jpayne@69: /**
jpayne@69: * Does this code unit alone encode a code point (BMP, not a surrogate)?
jpayne@69: * Same as UTF16_IS_SINGLE.
jpayne@69: * @deprecated ICU 2.4. Renamed to U_IS_SINGLE and U16_IS_SINGLE, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF_IS_SINGLE(uchar) U16_IS_SINGLE(uchar)
jpayne@69:
jpayne@69: /**
jpayne@69: * Is this code unit the first one of several (a lead surrogate)?
jpayne@69: * Same as UTF16_IS_LEAD.
jpayne@69: * @deprecated ICU 2.4. Renamed to U_IS_LEAD and U16_IS_LEAD, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF_IS_LEAD(uchar) U16_IS_LEAD(uchar)
jpayne@69:
jpayne@69: /**
jpayne@69: * Is this code unit one of several but not the first one (a trail surrogate)?
jpayne@69: * Same as UTF16_IS_TRAIL.
jpayne@69: * @deprecated ICU 2.4. Renamed to U_IS_TRAIL and U16_IS_TRAIL, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF_IS_TRAIL(uchar) U16_IS_TRAIL(uchar)
jpayne@69:
jpayne@69: /**
jpayne@69: * Does this code point require multiple code units (is it a supplementary code point)?
jpayne@69: * Same as UTF16_NEED_MULTIPLE_UCHAR.
jpayne@69: * @deprecated ICU 2.4. Use U16_LENGTH or test ((uint32_t)(c)>0xffff) instead.
jpayne@69: */
jpayne@69: #define UTF_NEED_MULTIPLE_UCHAR(c) UTF16_NEED_MULTIPLE_UCHAR(c)
jpayne@69:
jpayne@69: /**
jpayne@69: * How many code units are used to encode this code point (1 or 2)?
jpayne@69: * Same as UTF16_CHAR_LENGTH.
jpayne@69: * @deprecated ICU 2.4. Renamed to U16_LENGTH, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF_CHAR_LENGTH(c) U16_LENGTH(c)
jpayne@69:
jpayne@69: /**
jpayne@69: * How many code units are used at most for any Unicode code point (2)?
jpayne@69: * Same as UTF16_MAX_CHAR_LENGTH.
jpayne@69: * @deprecated ICU 2.4. Renamed to U16_MAX_LENGTH, see utf_old.h.
jpayne@69: */
jpayne@69: #define UTF_MAX_CHAR_LENGTH U16_MAX_LENGTH
jpayne@69:
jpayne@69: /**
jpayne@69: * Set c to the code point that contains the code unit i.
jpayne@69: * i could point to the lead or the trail surrogate for the code point.
jpayne@69: * i is not modified.
jpayne@69: * Same as UTF16_GET_CHAR.
jpayne@69: * \pre 0<=i