X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..340931cb2e044a2141d11567dd0f782524e32994:/icuSources/common/utrie.h diff --git a/icuSources/common/utrie.h b/icuSources/common/utrie.h index d8d77ac4..532ba778 100644 --- a/icuSources/common/utrie.h +++ b/icuSources/common/utrie.h @@ -1,12 +1,14 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ****************************************************************************** * -* Copyright (C) 2001-2006, International Business Machines +* Copyright (C) 2001-2011, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** * file name: utrie.h -* encoding: US-ASCII +* encoding: UTF-8 * tab size: 8 (not used) * indentation:4 * @@ -18,7 +20,7 @@ #define __UTRIE_H__ #include "unicode/utypes.h" -#include "udataswp.h" +#include "unicode/utf16.h" U_CDECL_BEGIN @@ -168,7 +170,9 @@ struct UTrie { UBool isLatin1Linear; }; +#ifndef __UTRIE2_H__ typedef struct UTrie UTrie; +#endif /** Internal trie getter from an offset (0 if c16 is a BMP/lead units) and a 16-bit unit */ #define _UTRIE_GET_RAW(trie, data, offset, c16) \ @@ -178,7 +182,7 @@ typedef struct UTrie UTrie; ] /** Internal trie getter from a pair of surrogates */ -#define _UTRIE_GET_FROM_PAIR(trie, data, c, c2, result, resultType) { \ +#define _UTRIE_GET_FROM_PAIR(trie, data, c, c2, result, resultType) UPRV_BLOCK_MACRO_BEGIN { \ int32_t __offset; \ \ /* get data for lead surrogate */ \ @@ -191,37 +195,38 @@ typedef struct UTrie UTrie; } else { \ (result)=(resultType)((trie)->initialValue); \ } \ -} +} UPRV_BLOCK_MACRO_END /** Internal trie getter from a BMP code point, treating a lead surrogate as a normal code point */ #define _UTRIE_GET_FROM_BMP(trie, data, c16) \ - _UTRIE_GET_RAW(trie, data, 0xd800<=(c16) && (c16)<=0xdbff ? UTRIE_LEAD_INDEX_DISP : 0, c16); + _UTRIE_GET_RAW(trie, data, 0xd800<=(c16) && (c16)<=0xdbff ? UTRIE_LEAD_INDEX_DISP : 0, c16) /** * Internal trie getter from a code point. * Could be faster(?) but longer with * if((c32)<=0xd7ff) { (result)=_UTRIE_GET_RAW(trie, data, 0, c32); } */ -#define _UTRIE_GET(trie, data, c32, result, resultType) \ +#define _UTRIE_GET(trie, data, c32, result, resultType) UPRV_BLOCK_MACRO_BEGIN { \ if((uint32_t)(c32)<=0xffff) { \ /* BMP code points */ \ (result)=_UTRIE_GET_FROM_BMP(trie, data, c32); \ } else if((uint32_t)(c32)<=0x10ffff) { \ /* supplementary code point */ \ - UChar __lead16=UTF16_LEAD(c32); \ + UChar __lead16=U16_LEAD(c32); \ _UTRIE_GET_FROM_PAIR(trie, data, __lead16, c32, result, resultType); \ } else { \ /* out of range */ \ (result)=(resultType)((trie)->initialValue); \ - } + } \ +} UPRV_BLOCK_MACRO_END /** Internal next-post-increment: get the next code point (c, c2) and its data */ -#define _UTRIE_NEXT(trie, data, src, limit, c, c2, result, resultType) { \ +#define _UTRIE_NEXT(trie, data, src, limit, c, c2, result, resultType) UPRV_BLOCK_MACRO_BEGIN { \ (c)=*(src)++; \ - if(!UTF_IS_LEAD(c)) { \ + if(!U16_IS_LEAD(c)) { \ (c2)=0; \ (result)=_UTRIE_GET_RAW((trie), data, 0, (c)); \ - } else if((src)!=(limit) && UTF_IS_TRAIL((c2)=*(src))) { \ + } else if((src)!=(limit) && U16_IS_TRAIL((c2)=*(src))) { \ ++(src); \ _UTRIE_GET_FROM_PAIR((trie), data, (c), (c2), (result), resultType); \ } else { \ @@ -229,17 +234,17 @@ typedef struct UTrie UTrie; (c2)=0; \ (result)=_UTRIE_GET_RAW((trie), data, UTRIE_LEAD_INDEX_DISP, (c)); \ } \ -} +} UPRV_BLOCK_MACRO_END /** Internal previous: get the previous code point (c, c2) and its data */ -#define _UTRIE_PREVIOUS(trie, data, start, src, c, c2, result, resultType) { \ +#define _UTRIE_PREVIOUS(trie, data, start, src, c, c2, result, resultType) UPRV_BLOCK_MACRO_BEGIN { \ (c)=*--(src); \ - if(!UTF_IS_SURROGATE(c)) { \ + if(!U16_IS_SURROGATE(c)) { \ (c2)=0; \ (result)=_UTRIE_GET_RAW((trie), data, 0, (c)); \ - } else if(!UTF_IS_SURROGATE_FIRST(c)) { \ + } else if(!U16_IS_SURROGATE_LEAD(c)) { \ /* trail surrogate */ \ - if((start)!=(src) && UTF_IS_LEAD((c2)=*((src)-1))) { \ + if((start)!=(src) && U16_IS_LEAD((c2)=*((src)-1))) { \ --(src); \ (result)=(c); (c)=(c2); (c2)=(UChar)(result); /* swap c, c2 */ \ _UTRIE_GET_FROM_PAIR((trie), data, (c), (c2), (result), resultType); \ @@ -253,7 +258,7 @@ typedef struct UTrie UTrie; (c2)=0; \ (result)=_UTRIE_GET_RAW((trie), data, UTRIE_LEAD_INDEX_DISP, (c)); \ } \ -} +} UPRV_BLOCK_MACRO_END /* Public UTrie API ---------------------------------------------------------*/ @@ -551,7 +556,7 @@ struct UNewTrie { * Index values at build-time are 32 bits wide for easier processing. * Bit 31 is set if the data block is used by multiple index values (from utrie_setRange()). */ - int32_t index[UTRIE_MAX_INDEX_LENGTH]; + int32_t index[UTRIE_MAX_INDEX_LENGTH+UTRIE_SURROGATE_BLOCK_COUNT]; uint32_t *data; uint32_t leadUnitValue; @@ -727,17 +732,13 @@ utrie_serialize(UNewTrie *trie, void *data, int32_t capacity, UBool reduceTo16Bits, UErrorCode *pErrorCode); -/** - * Swap a serialized UTrie. - * @internal - */ -U_CAPI int32_t U_EXPORT2 -utrie_swap(const UDataSwapper *ds, - const void *inData, int32_t length, void *outData, - UErrorCode *pErrorCode); - /* serialization ------------------------------------------------------------ */ +// UTrie signature values, in platform endianness and opposite endianness. +// The UTrie signature ASCII byte values spell "Trie". +#define UTRIE_SIG 0x54726965 +#define UTRIE_OE_SIG 0x65697254 + /** * Trie data structure in serialized form: *