1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru******************************************************************************* 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 427f654740f2a26ad62a5c155af9199af9e69b889claireho* Copyright (C) 1999-2010, International Business Machines 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Corporation and others. All Rights Reserved. 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru******************************************************************************* 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* file name: utf16.h 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* encoding: US-ASCII 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* tab size: 8 (not used) 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* indentation:4 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* created on: 1999sep09 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* created by: Markus W. Scherer 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * \file 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * \brief C API: 16-bit Unicode handling macros 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * This file defines macros to deal with 16-bit Unicode (UTF-16) code units and strings. 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * utf16.h is included by utf.h after unicode/umachine.h 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and some common definitions. 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * For more information see utf.h and the ICU User Guide Strings chapter 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (http://icu-project.org/userguide/strings.html). 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <em>Usage:</em> 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ICU coding guidelines for if() statements should be followed when using these macros. 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Compound statements (curly braces {}) must be used for if-else-while... 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * bodies and all macro statements should be terminated with semicolon. 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef __UTF16_H__ 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define __UTF16_H__ 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* utf.h must be included first. */ 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef __UTF_H__ 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru# include "unicode/utf.h" 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* single-code point definitions -------------------------------------------- */ 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Does this code unit alone encode a code point (BMP, not a surrogate)? 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param c 16-bit code unit 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return TRUE or FALSE 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_IS_SINGLE(c) !U_IS_SURROGATE(c) 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Is this code unit a lead surrogate (U+d800..U+dbff)? 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param c 16-bit code unit 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return TRUE or FALSE 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_IS_LEAD(c) (((c)&0xfffffc00)==0xd800) 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Is this code unit a trail surrogate (U+dc00..U+dfff)? 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param c 16-bit code unit 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return TRUE or FALSE 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_IS_TRAIL(c) (((c)&0xfffffc00)==0xdc00) 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Is this code unit a surrogate (U+d800..U+dfff)? 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param c 16-bit code unit 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return TRUE or FALSE 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_IS_SURROGATE(c) U_IS_SURROGATE(c) 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Assuming c is a surrogate code point (U16_IS_SURROGATE(c)), 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * is it a lead surrogate? 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param c 16-bit code unit 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return TRUE or FALSE 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_IS_SURROGATE_LEAD(c) (((c)&0x400)==0) 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 8685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Assuming c is a surrogate code point (U16_IS_SURROGATE(c)), 8785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * is it a trail surrogate? 8885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * @param c 16-bit code unit 8985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * @return TRUE or FALSE 9027f654740f2a26ad62a5c155af9199af9e69b889claireho * @stable ICU 4.2 9185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho */ 9285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#define U16_IS_SURROGATE_TRAIL(c) (((c)&0x400)!=0) 9385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 9485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/** 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Helper constant for U16_GET_SUPPLEMENTARY. 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @internal 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000) 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Get a supplementary code point value (U+10000..U+10ffff) 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * from its lead and trail surrogates. 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The result is undefined if the input values are not 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * lead and trail surrogates. 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param lead lead surrogate (U+d800..U+dbff) 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param trail trail surrogate (U+dc00..U+dfff) 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return supplementary code point (U+10000..U+10ffff) 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_GET_SUPPLEMENTARY(lead, trail) \ 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (((UChar32)(lead)<<10UL)+(UChar32)(trail)-U16_SURROGATE_OFFSET) 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Get the lead surrogate (0xd800..0xdbff) for a 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * supplementary code point (0x10000..0x10ffff). 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param supplementary 32-bit code point (U+10000..U+10ffff) 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return lead surrogate (U+d800..U+dbff) for supplementary 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_LEAD(supplementary) (UChar)(((supplementary)>>10)+0xd7c0) 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Get the trail surrogate (0xdc00..0xdfff) for a 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * supplementary code point (0x10000..0x10ffff). 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param supplementary 32-bit code point (U+10000..U+10ffff) 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return trail surrogate (U+dc00..U+dfff) for supplementary 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_TRAIL(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00) 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * How many 16-bit code units are used to encode this Unicode code point? (1 or 2) 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The result is not defined if c is not a Unicode code point (U+0000..U+10ffff). 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param c 32-bit code point 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return 1 or 2 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_LENGTH(c) ((uint32_t)(c)<=0xffff ? 1 : 2) 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The maximum number of 16-bit code units per Unicode code point (U+0000..U+10ffff). 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return 2 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_MAX_LENGTH 2 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Get a code point from a string at a random-access offset, 151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * without changing the offset. 152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Unsafe" macro, assumes well-formed UTF-16. 153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The offset may point to either the lead or trail surrogate unit 155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * for a supplementary code point, in which case the macro will read 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the adjacent matching surrogate as well. 157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The result is undefined if the offset points to a single, unpaired surrogate. 158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Iteration through a string is more efficient with U16_NEXT_UNSAFE or U16_NEXT. 159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset 162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param c output UChar32 variable 163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_GET 164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_GET_UNSAFE(s, i, c) { \ 167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (c)=(s)[i]; \ 168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U16_IS_SURROGATE(c)) { \ 169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U16_IS_SURROGATE_LEAD(c)) { \ 170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (c)=U16_GET_SUPPLEMENTARY((c), (s)[(i)+1]); \ 171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { \ 172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (c)=U16_GET_SUPPLEMENTARY((s)[(i)-1], (c)); \ 173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Get a code point from a string at a random-access offset, 179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * without changing the offset. 180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Safe" macro, handles unpaired surrogates and checks for string boundaries. 181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The offset may point to either the lead or trail surrogate unit 183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * for a supplementary code point, in which case the macro will read 184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the adjacent matching surrogate as well. 185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If the offset points to a single, unpaired surrogate, then that itself 186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * will be returned as the code point. 187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Iteration through a string is more efficient with U16_NEXT_UNSAFE or U16_NEXT. 188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param start starting string offset (usually 0) 191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset, must be start<=i<length 192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param length string length 193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param c output UChar32 variable 194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_GET_UNSAFE 195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_GET(s, start, i, length, c) { \ 198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (c)=(s)[i]; \ 199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U16_IS_SURROGATE(c)) { \ 200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t __c2; \ 201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U16_IS_SURROGATE_LEAD(c)) { \ 202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if((i)+1<(length) && U16_IS_TRAIL(__c2=(s)[(i)+1])) { \ 203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (c)=U16_GET_SUPPLEMENTARY((c), __c2); \ 204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { \ 20627f654740f2a26ad62a5c155af9199af9e69b889claireho if((i)>(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \ 207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \ 208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* definitions with forward iteration --------------------------------------- */ 214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Get a code point from a string at a code point boundary offset, 217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and advance the offset to the next code point boundary. 218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (Post-incrementing forward iteration.) 219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Unsafe" macro, assumes well-formed UTF-16. 220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The offset may point to the lead surrogate unit 222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * for a supplementary code point, in which case the macro will read 223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the following trail surrogate as well. 224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If the offset points to a trail surrogate, then that itself 225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * will be returned as the code point. 226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The result is undefined if the offset points to a single, unpaired lead surrogate. 227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset 230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param c output UChar32 variable 231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_NEXT 232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_NEXT_UNSAFE(s, i, c) { \ 235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (c)=(s)[(i)++]; \ 236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U16_IS_LEAD(c)) { \ 237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (c)=U16_GET_SUPPLEMENTARY((c), (s)[(i)++]); \ 238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Get a code point from a string at a code point boundary offset, 243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and advance the offset to the next code point boundary. 244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (Post-incrementing forward iteration.) 245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Safe" macro, handles unpaired surrogates and checks for string boundaries. 246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The offset may point to the lead surrogate unit 248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * for a supplementary code point, in which case the macro will read 249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the following trail surrogate as well. 250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If the offset points to a trail surrogate or 251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * to a single, unpaired lead surrogate, then that itself 252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * will be returned as the code point. 253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset, must be i<length 256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param length string length 257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param c output UChar32 variable 258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_NEXT_UNSAFE 259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_NEXT(s, i, length, c) { \ 262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (c)=(s)[(i)++]; \ 263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U16_IS_LEAD(c)) { \ 264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t __c2; \ 265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if((i)<(length) && U16_IS_TRAIL(__c2=(s)[(i)])) { \ 266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++(i); \ 267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (c)=U16_GET_SUPPLEMENTARY((c), __c2); \ 268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Append a code point to a string, overwriting 1 or 2 code units. 274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The offset points to the current end of the string contents 275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and is advanced (post-increment). 276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Unsafe" macro, assumes a valid code point and sufficient space in the string. 277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Otherwise, the result is undefined. 278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string buffer 280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset 281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param c code point to append 282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_APPEND 283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_APPEND_UNSAFE(s, i, c) { \ 286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if((uint32_t)(c)<=0xffff) { \ 287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (s)[(i)++]=(uint16_t)(c); \ 288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { \ 289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \ 290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \ 291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Append a code point to a string, overwriting 1 or 2 code units. 296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The offset points to the current end of the string contents 297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and is advanced (post-increment). 298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Safe" macro, checks for a valid code point. 299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If a surrogate pair is written, checks for sufficient space in the string. 300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If the code point is not valid or a trail surrogate does not fit, 301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * then isError is set to TRUE. 302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string buffer 304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset, must be i<capacity 305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param capacity size of the string buffer 306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param c code point to append 307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param isError output UBool set to TRUE if an error occurs, otherwise not modified 308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_APPEND_UNSAFE 309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_APPEND(s, i, capacity, c, isError) { \ 312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if((uint32_t)(c)<=0xffff) { \ 313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (s)[(i)++]=(uint16_t)(c); \ 314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else if((uint32_t)(c)<=0x10ffff && (i)+1<(capacity)) { \ 315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \ 316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \ 317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else /* c>0x10ffff or not enough space */ { \ 318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (isError)=TRUE; \ 319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Advance the string offset from one code point boundary to the next. 324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (Post-incrementing iteration.) 325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Unsafe" macro, assumes well-formed UTF-16. 326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset 329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_FWD_1 330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_FWD_1_UNSAFE(s, i) { \ 333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U16_IS_LEAD((s)[(i)++])) { \ 334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++(i); \ 335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Advance the string offset from one code point boundary to the next. 340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (Post-incrementing iteration.) 341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Safe" macro, handles unpaired surrogates and checks for string boundaries. 342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset, must be i<length 345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param length string length 346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_FWD_1_UNSAFE 347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_FWD_1(s, i, length) { \ 350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U16_IS_LEAD((s)[(i)++]) && (i)<(length) && U16_IS_TRAIL((s)[i])) { \ 351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++(i); \ 352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Advance the string offset from one code point boundary to the n-th next one, 357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * i.e., move forward by n code points. 358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (Post-incrementing iteration.) 359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Unsafe" macro, assumes well-formed UTF-16. 360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset 363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param n number of code points to skip 364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_FWD_N 365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_FWD_N_UNSAFE(s, i, n) { \ 368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t __N=(n); \ 369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while(__N>0) { \ 370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U16_FWD_1_UNSAFE(s, i); \ 371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru --__N; \ 372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Advance the string offset from one code point boundary to the n-th next one, 377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * i.e., move forward by n code points. 378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (Post-incrementing iteration.) 379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Safe" macro, handles unpaired surrogates and checks for string boundaries. 380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset, must be i<length 383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param length string length 384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param n number of code points to skip 385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_FWD_N_UNSAFE 386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_FWD_N(s, i, length, n) { \ 389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t __N=(n); \ 390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while(__N>0 && (i)<(length)) { \ 391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U16_FWD_1(s, i, length); \ 392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru --__N; \ 393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Adjust a random-access offset to a code point boundary 398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * at the start of a code point. 399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If the offset points to the trail surrogate of a surrogate pair, 400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * then the offset is decremented. 401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Otherwise, it is not modified. 402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Unsafe" macro, assumes well-formed UTF-16. 403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset 406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_SET_CP_START 407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_SET_CP_START_UNSAFE(s, i) { \ 410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U16_IS_TRAIL((s)[i])) { \ 411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru --(i); \ 412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Adjust a random-access offset to a code point boundary 417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * at the start of a code point. 418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If the offset points to the trail surrogate of a surrogate pair, 419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * then the offset is decremented. 420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Otherwise, it is not modified. 421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Safe" macro, handles unpaired surrogates and checks for string boundaries. 422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param start starting string offset (usually 0) 425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset, must be start<=i 426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_SET_CP_START_UNSAFE 427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_SET_CP_START(s, start, i) { \ 430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U16_IS_TRAIL((s)[i]) && (i)>(start) && U16_IS_LEAD((s)[(i)-1])) { \ 431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru --(i); \ 432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* definitions with backward iteration -------------------------------------- */ 436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Move the string offset from one code point boundary to the previous one 439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and get the code point between them. 440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (Pre-decrementing backward iteration.) 441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Unsafe" macro, assumes well-formed UTF-16. 442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The input offset may be the same as the string length. 444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If the offset is behind a trail surrogate unit 445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * for a supplementary code point, then the macro will read 446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the preceding lead surrogate as well. 447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If the offset is behind a lead surrogate, then that itself 448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * will be returned as the code point. 449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The result is undefined if the offset is behind a single, unpaired trail surrogate. 450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset 453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param c output UChar32 variable 454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_PREV 455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_PREV_UNSAFE(s, i, c) { \ 458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (c)=(s)[--(i)]; \ 459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U16_IS_TRAIL(c)) { \ 460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (c)=U16_GET_SUPPLEMENTARY((s)[--(i)], (c)); \ 461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Move the string offset from one code point boundary to the previous one 466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and get the code point between them. 467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (Pre-decrementing backward iteration.) 468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Safe" macro, handles unpaired surrogates and checks for string boundaries. 469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The input offset may be the same as the string length. 471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If the offset is behind a trail surrogate unit 472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * for a supplementary code point, then the macro will read 473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the preceding lead surrogate as well. 474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If the offset is behind a lead surrogate or behind a single, unpaired 475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * trail surrogate, then that itself 476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * will be returned as the code point. 477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 478ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param start starting string offset (usually 0) 480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset, must be start<i 481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param c output UChar32 variable 482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_PREV_UNSAFE 483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_PREV(s, start, i, c) { \ 486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (c)=(s)[--(i)]; \ 487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U16_IS_TRAIL(c)) { \ 488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint16_t __c2; \ 489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if((i)>(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \ 490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru --(i); \ 491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \ 492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Move the string offset from one code point boundary to the previous one. 498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (Pre-decrementing backward iteration.) 499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The input offset may be the same as the string length. 500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Unsafe" macro, assumes well-formed UTF-16. 501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset 504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_BACK_1 505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_BACK_1_UNSAFE(s, i) { \ 508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U16_IS_TRAIL((s)[--(i)])) { \ 509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru --(i); \ 510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Move the string offset from one code point boundary to the previous one. 515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (Pre-decrementing backward iteration.) 516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The input offset may be the same as the string length. 517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Safe" macro, handles unpaired surrogates and checks for string boundaries. 518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param start starting string offset (usually 0) 521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset, must be start<i 522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_BACK_1_UNSAFE 523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_BACK_1(s, start, i) { \ 526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U16_IS_TRAIL((s)[--(i)]) && (i)>(start) && U16_IS_LEAD((s)[(i)-1])) { \ 527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru --(i); \ 528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Move the string offset from one code point boundary to the n-th one before it, 533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * i.e., move backward by n code points. 534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (Pre-decrementing backward iteration.) 535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The input offset may be the same as the string length. 536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Unsafe" macro, assumes well-formed UTF-16. 537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset 540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param n number of code points to skip 541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_BACK_N 542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_BACK_N_UNSAFE(s, i, n) { \ 545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t __N=(n); \ 546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while(__N>0) { \ 547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U16_BACK_1_UNSAFE(s, i); \ 548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru --__N; \ 549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Move the string offset from one code point boundary to the n-th one before it, 554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * i.e., move backward by n code points. 555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * (Pre-decrementing backward iteration.) 556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The input offset may be the same as the string length. 557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Safe" macro, handles unpaired surrogates and checks for string boundaries. 558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param start start of string 561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset, must be start<i 562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param n number of code points to skip 563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_BACK_N_UNSAFE 564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_BACK_N(s, start, i, n) { \ 567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t __N=(n); \ 568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while(__N>0 && (i)>(start)) { \ 569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U16_BACK_1(s, start, i); \ 570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru --__N; \ 571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Adjust a random-access offset to a code point boundary after a code point. 576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If the offset is behind the lead surrogate of a surrogate pair, 577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * then the offset is incremented. 578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Otherwise, it is not modified. 579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The input offset may be the same as the string length. 580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Unsafe" macro, assumes well-formed UTF-16. 581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset 584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_SET_CP_LIMIT 585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_SET_CP_LIMIT_UNSAFE(s, i) { \ 588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U16_IS_LEAD((s)[(i)-1])) { \ 589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++(i); \ 590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Adjust a random-access offset to a code point boundary after a code point. 595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * If the offset is behind the lead surrogate of a surrogate pair, 596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * then the offset is incremented. 597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Otherwise, it is not modified. 598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * The input offset may be the same as the string length. 599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * "Safe" macro, handles unpaired surrogates and checks for string boundaries. 600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param s const UChar * string 602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param start starting string offset (usually 0) 603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param i string offset, start<=i<=length 604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param length string length 605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @see U16_SET_CP_LIMIT_UNSAFE 606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4 607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define U16_SET_CP_LIMIT(s, start, i, length) { \ 609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if((start)<(i) && (i)<(length) && U16_IS_LEAD((s)[(i)-1]) && U16_IS_TRAIL((s)[i])) { \ 610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++(i); \ 611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } \ 612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 615