1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker /* 4*0e209d39SAndroid Build Coastguard Worker ******************************************************************************* 5*0e209d39SAndroid Build Coastguard Worker * 6*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2004-2012, International Business Machines 7*0e209d39SAndroid Build Coastguard Worker * Corporation and others. All Rights Reserved. 8*0e209d39SAndroid Build Coastguard Worker * 9*0e209d39SAndroid Build Coastguard Worker ******************************************************************************* 10*0e209d39SAndroid Build Coastguard Worker * file name: utext.h 11*0e209d39SAndroid Build Coastguard Worker * encoding: UTF-8 12*0e209d39SAndroid Build Coastguard Worker * tab size: 8 (not used) 13*0e209d39SAndroid Build Coastguard Worker * indentation:4 14*0e209d39SAndroid Build Coastguard Worker * 15*0e209d39SAndroid Build Coastguard Worker * created on: 2004oct06 16*0e209d39SAndroid Build Coastguard Worker * created by: Markus W. Scherer 17*0e209d39SAndroid Build Coastguard Worker */ 18*0e209d39SAndroid Build Coastguard Worker 19*0e209d39SAndroid Build Coastguard Worker #ifndef __UTEXT_H__ 20*0e209d39SAndroid Build Coastguard Worker #define __UTEXT_H__ 21*0e209d39SAndroid Build Coastguard Worker 22*0e209d39SAndroid Build Coastguard Worker /** 23*0e209d39SAndroid Build Coastguard Worker * \file 24*0e209d39SAndroid Build Coastguard Worker * \brief C API: Abstract Unicode Text API 25*0e209d39SAndroid Build Coastguard Worker * 26*0e209d39SAndroid Build Coastguard Worker * The Text Access API provides a means to allow text that is stored in alternative 27*0e209d39SAndroid Build Coastguard Worker * formats to work with ICU services. ICU normally operates on text that is 28*0e209d39SAndroid Build Coastguard Worker * stored in UTF-16 format, in (UChar *) arrays for the C APIs or as type 29*0e209d39SAndroid Build Coastguard Worker * UnicodeString for C++ APIs. 30*0e209d39SAndroid Build Coastguard Worker * 31*0e209d39SAndroid Build Coastguard Worker * ICU Text Access allows other formats, such as UTF-8 or non-contiguous 32*0e209d39SAndroid Build Coastguard Worker * UTF-16 strings, to be placed in a UText wrapper and then passed to ICU services. 33*0e209d39SAndroid Build Coastguard Worker * 34*0e209d39SAndroid Build Coastguard Worker * There are three general classes of usage for UText: 35*0e209d39SAndroid Build Coastguard Worker * 36*0e209d39SAndroid Build Coastguard Worker * Application Level Use. This is the simplest usage - applications would 37*0e209d39SAndroid Build Coastguard Worker * use one of the utext_open() functions on their input text, and pass 38*0e209d39SAndroid Build Coastguard Worker * the resulting UText to the desired ICU service. 39*0e209d39SAndroid Build Coastguard Worker * 40*0e209d39SAndroid Build Coastguard Worker * Second is usage in ICU Services, such as break iteration, that will need to 41*0e209d39SAndroid Build Coastguard Worker * operate on input presented to them as a UText. These implementations 42*0e209d39SAndroid Build Coastguard Worker * will need to use the iteration and related UText functions to gain 43*0e209d39SAndroid Build Coastguard Worker * access to the actual text. 44*0e209d39SAndroid Build Coastguard Worker * 45*0e209d39SAndroid Build Coastguard Worker * The third class of UText users are "text providers." These are the 46*0e209d39SAndroid Build Coastguard Worker * UText implementations for the various text storage formats. An application 47*0e209d39SAndroid Build Coastguard Worker * or system with a unique text storage format can implement a set of 48*0e209d39SAndroid Build Coastguard Worker * UText provider functions for that format, which will then allow 49*0e209d39SAndroid Build Coastguard Worker * ICU services to operate on that format. 50*0e209d39SAndroid Build Coastguard Worker * 51*0e209d39SAndroid Build Coastguard Worker * 52*0e209d39SAndroid Build Coastguard Worker * <em>Iterating over text</em> 53*0e209d39SAndroid Build Coastguard Worker * 54*0e209d39SAndroid Build Coastguard Worker * Here is sample code for a forward iteration over the contents of a UText 55*0e209d39SAndroid Build Coastguard Worker * 56*0e209d39SAndroid Build Coastguard Worker * \code 57*0e209d39SAndroid Build Coastguard Worker * UChar32 c; 58*0e209d39SAndroid Build Coastguard Worker * UText *ut = whatever(); 59*0e209d39SAndroid Build Coastguard Worker * 60*0e209d39SAndroid Build Coastguard Worker * for (c=utext_next32From(ut, 0); c>=0; c=utext_next32(ut)) { 61*0e209d39SAndroid Build Coastguard Worker * // do whatever with the codepoint c here. 62*0e209d39SAndroid Build Coastguard Worker * } 63*0e209d39SAndroid Build Coastguard Worker * \endcode 64*0e209d39SAndroid Build Coastguard Worker * 65*0e209d39SAndroid Build Coastguard Worker * And here is similar code to iterate in the reverse direction, from the end 66*0e209d39SAndroid Build Coastguard Worker * of the text towards the beginning. 67*0e209d39SAndroid Build Coastguard Worker * 68*0e209d39SAndroid Build Coastguard Worker * \code 69*0e209d39SAndroid Build Coastguard Worker * UChar32 c; 70*0e209d39SAndroid Build Coastguard Worker * UText *ut = whatever(); 71*0e209d39SAndroid Build Coastguard Worker * int textLength = utext_nativeLength(ut); 72*0e209d39SAndroid Build Coastguard Worker * for (c=utext_previous32From(ut, textLength); c>=0; c=utext_previous32(ut)) { 73*0e209d39SAndroid Build Coastguard Worker * // do whatever with the codepoint c here. 74*0e209d39SAndroid Build Coastguard Worker * } 75*0e209d39SAndroid Build Coastguard Worker * \endcode 76*0e209d39SAndroid Build Coastguard Worker * 77*0e209d39SAndroid Build Coastguard Worker * <em>Characters and Indexing</em> 78*0e209d39SAndroid Build Coastguard Worker * 79*0e209d39SAndroid Build Coastguard Worker * Indexing into text by UText functions is nearly always in terms of the native 80*0e209d39SAndroid Build Coastguard Worker * indexing of the underlying text storage. The storage format could be UTF-8 81*0e209d39SAndroid Build Coastguard Worker * or UTF-32, for example. When coding to the UText access API, no assumptions 82*0e209d39SAndroid Build Coastguard Worker * can be made regarding the size of characters, or how far an index 83*0e209d39SAndroid Build Coastguard Worker * may move when iterating between characters. 84*0e209d39SAndroid Build Coastguard Worker * 85*0e209d39SAndroid Build Coastguard Worker * All indices supplied to UText functions are pinned to the length of the 86*0e209d39SAndroid Build Coastguard Worker * text. An out-of-bounds index is not considered to be an error, but is 87*0e209d39SAndroid Build Coastguard Worker * adjusted to be in the range 0 <= index <= length of input text. 88*0e209d39SAndroid Build Coastguard Worker * 89*0e209d39SAndroid Build Coastguard Worker * 90*0e209d39SAndroid Build Coastguard Worker * When an index position is returned from a UText function, it will be 91*0e209d39SAndroid Build Coastguard Worker * a native index to the underlying text. In the case of multi-unit characters, 92*0e209d39SAndroid Build Coastguard Worker * it will always refer to the first position of the character, 93*0e209d39SAndroid Build Coastguard Worker * never to the interior. This is essentially the same thing as saying that 94*0e209d39SAndroid Build Coastguard Worker * a returned index will always point to a boundary between characters. 95*0e209d39SAndroid Build Coastguard Worker * 96*0e209d39SAndroid Build Coastguard Worker * When a native index is supplied to a UText function, all indices that 97*0e209d39SAndroid Build Coastguard Worker * refer to any part of a multi-unit character representation are considered 98*0e209d39SAndroid Build Coastguard Worker * to be equivalent. In the case of multi-unit characters, an incoming index 99*0e209d39SAndroid Build Coastguard Worker * will be logically normalized to refer to the start of the character. 100*0e209d39SAndroid Build Coastguard Worker * 101*0e209d39SAndroid Build Coastguard Worker * It is possible to test whether a native index is on a code point boundary 102*0e209d39SAndroid Build Coastguard Worker * by doing a utext_setNativeIndex() followed by a utext_getNativeIndex(). 103*0e209d39SAndroid Build Coastguard Worker * If the index is returned unchanged, it was on a code point boundary. If 104*0e209d39SAndroid Build Coastguard Worker * an adjusted index is returned, the original index referred to the 105*0e209d39SAndroid Build Coastguard Worker * interior of a character. 106*0e209d39SAndroid Build Coastguard Worker * 107*0e209d39SAndroid Build Coastguard Worker * <em>Conventions for calling UText functions</em> 108*0e209d39SAndroid Build Coastguard Worker * 109*0e209d39SAndroid Build Coastguard Worker * Most UText access functions have as their first parameter a (UText *) pointer, 110*0e209d39SAndroid Build Coastguard Worker * which specifies the UText to be used. Unless otherwise noted, the 111*0e209d39SAndroid Build Coastguard Worker * pointer must refer to a valid, open UText. Attempting to 112*0e209d39SAndroid Build Coastguard Worker * use a closed UText or passing a NULL pointer is a programming error and 113*0e209d39SAndroid Build Coastguard Worker * will produce undefined results or NULL pointer exceptions. 114*0e209d39SAndroid Build Coastguard Worker * 115*0e209d39SAndroid Build Coastguard Worker * The UText_Open family of functions can either open an existing (closed) 116*0e209d39SAndroid Build Coastguard Worker * UText, or heap allocate a new UText. Here is sample code for creating 117*0e209d39SAndroid Build Coastguard Worker * a stack-allocated UText. 118*0e209d39SAndroid Build Coastguard Worker * 119*0e209d39SAndroid Build Coastguard Worker * \code 120*0e209d39SAndroid Build Coastguard Worker * char *s = whatever(); // A utf-8 string 121*0e209d39SAndroid Build Coastguard Worker * U_ErrorCode status = U_ZERO_ERROR; 122*0e209d39SAndroid Build Coastguard Worker * UText ut = UTEXT_INITIALIZER; 123*0e209d39SAndroid Build Coastguard Worker * utext_openUTF8(ut, s, -1, &status); 124*0e209d39SAndroid Build Coastguard Worker * if (U_FAILURE(status)) { 125*0e209d39SAndroid Build Coastguard Worker * // error handling 126*0e209d39SAndroid Build Coastguard Worker * } else { 127*0e209d39SAndroid Build Coastguard Worker * // work with the UText 128*0e209d39SAndroid Build Coastguard Worker * } 129*0e209d39SAndroid Build Coastguard Worker * \endcode 130*0e209d39SAndroid Build Coastguard Worker * 131*0e209d39SAndroid Build Coastguard Worker * Any existing UText passed to an open function _must_ have been initialized, 132*0e209d39SAndroid Build Coastguard Worker * either by the UTEXT_INITIALIZER, or by having been originally heap-allocated 133*0e209d39SAndroid Build Coastguard Worker * by an open function. Passing NULL will cause the open function to 134*0e209d39SAndroid Build Coastguard Worker * heap-allocate and fully initialize a new UText. 135*0e209d39SAndroid Build Coastguard Worker * 136*0e209d39SAndroid Build Coastguard Worker */ 137*0e209d39SAndroid Build Coastguard Worker 138*0e209d39SAndroid Build Coastguard Worker 139*0e209d39SAndroid Build Coastguard Worker 140*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 141*0e209d39SAndroid Build Coastguard Worker #include "unicode/uchar.h" 142*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API 143*0e209d39SAndroid Build Coastguard Worker #include "unicode/localpointer.h" 144*0e209d39SAndroid Build Coastguard Worker #include "unicode/rep.h" 145*0e209d39SAndroid Build Coastguard Worker #include "unicode/unistr.h" 146*0e209d39SAndroid Build Coastguard Worker #include "unicode/chariter.h" 147*0e209d39SAndroid Build Coastguard Worker #endif 148*0e209d39SAndroid Build Coastguard Worker 149*0e209d39SAndroid Build Coastguard Worker 150*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN 151*0e209d39SAndroid Build Coastguard Worker 152*0e209d39SAndroid Build Coastguard Worker struct UText; 153*0e209d39SAndroid Build Coastguard Worker typedef struct UText UText; /**< C typedef for struct UText. @stable ICU 3.6 */ 154*0e209d39SAndroid Build Coastguard Worker 155*0e209d39SAndroid Build Coastguard Worker 156*0e209d39SAndroid Build Coastguard Worker /*************************************************************************************** 157*0e209d39SAndroid Build Coastguard Worker * 158*0e209d39SAndroid Build Coastguard Worker * C Functions for creating UText wrappers around various kinds of text strings. 159*0e209d39SAndroid Build Coastguard Worker * 160*0e209d39SAndroid Build Coastguard Worker ****************************************************************************************/ 161*0e209d39SAndroid Build Coastguard Worker 162*0e209d39SAndroid Build Coastguard Worker 163*0e209d39SAndroid Build Coastguard Worker /** 164*0e209d39SAndroid Build Coastguard Worker * Close function for UText instances. 165*0e209d39SAndroid Build Coastguard Worker * Cleans up, releases any resources being held by an open UText. 166*0e209d39SAndroid Build Coastguard Worker * <p> 167*0e209d39SAndroid Build Coastguard Worker * If the UText was originally allocated by one of the utext_open functions, 168*0e209d39SAndroid Build Coastguard Worker * the storage associated with the utext will also be freed. 169*0e209d39SAndroid Build Coastguard Worker * If the UText storage originated with the application, as it would with 170*0e209d39SAndroid Build Coastguard Worker * a local or static instance, the storage will not be deleted. 171*0e209d39SAndroid Build Coastguard Worker * 172*0e209d39SAndroid Build Coastguard Worker * An open UText can be reset to refer to new string by using one of the utext_open() 173*0e209d39SAndroid Build Coastguard Worker * functions without first closing the UText. 174*0e209d39SAndroid Build Coastguard Worker * 175*0e209d39SAndroid Build Coastguard Worker * @param ut The UText to be closed. 176*0e209d39SAndroid Build Coastguard Worker * @return NULL if the UText struct was deleted by the close. If the UText struct 177*0e209d39SAndroid Build Coastguard Worker * was originally provided by the caller to the open function, it is 178*0e209d39SAndroid Build Coastguard Worker * returned by this function, and may be safely used again in 179*0e209d39SAndroid Build Coastguard Worker * a subsequent utext_open. 180*0e209d39SAndroid Build Coastguard Worker * 181*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 182*0e209d39SAndroid Build Coastguard Worker */ 183*0e209d39SAndroid Build Coastguard Worker U_CAPI UText * U_EXPORT2 184*0e209d39SAndroid Build Coastguard Worker utext_close(UText *ut); 185*0e209d39SAndroid Build Coastguard Worker 186*0e209d39SAndroid Build Coastguard Worker /** 187*0e209d39SAndroid Build Coastguard Worker * Open a read-only UText implementation for UTF-8 strings. 188*0e209d39SAndroid Build Coastguard Worker * 189*0e209d39SAndroid Build Coastguard Worker * \htmlonly 190*0e209d39SAndroid Build Coastguard Worker * Any invalid UTF-8 in the input will be handled in this way: 191*0e209d39SAndroid Build Coastguard Worker * a sequence of bytes that has the form of a truncated, but otherwise valid, 192*0e209d39SAndroid Build Coastguard Worker * UTF-8 sequence will be replaced by a single unicode replacement character, \uFFFD. 193*0e209d39SAndroid Build Coastguard Worker * Any other illegal bytes will each be replaced by a \uFFFD. 194*0e209d39SAndroid Build Coastguard Worker * \endhtmlonly 195*0e209d39SAndroid Build Coastguard Worker * 196*0e209d39SAndroid Build Coastguard Worker * @param ut Pointer to a UText struct. If NULL, a new UText will be created. 197*0e209d39SAndroid Build Coastguard Worker * If non-NULL, must refer to an initialized UText struct, which will then 198*0e209d39SAndroid Build Coastguard Worker * be reset to reference the specified UTF-8 string. 199*0e209d39SAndroid Build Coastguard Worker * @param s A UTF-8 string. Must not be NULL. 200*0e209d39SAndroid Build Coastguard Worker * @param length The length of the UTF-8 string in bytes, or -1 if the string is 201*0e209d39SAndroid Build Coastguard Worker * zero terminated. 202*0e209d39SAndroid Build Coastguard Worker * @param status Errors are returned here. 203*0e209d39SAndroid Build Coastguard Worker * @return A pointer to the UText. If a pre-allocated UText was provided, it 204*0e209d39SAndroid Build Coastguard Worker * will always be used and returned. 205*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 206*0e209d39SAndroid Build Coastguard Worker */ 207*0e209d39SAndroid Build Coastguard Worker U_CAPI UText * U_EXPORT2 208*0e209d39SAndroid Build Coastguard Worker utext_openUTF8(UText *ut, const char *s, int64_t length, UErrorCode *status); 209*0e209d39SAndroid Build Coastguard Worker 210*0e209d39SAndroid Build Coastguard Worker 211*0e209d39SAndroid Build Coastguard Worker /** 212*0e209d39SAndroid Build Coastguard Worker * Open a read-only UText for UChar * string. 213*0e209d39SAndroid Build Coastguard Worker * 214*0e209d39SAndroid Build Coastguard Worker * @param ut Pointer to a UText struct. If NULL, a new UText will be created. 215*0e209d39SAndroid Build Coastguard Worker * If non-NULL, must refer to an initialized UText struct, which will then 216*0e209d39SAndroid Build Coastguard Worker * be reset to reference the specified UChar string. 217*0e209d39SAndroid Build Coastguard Worker * @param s A UChar (UTF-16) string 218*0e209d39SAndroid Build Coastguard Worker * @param length The number of UChars in the input string, or -1 if the string is 219*0e209d39SAndroid Build Coastguard Worker * zero terminated. 220*0e209d39SAndroid Build Coastguard Worker * @param status Errors are returned here. 221*0e209d39SAndroid Build Coastguard Worker * @return A pointer to the UText. If a pre-allocated UText was provided, it 222*0e209d39SAndroid Build Coastguard Worker * will always be used and returned. 223*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 224*0e209d39SAndroid Build Coastguard Worker */ 225*0e209d39SAndroid Build Coastguard Worker U_CAPI UText * U_EXPORT2 226*0e209d39SAndroid Build Coastguard Worker utext_openUChars(UText *ut, const UChar *s, int64_t length, UErrorCode *status); 227*0e209d39SAndroid Build Coastguard Worker 228*0e209d39SAndroid Build Coastguard Worker 229*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API 230*0e209d39SAndroid Build Coastguard Worker /** 231*0e209d39SAndroid Build Coastguard Worker * Open a writable UText for a non-const UnicodeString. 232*0e209d39SAndroid Build Coastguard Worker * 233*0e209d39SAndroid Build Coastguard Worker * @param ut Pointer to a UText struct. If nullptr, a new UText will be created. 234*0e209d39SAndroid Build Coastguard Worker * If non-nullptr, must refer to an initialized UText struct, which will then 235*0e209d39SAndroid Build Coastguard Worker * be reset to reference the specified input string. 236*0e209d39SAndroid Build Coastguard Worker * @param s A UnicodeString. 237*0e209d39SAndroid Build Coastguard Worker * @param status Errors are returned here. 238*0e209d39SAndroid Build Coastguard Worker * @return Pointer to the UText. If a UText was supplied as input, this 239*0e209d39SAndroid Build Coastguard Worker * will always be used and returned. 240*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 241*0e209d39SAndroid Build Coastguard Worker */ 242*0e209d39SAndroid Build Coastguard Worker U_CAPI UText * U_EXPORT2 243*0e209d39SAndroid Build Coastguard Worker utext_openUnicodeString(UText *ut, icu::UnicodeString *s, UErrorCode *status); 244*0e209d39SAndroid Build Coastguard Worker 245*0e209d39SAndroid Build Coastguard Worker 246*0e209d39SAndroid Build Coastguard Worker /** 247*0e209d39SAndroid Build Coastguard Worker * Open a UText for a const UnicodeString. The resulting UText will not be writable. 248*0e209d39SAndroid Build Coastguard Worker * 249*0e209d39SAndroid Build Coastguard Worker * @param ut Pointer to a UText struct. If nullptr, a new UText will be created. 250*0e209d39SAndroid Build Coastguard Worker * If non-nullptr, must refer to an initialized UText struct, which will then 251*0e209d39SAndroid Build Coastguard Worker * be reset to reference the specified input string. 252*0e209d39SAndroid Build Coastguard Worker * @param s A const UnicodeString to be wrapped. 253*0e209d39SAndroid Build Coastguard Worker * @param status Errors are returned here. 254*0e209d39SAndroid Build Coastguard Worker * @return Pointer to the UText. If a UText was supplied as input, this 255*0e209d39SAndroid Build Coastguard Worker * will always be used and returned. 256*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 257*0e209d39SAndroid Build Coastguard Worker */ 258*0e209d39SAndroid Build Coastguard Worker U_CAPI UText * U_EXPORT2 259*0e209d39SAndroid Build Coastguard Worker utext_openConstUnicodeString(UText *ut, const icu::UnicodeString *s, UErrorCode *status); 260*0e209d39SAndroid Build Coastguard Worker 261*0e209d39SAndroid Build Coastguard Worker 262*0e209d39SAndroid Build Coastguard Worker /** 263*0e209d39SAndroid Build Coastguard Worker * Open a writable UText implementation for an ICU Replaceable object. 264*0e209d39SAndroid Build Coastguard Worker * @param ut Pointer to a UText struct. If nullptr, a new UText will be created. 265*0e209d39SAndroid Build Coastguard Worker * If non-nullptr, must refer to an already existing UText, which will then 266*0e209d39SAndroid Build Coastguard Worker * be reset to reference the specified replaceable text. 267*0e209d39SAndroid Build Coastguard Worker * @param rep A Replaceable text object. 268*0e209d39SAndroid Build Coastguard Worker * @param status Errors are returned here. 269*0e209d39SAndroid Build Coastguard Worker * @return Pointer to the UText. If a UText was supplied as input, this 270*0e209d39SAndroid Build Coastguard Worker * will always be used and returned. 271*0e209d39SAndroid Build Coastguard Worker * @see Replaceable 272*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 273*0e209d39SAndroid Build Coastguard Worker */ 274*0e209d39SAndroid Build Coastguard Worker U_CAPI UText * U_EXPORT2 275*0e209d39SAndroid Build Coastguard Worker utext_openReplaceable(UText *ut, icu::Replaceable *rep, UErrorCode *status); 276*0e209d39SAndroid Build Coastguard Worker 277*0e209d39SAndroid Build Coastguard Worker /** 278*0e209d39SAndroid Build Coastguard Worker * Open a UText implementation over an ICU CharacterIterator. 279*0e209d39SAndroid Build Coastguard Worker * @param ut Pointer to a UText struct. If nullptr, a new UText will be created. 280*0e209d39SAndroid Build Coastguard Worker * If non-nullptr, must refer to an already existing UText, which will then 281*0e209d39SAndroid Build Coastguard Worker * be reset to reference the specified replaceable text. 282*0e209d39SAndroid Build Coastguard Worker * @param ci A Character Iterator. 283*0e209d39SAndroid Build Coastguard Worker * @param status Errors are returned here. 284*0e209d39SAndroid Build Coastguard Worker * @return Pointer to the UText. If a UText was supplied as input, this 285*0e209d39SAndroid Build Coastguard Worker * will always be used and returned. 286*0e209d39SAndroid Build Coastguard Worker * @see Replaceable 287*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 288*0e209d39SAndroid Build Coastguard Worker */ 289*0e209d39SAndroid Build Coastguard Worker U_CAPI UText * U_EXPORT2 290*0e209d39SAndroid Build Coastguard Worker utext_openCharacterIterator(UText *ut, icu::CharacterIterator *ci, UErrorCode *status); 291*0e209d39SAndroid Build Coastguard Worker 292*0e209d39SAndroid Build Coastguard Worker #endif 293*0e209d39SAndroid Build Coastguard Worker 294*0e209d39SAndroid Build Coastguard Worker 295*0e209d39SAndroid Build Coastguard Worker /** 296*0e209d39SAndroid Build Coastguard Worker * Clone a UText. This is much like opening a UText where the source text is itself 297*0e209d39SAndroid Build Coastguard Worker * another UText. 298*0e209d39SAndroid Build Coastguard Worker * 299*0e209d39SAndroid Build Coastguard Worker * A deep clone will copy both the UText data structures and the underlying text. 300*0e209d39SAndroid Build Coastguard Worker * The original and cloned UText will operate completely independently; modifications 301*0e209d39SAndroid Build Coastguard Worker * made to the text in one will not affect the other. Text providers are not 302*0e209d39SAndroid Build Coastguard Worker * required to support deep clones. The user of clone() must check the status return 303*0e209d39SAndroid Build Coastguard Worker * and be prepared to handle failures. 304*0e209d39SAndroid Build Coastguard Worker * 305*0e209d39SAndroid Build Coastguard Worker * The standard UText implementations for UTF8, UChar *, UnicodeString and 306*0e209d39SAndroid Build Coastguard Worker * Replaceable all support deep cloning. 307*0e209d39SAndroid Build Coastguard Worker * 308*0e209d39SAndroid Build Coastguard Worker * The UText returned from a deep clone will be writable, assuming that the text 309*0e209d39SAndroid Build Coastguard Worker * provider is able to support writing, even if the source UText had been made 310*0e209d39SAndroid Build Coastguard Worker * non-writable by means of UText_freeze(). 311*0e209d39SAndroid Build Coastguard Worker * 312*0e209d39SAndroid Build Coastguard Worker * A shallow clone replicates only the UText data structures; it does not make 313*0e209d39SAndroid Build Coastguard Worker * a copy of the underlying text. Shallow clones can be used as an efficient way to 314*0e209d39SAndroid Build Coastguard Worker * have multiple iterators active in a single text string that is not being 315*0e209d39SAndroid Build Coastguard Worker * modified. 316*0e209d39SAndroid Build Coastguard Worker * 317*0e209d39SAndroid Build Coastguard Worker * A shallow clone operation will not fail, barring truly exceptional conditions such 318*0e209d39SAndroid Build Coastguard Worker * as memory allocation failures. 319*0e209d39SAndroid Build Coastguard Worker * 320*0e209d39SAndroid Build Coastguard Worker * Shallow UText clones should be avoided if the UText functions that modify the 321*0e209d39SAndroid Build Coastguard Worker * text are expected to be used, either on the original or the cloned UText. 322*0e209d39SAndroid Build Coastguard Worker * Any such modifications can cause unpredictable behavior. Read Only 323*0e209d39SAndroid Build Coastguard Worker * shallow clones provide some protection against errors of this type by 324*0e209d39SAndroid Build Coastguard Worker * disabling text modification via the cloned UText. 325*0e209d39SAndroid Build Coastguard Worker * 326*0e209d39SAndroid Build Coastguard Worker * A shallow clone made with the readOnly parameter == false will preserve the 327*0e209d39SAndroid Build Coastguard Worker * utext_isWritable() state of the source object. Note, however, that 328*0e209d39SAndroid Build Coastguard Worker * write operations must be avoided while more than one UText exists that refer 329*0e209d39SAndroid Build Coastguard Worker * to the same underlying text. 330*0e209d39SAndroid Build Coastguard Worker * 331*0e209d39SAndroid Build Coastguard Worker * A UText and its clone may be safely concurrently accessed by separate threads. 332*0e209d39SAndroid Build Coastguard Worker * This is true for read access only with shallow clones, and for both read and 333*0e209d39SAndroid Build Coastguard Worker * write access with deep clones. 334*0e209d39SAndroid Build Coastguard Worker * It is the responsibility of the Text Provider to ensure that this thread safety 335*0e209d39SAndroid Build Coastguard Worker * constraint is met. 336*0e209d39SAndroid Build Coastguard Worker * 337*0e209d39SAndroid Build Coastguard Worker * @param dest A UText struct to be filled in with the result of the clone operation, 338*0e209d39SAndroid Build Coastguard Worker * or NULL if the clone function should heap-allocate a new UText struct. 339*0e209d39SAndroid Build Coastguard Worker * If non-NULL, must refer to an already existing UText, which will then 340*0e209d39SAndroid Build Coastguard Worker * be reset to become the clone. 341*0e209d39SAndroid Build Coastguard Worker * @param src The UText to be cloned. 342*0e209d39SAndroid Build Coastguard Worker * @param deep true to request a deep clone, false for a shallow clone. 343*0e209d39SAndroid Build Coastguard Worker * @param readOnly true to request that the cloned UText have read only access to the 344*0e209d39SAndroid Build Coastguard Worker * underlying text. 345*0e209d39SAndroid Build Coastguard Worker 346*0e209d39SAndroid Build Coastguard Worker * @param status Errors are returned here. For deep clones, U_UNSUPPORTED_ERROR 347*0e209d39SAndroid Build Coastguard Worker * will be returned if the text provider is unable to clone the 348*0e209d39SAndroid Build Coastguard Worker * original text. 349*0e209d39SAndroid Build Coastguard Worker * @return The newly created clone, or NULL if the clone operation failed. 350*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 351*0e209d39SAndroid Build Coastguard Worker */ 352*0e209d39SAndroid Build Coastguard Worker U_CAPI UText * U_EXPORT2 353*0e209d39SAndroid Build Coastguard Worker utext_clone(UText *dest, const UText *src, UBool deep, UBool readOnly, UErrorCode *status); 354*0e209d39SAndroid Build Coastguard Worker 355*0e209d39SAndroid Build Coastguard Worker 356*0e209d39SAndroid Build Coastguard Worker /** 357*0e209d39SAndroid Build Coastguard Worker * Compare two UText objects for equality. 358*0e209d39SAndroid Build Coastguard Worker * UTexts are equal if they are iterating over the same text, and 359*0e209d39SAndroid Build Coastguard Worker * have the same iteration position within the text. 360*0e209d39SAndroid Build Coastguard Worker * If either or both of the parameters are NULL, the comparison is false. 361*0e209d39SAndroid Build Coastguard Worker * 362*0e209d39SAndroid Build Coastguard Worker * @param a The first of the two UTexts to compare. 363*0e209d39SAndroid Build Coastguard Worker * @param b The other UText to be compared. 364*0e209d39SAndroid Build Coastguard Worker * @return true if the two UTexts are equal. 365*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 366*0e209d39SAndroid Build Coastguard Worker */ 367*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2 368*0e209d39SAndroid Build Coastguard Worker utext_equals(const UText *a, const UText *b); 369*0e209d39SAndroid Build Coastguard Worker 370*0e209d39SAndroid Build Coastguard Worker 371*0e209d39SAndroid Build Coastguard Worker /***************************************************************************** 372*0e209d39SAndroid Build Coastguard Worker * 373*0e209d39SAndroid Build Coastguard Worker * Functions to work with the text represented by a UText wrapper 374*0e209d39SAndroid Build Coastguard Worker * 375*0e209d39SAndroid Build Coastguard Worker *****************************************************************************/ 376*0e209d39SAndroid Build Coastguard Worker 377*0e209d39SAndroid Build Coastguard Worker /** 378*0e209d39SAndroid Build Coastguard Worker * Get the length of the text. Depending on the characteristics 379*0e209d39SAndroid Build Coastguard Worker * of the underlying text representation, this may be expensive. 380*0e209d39SAndroid Build Coastguard Worker * @see utext_isLengthExpensive() 381*0e209d39SAndroid Build Coastguard Worker * 382*0e209d39SAndroid Build Coastguard Worker * 383*0e209d39SAndroid Build Coastguard Worker * @param ut the text to be accessed. 384*0e209d39SAndroid Build Coastguard Worker * @return the length of the text, expressed in native units. 385*0e209d39SAndroid Build Coastguard Worker * 386*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 387*0e209d39SAndroid Build Coastguard Worker */ 388*0e209d39SAndroid Build Coastguard Worker U_CAPI int64_t U_EXPORT2 389*0e209d39SAndroid Build Coastguard Worker utext_nativeLength(UText *ut); 390*0e209d39SAndroid Build Coastguard Worker 391*0e209d39SAndroid Build Coastguard Worker /** 392*0e209d39SAndroid Build Coastguard Worker * Return true if calculating the length of the text could be expensive. 393*0e209d39SAndroid Build Coastguard Worker * Finding the length of NUL terminated strings is considered to be expensive. 394*0e209d39SAndroid Build Coastguard Worker * 395*0e209d39SAndroid Build Coastguard Worker * Note that the value of this function may change 396*0e209d39SAndroid Build Coastguard Worker * as the result of other operations on a UText. 397*0e209d39SAndroid Build Coastguard Worker * Once the length of a string has been discovered, it will no longer 398*0e209d39SAndroid Build Coastguard Worker * be expensive to report it. 399*0e209d39SAndroid Build Coastguard Worker * 400*0e209d39SAndroid Build Coastguard Worker * @param ut the text to be accessed. 401*0e209d39SAndroid Build Coastguard Worker * @return true if determining the length of the text could be time consuming. 402*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 403*0e209d39SAndroid Build Coastguard Worker */ 404*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2 405*0e209d39SAndroid Build Coastguard Worker utext_isLengthExpensive(const UText *ut); 406*0e209d39SAndroid Build Coastguard Worker 407*0e209d39SAndroid Build Coastguard Worker /** 408*0e209d39SAndroid Build Coastguard Worker * Returns the code point at the requested index, 409*0e209d39SAndroid Build Coastguard Worker * or U_SENTINEL (-1) if it is out of bounds. 410*0e209d39SAndroid Build Coastguard Worker * 411*0e209d39SAndroid Build Coastguard Worker * If the specified index points to the interior of a multi-unit 412*0e209d39SAndroid Build Coastguard Worker * character - one of the trail bytes of a UTF-8 sequence, for example - 413*0e209d39SAndroid Build Coastguard Worker * the complete code point will be returned. 414*0e209d39SAndroid Build Coastguard Worker * 415*0e209d39SAndroid Build Coastguard Worker * The iteration position will be set to the start of the returned code point. 416*0e209d39SAndroid Build Coastguard Worker * 417*0e209d39SAndroid Build Coastguard Worker * This function is roughly equivalent to the sequence 418*0e209d39SAndroid Build Coastguard Worker * utext_setNativeIndex(index); 419*0e209d39SAndroid Build Coastguard Worker * utext_current32(); 420*0e209d39SAndroid Build Coastguard Worker * (There is a subtle difference if the index is out of bounds by being less than zero - 421*0e209d39SAndroid Build Coastguard Worker * utext_setNativeIndex(negative value) sets the index to zero, after which utext_current() 422*0e209d39SAndroid Build Coastguard Worker * will return the char at zero. utext_char32At(negative index), on the other hand, will 423*0e209d39SAndroid Build Coastguard Worker * return the U_SENTINEL value of -1.) 424*0e209d39SAndroid Build Coastguard Worker * 425*0e209d39SAndroid Build Coastguard Worker * @param ut the text to be accessed 426*0e209d39SAndroid Build Coastguard Worker * @param nativeIndex the native index of the character to be accessed. If the index points 427*0e209d39SAndroid Build Coastguard Worker * to other than the first unit of a multi-unit character, it will be adjusted 428*0e209d39SAndroid Build Coastguard Worker * to the start of the character. 429*0e209d39SAndroid Build Coastguard Worker * @return the code point at the specified index. 430*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 431*0e209d39SAndroid Build Coastguard Worker */ 432*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2 433*0e209d39SAndroid Build Coastguard Worker utext_char32At(UText *ut, int64_t nativeIndex); 434*0e209d39SAndroid Build Coastguard Worker 435*0e209d39SAndroid Build Coastguard Worker 436*0e209d39SAndroid Build Coastguard Worker /** 437*0e209d39SAndroid Build Coastguard Worker * 438*0e209d39SAndroid Build Coastguard Worker * Get the code point at the current iteration position, 439*0e209d39SAndroid Build Coastguard Worker * or U_SENTINEL (-1) if the iteration has reached the end of 440*0e209d39SAndroid Build Coastguard Worker * the input text. 441*0e209d39SAndroid Build Coastguard Worker * 442*0e209d39SAndroid Build Coastguard Worker * @param ut the text to be accessed. 443*0e209d39SAndroid Build Coastguard Worker * @return the Unicode code point at the current iterator position. 444*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 445*0e209d39SAndroid Build Coastguard Worker */ 446*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2 447*0e209d39SAndroid Build Coastguard Worker utext_current32(UText *ut); 448*0e209d39SAndroid Build Coastguard Worker 449*0e209d39SAndroid Build Coastguard Worker 450*0e209d39SAndroid Build Coastguard Worker /** 451*0e209d39SAndroid Build Coastguard Worker * Get the code point at the current iteration position of the UText, and 452*0e209d39SAndroid Build Coastguard Worker * advance the position to the first index following the character. 453*0e209d39SAndroid Build Coastguard Worker * 454*0e209d39SAndroid Build Coastguard Worker * If the position is at the end of the text (the index following 455*0e209d39SAndroid Build Coastguard Worker * the last character, which is also the length of the text), 456*0e209d39SAndroid Build Coastguard Worker * return U_SENTINEL (-1) and do not advance the index. 457*0e209d39SAndroid Build Coastguard Worker * 458*0e209d39SAndroid Build Coastguard Worker * This is a post-increment operation. 459*0e209d39SAndroid Build Coastguard Worker * 460*0e209d39SAndroid Build Coastguard Worker * An inline macro version of this function, UTEXT_NEXT32(), 461*0e209d39SAndroid Build Coastguard Worker * is available for performance critical use. 462*0e209d39SAndroid Build Coastguard Worker * 463*0e209d39SAndroid Build Coastguard Worker * @param ut the text to be accessed. 464*0e209d39SAndroid Build Coastguard Worker * @return the Unicode code point at the iteration position. 465*0e209d39SAndroid Build Coastguard Worker * @see UTEXT_NEXT32 466*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 467*0e209d39SAndroid Build Coastguard Worker */ 468*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2 469*0e209d39SAndroid Build Coastguard Worker utext_next32(UText *ut); 470*0e209d39SAndroid Build Coastguard Worker 471*0e209d39SAndroid Build Coastguard Worker 472*0e209d39SAndroid Build Coastguard Worker /** 473*0e209d39SAndroid Build Coastguard Worker * Move the iterator position to the character (code point) whose 474*0e209d39SAndroid Build Coastguard Worker * index precedes the current position, and return that character. 475*0e209d39SAndroid Build Coastguard Worker * This is a pre-decrement operation. 476*0e209d39SAndroid Build Coastguard Worker * 477*0e209d39SAndroid Build Coastguard Worker * If the initial position is at the start of the text (index of 0) 478*0e209d39SAndroid Build Coastguard Worker * return U_SENTINEL (-1), and leave the position unchanged. 479*0e209d39SAndroid Build Coastguard Worker * 480*0e209d39SAndroid Build Coastguard Worker * An inline macro version of this function, UTEXT_PREVIOUS32(), 481*0e209d39SAndroid Build Coastguard Worker * is available for performance critical use. 482*0e209d39SAndroid Build Coastguard Worker * 483*0e209d39SAndroid Build Coastguard Worker * @param ut the text to be accessed. 484*0e209d39SAndroid Build Coastguard Worker * @return the previous UChar32 code point, or U_SENTINEL (-1) 485*0e209d39SAndroid Build Coastguard Worker * if the iteration has reached the start of the text. 486*0e209d39SAndroid Build Coastguard Worker * @see UTEXT_PREVIOUS32 487*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 488*0e209d39SAndroid Build Coastguard Worker */ 489*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2 490*0e209d39SAndroid Build Coastguard Worker utext_previous32(UText *ut); 491*0e209d39SAndroid Build Coastguard Worker 492*0e209d39SAndroid Build Coastguard Worker 493*0e209d39SAndroid Build Coastguard Worker /** 494*0e209d39SAndroid Build Coastguard Worker * Set the iteration index and return the code point at that index. 495*0e209d39SAndroid Build Coastguard Worker * Leave the iteration index at the start of the following code point. 496*0e209d39SAndroid Build Coastguard Worker * 497*0e209d39SAndroid Build Coastguard Worker * This function is the most efficient and convenient way to 498*0e209d39SAndroid Build Coastguard Worker * begin a forward iteration. The results are identical to the those 499*0e209d39SAndroid Build Coastguard Worker * from the sequence 500*0e209d39SAndroid Build Coastguard Worker * \code 501*0e209d39SAndroid Build Coastguard Worker * utext_setIndex(); 502*0e209d39SAndroid Build Coastguard Worker * utext_next32(); 503*0e209d39SAndroid Build Coastguard Worker * \endcode 504*0e209d39SAndroid Build Coastguard Worker * 505*0e209d39SAndroid Build Coastguard Worker * @param ut the text to be accessed. 506*0e209d39SAndroid Build Coastguard Worker * @param nativeIndex Iteration index, in the native units of the text provider. 507*0e209d39SAndroid Build Coastguard Worker * @return Code point which starts at or before index, 508*0e209d39SAndroid Build Coastguard Worker * or U_SENTINEL (-1) if it is out of bounds. 509*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 510*0e209d39SAndroid Build Coastguard Worker */ 511*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2 512*0e209d39SAndroid Build Coastguard Worker utext_next32From(UText *ut, int64_t nativeIndex); 513*0e209d39SAndroid Build Coastguard Worker 514*0e209d39SAndroid Build Coastguard Worker 515*0e209d39SAndroid Build Coastguard Worker 516*0e209d39SAndroid Build Coastguard Worker /** 517*0e209d39SAndroid Build Coastguard Worker * Set the iteration index, and return the code point preceding the 518*0e209d39SAndroid Build Coastguard Worker * one specified by the initial index. Leave the iteration position 519*0e209d39SAndroid Build Coastguard Worker * at the start of the returned code point. 520*0e209d39SAndroid Build Coastguard Worker * 521*0e209d39SAndroid Build Coastguard Worker * This function is the most efficient and convenient way to 522*0e209d39SAndroid Build Coastguard Worker * begin a backwards iteration. 523*0e209d39SAndroid Build Coastguard Worker * 524*0e209d39SAndroid Build Coastguard Worker * @param ut the text to be accessed. 525*0e209d39SAndroid Build Coastguard Worker * @param nativeIndex Iteration index in the native units of the text provider. 526*0e209d39SAndroid Build Coastguard Worker * @return Code point preceding the one at the initial index, 527*0e209d39SAndroid Build Coastguard Worker * or U_SENTINEL (-1) if it is out of bounds. 528*0e209d39SAndroid Build Coastguard Worker * 529*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 530*0e209d39SAndroid Build Coastguard Worker */ 531*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2 532*0e209d39SAndroid Build Coastguard Worker utext_previous32From(UText *ut, int64_t nativeIndex); 533*0e209d39SAndroid Build Coastguard Worker 534*0e209d39SAndroid Build Coastguard Worker /** 535*0e209d39SAndroid Build Coastguard Worker * Get the current iterator position, which can range from 0 to 536*0e209d39SAndroid Build Coastguard Worker * the length of the text. 537*0e209d39SAndroid Build Coastguard Worker * The position is a native index into the input text, in whatever format it 538*0e209d39SAndroid Build Coastguard Worker * may have (possibly UTF-8 for example), and may not always be the same as 539*0e209d39SAndroid Build Coastguard Worker * the corresponding UChar (UTF-16) index. 540*0e209d39SAndroid Build Coastguard Worker * The returned position will always be aligned to a code point boundary. 541*0e209d39SAndroid Build Coastguard Worker * 542*0e209d39SAndroid Build Coastguard Worker * @param ut the text to be accessed. 543*0e209d39SAndroid Build Coastguard Worker * @return the current index position, in the native units of the text provider. 544*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 545*0e209d39SAndroid Build Coastguard Worker */ 546*0e209d39SAndroid Build Coastguard Worker U_CAPI int64_t U_EXPORT2 547*0e209d39SAndroid Build Coastguard Worker utext_getNativeIndex(const UText *ut); 548*0e209d39SAndroid Build Coastguard Worker 549*0e209d39SAndroid Build Coastguard Worker /** 550*0e209d39SAndroid Build Coastguard Worker * Set the current iteration position to the nearest code point 551*0e209d39SAndroid Build Coastguard Worker * boundary at or preceding the specified index. 552*0e209d39SAndroid Build Coastguard Worker * The index is in the native units of the original input text. 553*0e209d39SAndroid Build Coastguard Worker * If the index is out of range, it will be pinned to be within 554*0e209d39SAndroid Build Coastguard Worker * the range of the input text. 555*0e209d39SAndroid Build Coastguard Worker * <p> 556*0e209d39SAndroid Build Coastguard Worker * It will usually be more efficient to begin an iteration 557*0e209d39SAndroid Build Coastguard Worker * using the functions utext_next32From() or utext_previous32From() 558*0e209d39SAndroid Build Coastguard Worker * rather than setIndex(). 559*0e209d39SAndroid Build Coastguard Worker * <p> 560*0e209d39SAndroid Build Coastguard Worker * Moving the index position to an adjacent character is best done 561*0e209d39SAndroid Build Coastguard Worker * with utext_next32(), utext_previous32() or utext_moveIndex32(). 562*0e209d39SAndroid Build Coastguard Worker * Attempting to do direct arithmetic on the index position is 563*0e209d39SAndroid Build Coastguard Worker * complicated by the fact that the size (in native units) of a 564*0e209d39SAndroid Build Coastguard Worker * character depends on the underlying representation of the character 565*0e209d39SAndroid Build Coastguard Worker * (UTF-8, UTF-16, UTF-32, arbitrary codepage), and is not 566*0e209d39SAndroid Build Coastguard Worker * easily knowable. 567*0e209d39SAndroid Build Coastguard Worker * 568*0e209d39SAndroid Build Coastguard Worker * @param ut the text to be accessed. 569*0e209d39SAndroid Build Coastguard Worker * @param nativeIndex the native unit index of the new iteration position. 570*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 571*0e209d39SAndroid Build Coastguard Worker */ 572*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 573*0e209d39SAndroid Build Coastguard Worker utext_setNativeIndex(UText *ut, int64_t nativeIndex); 574*0e209d39SAndroid Build Coastguard Worker 575*0e209d39SAndroid Build Coastguard Worker /** 576*0e209d39SAndroid Build Coastguard Worker * Move the iterator position by delta code points. The number of code points 577*0e209d39SAndroid Build Coastguard Worker * is a signed number; a negative delta will move the iterator backwards, 578*0e209d39SAndroid Build Coastguard Worker * towards the start of the text. 579*0e209d39SAndroid Build Coastguard Worker * <p> 580*0e209d39SAndroid Build Coastguard Worker * The index is moved by <code>delta</code> code points 581*0e209d39SAndroid Build Coastguard Worker * forward or backward, but no further backward than to 0 and 582*0e209d39SAndroid Build Coastguard Worker * no further forward than to utext_nativeLength(). 583*0e209d39SAndroid Build Coastguard Worker * The resulting index value will be in between 0 and length, inclusive. 584*0e209d39SAndroid Build Coastguard Worker * 585*0e209d39SAndroid Build Coastguard Worker * @param ut the text to be accessed. 586*0e209d39SAndroid Build Coastguard Worker * @param delta the signed number of code points to move the iteration position. 587*0e209d39SAndroid Build Coastguard Worker * @return true if the position could be moved the requested number of positions while 588*0e209d39SAndroid Build Coastguard Worker * staying within the range [0 - text length]. 589*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 590*0e209d39SAndroid Build Coastguard Worker */ 591*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2 592*0e209d39SAndroid Build Coastguard Worker utext_moveIndex32(UText *ut, int32_t delta); 593*0e209d39SAndroid Build Coastguard Worker 594*0e209d39SAndroid Build Coastguard Worker /** 595*0e209d39SAndroid Build Coastguard Worker * Get the native index of the character preceding the current position. 596*0e209d39SAndroid Build Coastguard Worker * If the iteration position is already at the start of the text, zero 597*0e209d39SAndroid Build Coastguard Worker * is returned. 598*0e209d39SAndroid Build Coastguard Worker * The value returned is the same as that obtained from the following sequence, 599*0e209d39SAndroid Build Coastguard Worker * but without the side effect of changing the iteration position. 600*0e209d39SAndroid Build Coastguard Worker * 601*0e209d39SAndroid Build Coastguard Worker * \code 602*0e209d39SAndroid Build Coastguard Worker * UText *ut = whatever; 603*0e209d39SAndroid Build Coastguard Worker * ... 604*0e209d39SAndroid Build Coastguard Worker * utext_previous(ut) 605*0e209d39SAndroid Build Coastguard Worker * utext_getNativeIndex(ut); 606*0e209d39SAndroid Build Coastguard Worker * \endcode 607*0e209d39SAndroid Build Coastguard Worker * 608*0e209d39SAndroid Build Coastguard Worker * This function is most useful during forwards iteration, where it will get the 609*0e209d39SAndroid Build Coastguard Worker * native index of the character most recently returned from utext_next(). 610*0e209d39SAndroid Build Coastguard Worker * 611*0e209d39SAndroid Build Coastguard Worker * @param ut the text to be accessed 612*0e209d39SAndroid Build Coastguard Worker * @return the native index of the character preceding the current index position, 613*0e209d39SAndroid Build Coastguard Worker * or zero if the current position is at the start of the text. 614*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 615*0e209d39SAndroid Build Coastguard Worker */ 616*0e209d39SAndroid Build Coastguard Worker U_CAPI int64_t U_EXPORT2 617*0e209d39SAndroid Build Coastguard Worker utext_getPreviousNativeIndex(UText *ut); 618*0e209d39SAndroid Build Coastguard Worker 619*0e209d39SAndroid Build Coastguard Worker 620*0e209d39SAndroid Build Coastguard Worker /** 621*0e209d39SAndroid Build Coastguard Worker * 622*0e209d39SAndroid Build Coastguard Worker * Extract text from a UText into a UChar buffer. The range of text to be extracted 623*0e209d39SAndroid Build Coastguard Worker * is specified in the native indices of the UText provider. These may not necessarily 624*0e209d39SAndroid Build Coastguard Worker * be UTF-16 indices. 625*0e209d39SAndroid Build Coastguard Worker * <p> 626*0e209d39SAndroid Build Coastguard Worker * The size (number of 16 bit UChars) of the data to be extracted is returned. The 627*0e209d39SAndroid Build Coastguard Worker * full number of UChars is returned, even when the extracted text is truncated 628*0e209d39SAndroid Build Coastguard Worker * because the specified buffer size is too small. 629*0e209d39SAndroid Build Coastguard Worker * <p> 630*0e209d39SAndroid Build Coastguard Worker * The extracted string will (if you are a user) / must (if you are a text provider) 631*0e209d39SAndroid Build Coastguard Worker * be NUL-terminated if there is sufficient space in the destination buffer. This 632*0e209d39SAndroid Build Coastguard Worker * terminating NUL is not included in the returned length. 633*0e209d39SAndroid Build Coastguard Worker * <p> 634*0e209d39SAndroid Build Coastguard Worker * The iteration index is left at the position following the last extracted character. 635*0e209d39SAndroid Build Coastguard Worker * 636*0e209d39SAndroid Build Coastguard Worker * @param ut the UText from which to extract data. 637*0e209d39SAndroid Build Coastguard Worker * @param nativeStart the native index of the first character to extract.\ 638*0e209d39SAndroid Build Coastguard Worker * If the specified index is out of range, 639*0e209d39SAndroid Build Coastguard Worker * it will be pinned to be within 0 <= index <= textLength 640*0e209d39SAndroid Build Coastguard Worker * @param nativeLimit the native string index of the position following the last 641*0e209d39SAndroid Build Coastguard Worker * character to extract. If the specified index is out of range, 642*0e209d39SAndroid Build Coastguard Worker * it will be pinned to be within 0 <= index <= textLength. 643*0e209d39SAndroid Build Coastguard Worker * nativeLimit must be >= nativeStart. 644*0e209d39SAndroid Build Coastguard Worker * @param dest the UChar (UTF-16) buffer into which the extracted text is placed 645*0e209d39SAndroid Build Coastguard Worker * @param destCapacity The size, in UChars, of the destination buffer. May be zero 646*0e209d39SAndroid Build Coastguard Worker * for precomputing the required size. 647*0e209d39SAndroid Build Coastguard Worker * @param status receives any error status. 648*0e209d39SAndroid Build Coastguard Worker * U_BUFFER_OVERFLOW_ERROR: the extracted text was truncated because the 649*0e209d39SAndroid Build Coastguard Worker * buffer was too small. Returns number of UChars for preflighting. 650*0e209d39SAndroid Build Coastguard Worker * @return Number of UChars in the data to be extracted. Does not include a trailing NUL. 651*0e209d39SAndroid Build Coastguard Worker * 652*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 653*0e209d39SAndroid Build Coastguard Worker */ 654*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2 655*0e209d39SAndroid Build Coastguard Worker utext_extract(UText *ut, 656*0e209d39SAndroid Build Coastguard Worker int64_t nativeStart, int64_t nativeLimit, 657*0e209d39SAndroid Build Coastguard Worker UChar *dest, int32_t destCapacity, 658*0e209d39SAndroid Build Coastguard Worker UErrorCode *status); 659*0e209d39SAndroid Build Coastguard Worker 660*0e209d39SAndroid Build Coastguard Worker 661*0e209d39SAndroid Build Coastguard Worker 662*0e209d39SAndroid Build Coastguard Worker /************************************************************************************ 663*0e209d39SAndroid Build Coastguard Worker * 664*0e209d39SAndroid Build Coastguard Worker * #define inline versions of selected performance-critical text access functions 665*0e209d39SAndroid Build Coastguard Worker * Caution: do not use auto increment++ or decrement-- expressions 666*0e209d39SAndroid Build Coastguard Worker * as parameters to these macros. 667*0e209d39SAndroid Build Coastguard Worker * 668*0e209d39SAndroid Build Coastguard Worker * For most use, where there is no extreme performance constraint, the 669*0e209d39SAndroid Build Coastguard Worker * normal, non-inline functions are a better choice. The resulting code 670*0e209d39SAndroid Build Coastguard Worker * will be smaller, and, if the need ever arises, easier to debug. 671*0e209d39SAndroid Build Coastguard Worker * 672*0e209d39SAndroid Build Coastguard Worker * These are implemented as #defines rather than real functions 673*0e209d39SAndroid Build Coastguard Worker * because there is no fully portable way to do inline functions in plain C. 674*0e209d39SAndroid Build Coastguard Worker * 675*0e209d39SAndroid Build Coastguard Worker ************************************************************************************/ 676*0e209d39SAndroid Build Coastguard Worker 677*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API 678*0e209d39SAndroid Build Coastguard Worker /** 679*0e209d39SAndroid Build Coastguard Worker * inline version of utext_current32(), for performance-critical situations. 680*0e209d39SAndroid Build Coastguard Worker * 681*0e209d39SAndroid Build Coastguard Worker * Get the code point at the current iteration position of the UText. 682*0e209d39SAndroid Build Coastguard Worker * Returns U_SENTINEL (-1) if the position is at the end of the 683*0e209d39SAndroid Build Coastguard Worker * text. 684*0e209d39SAndroid Build Coastguard Worker * 685*0e209d39SAndroid Build Coastguard Worker * @internal ICU 4.4 technology preview 686*0e209d39SAndroid Build Coastguard Worker */ 687*0e209d39SAndroid Build Coastguard Worker #define UTEXT_CURRENT32(ut) \ 688*0e209d39SAndroid Build Coastguard Worker ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \ 689*0e209d39SAndroid Build Coastguard Worker ((ut)->chunkContents)[((ut)->chunkOffset)] : utext_current32(ut)) 690*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */ 691*0e209d39SAndroid Build Coastguard Worker 692*0e209d39SAndroid Build Coastguard Worker /** 693*0e209d39SAndroid Build Coastguard Worker * inline version of utext_next32(), for performance-critical situations. 694*0e209d39SAndroid Build Coastguard Worker * 695*0e209d39SAndroid Build Coastguard Worker * Get the code point at the current iteration position of the UText, and 696*0e209d39SAndroid Build Coastguard Worker * advance the position to the first index following the character. 697*0e209d39SAndroid Build Coastguard Worker * This is a post-increment operation. 698*0e209d39SAndroid Build Coastguard Worker * Returns U_SENTINEL (-1) if the position is at the end of the 699*0e209d39SAndroid Build Coastguard Worker * text. 700*0e209d39SAndroid Build Coastguard Worker * 701*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 702*0e209d39SAndroid Build Coastguard Worker */ 703*0e209d39SAndroid Build Coastguard Worker #define UTEXT_NEXT32(ut) \ 704*0e209d39SAndroid Build Coastguard Worker ((ut)->chunkOffset < (ut)->chunkLength && ((ut)->chunkContents)[(ut)->chunkOffset]<0xd800 ? \ 705*0e209d39SAndroid Build Coastguard Worker ((ut)->chunkContents)[((ut)->chunkOffset)++] : utext_next32(ut)) 706*0e209d39SAndroid Build Coastguard Worker 707*0e209d39SAndroid Build Coastguard Worker /** 708*0e209d39SAndroid Build Coastguard Worker * inline version of utext_previous32(), for performance-critical situations. 709*0e209d39SAndroid Build Coastguard Worker * 710*0e209d39SAndroid Build Coastguard Worker * Move the iterator position to the character (code point) whose 711*0e209d39SAndroid Build Coastguard Worker * index precedes the current position, and return that character. 712*0e209d39SAndroid Build Coastguard Worker * This is a pre-decrement operation. 713*0e209d39SAndroid Build Coastguard Worker * Returns U_SENTINEL (-1) if the position is at the start of the text. 714*0e209d39SAndroid Build Coastguard Worker * 715*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 716*0e209d39SAndroid Build Coastguard Worker */ 717*0e209d39SAndroid Build Coastguard Worker #define UTEXT_PREVIOUS32(ut) \ 718*0e209d39SAndroid Build Coastguard Worker ((ut)->chunkOffset > 0 && \ 719*0e209d39SAndroid Build Coastguard Worker (ut)->chunkContents[(ut)->chunkOffset-1] < 0xd800 ? \ 720*0e209d39SAndroid Build Coastguard Worker (ut)->chunkContents[--((ut)->chunkOffset)] : utext_previous32(ut)) 721*0e209d39SAndroid Build Coastguard Worker 722*0e209d39SAndroid Build Coastguard Worker /** 723*0e209d39SAndroid Build Coastguard Worker * inline version of utext_getNativeIndex(), for performance-critical situations. 724*0e209d39SAndroid Build Coastguard Worker * 725*0e209d39SAndroid Build Coastguard Worker * Get the current iterator position, which can range from 0 to 726*0e209d39SAndroid Build Coastguard Worker * the length of the text. 727*0e209d39SAndroid Build Coastguard Worker * The position is a native index into the input text, in whatever format it 728*0e209d39SAndroid Build Coastguard Worker * may have (possibly UTF-8 for example), and may not always be the same as 729*0e209d39SAndroid Build Coastguard Worker * the corresponding UChar (UTF-16) index. 730*0e209d39SAndroid Build Coastguard Worker * The returned position will always be aligned to a code point boundary. 731*0e209d39SAndroid Build Coastguard Worker * 732*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 733*0e209d39SAndroid Build Coastguard Worker */ 734*0e209d39SAndroid Build Coastguard Worker #define UTEXT_GETNATIVEINDEX(ut) \ 735*0e209d39SAndroid Build Coastguard Worker ((ut)->chunkOffset <= (ut)->nativeIndexingLimit? \ 736*0e209d39SAndroid Build Coastguard Worker (ut)->chunkNativeStart+(ut)->chunkOffset : \ 737*0e209d39SAndroid Build Coastguard Worker (ut)->pFuncs->mapOffsetToNative(ut)) 738*0e209d39SAndroid Build Coastguard Worker 739*0e209d39SAndroid Build Coastguard Worker /** 740*0e209d39SAndroid Build Coastguard Worker * inline version of utext_setNativeIndex(), for performance-critical situations. 741*0e209d39SAndroid Build Coastguard Worker * 742*0e209d39SAndroid Build Coastguard Worker * Set the current iteration position to the nearest code point 743*0e209d39SAndroid Build Coastguard Worker * boundary at or preceding the specified index. 744*0e209d39SAndroid Build Coastguard Worker * The index is in the native units of the original input text. 745*0e209d39SAndroid Build Coastguard Worker * If the index is out of range, it will be pinned to be within 746*0e209d39SAndroid Build Coastguard Worker * the range of the input text. 747*0e209d39SAndroid Build Coastguard Worker * 748*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 749*0e209d39SAndroid Build Coastguard Worker */ 750*0e209d39SAndroid Build Coastguard Worker #define UTEXT_SETNATIVEINDEX(ut, ix) UPRV_BLOCK_MACRO_BEGIN { \ 751*0e209d39SAndroid Build Coastguard Worker int64_t __offset = (ix) - (ut)->chunkNativeStart; \ 752*0e209d39SAndroid Build Coastguard Worker if (__offset>=0 && __offset<(int64_t)(ut)->nativeIndexingLimit && (ut)->chunkContents[__offset]<0xdc00) { \ 753*0e209d39SAndroid Build Coastguard Worker (ut)->chunkOffset=(int32_t)__offset; \ 754*0e209d39SAndroid Build Coastguard Worker } else { \ 755*0e209d39SAndroid Build Coastguard Worker utext_setNativeIndex((ut), (ix)); \ 756*0e209d39SAndroid Build Coastguard Worker } \ 757*0e209d39SAndroid Build Coastguard Worker } UPRV_BLOCK_MACRO_END 758*0e209d39SAndroid Build Coastguard Worker 759*0e209d39SAndroid Build Coastguard Worker 760*0e209d39SAndroid Build Coastguard Worker 761*0e209d39SAndroid Build Coastguard Worker /************************************************************************************ 762*0e209d39SAndroid Build Coastguard Worker * 763*0e209d39SAndroid Build Coastguard Worker * Functions related to writing or modifying the text. 764*0e209d39SAndroid Build Coastguard Worker * These will work only with modifiable UTexts. Attempting to 765*0e209d39SAndroid Build Coastguard Worker * modify a read-only UText will return an error status. 766*0e209d39SAndroid Build Coastguard Worker * 767*0e209d39SAndroid Build Coastguard Worker ************************************************************************************/ 768*0e209d39SAndroid Build Coastguard Worker 769*0e209d39SAndroid Build Coastguard Worker 770*0e209d39SAndroid Build Coastguard Worker /** 771*0e209d39SAndroid Build Coastguard Worker * Return true if the text can be written (modified) with utext_replace() or 772*0e209d39SAndroid Build Coastguard Worker * utext_copy(). For the text to be writable, the text provider must 773*0e209d39SAndroid Build Coastguard Worker * be of a type that supports writing and the UText must not be frozen. 774*0e209d39SAndroid Build Coastguard Worker * 775*0e209d39SAndroid Build Coastguard Worker * Attempting to modify text when utext_isWriteable() is false will fail - 776*0e209d39SAndroid Build Coastguard Worker * the text will not be modified, and an error will be returned from the function 777*0e209d39SAndroid Build Coastguard Worker * that attempted the modification. 778*0e209d39SAndroid Build Coastguard Worker * 779*0e209d39SAndroid Build Coastguard Worker * @param ut the UText to be tested. 780*0e209d39SAndroid Build Coastguard Worker * @return true if the text is modifiable. 781*0e209d39SAndroid Build Coastguard Worker * 782*0e209d39SAndroid Build Coastguard Worker * @see utext_freeze() 783*0e209d39SAndroid Build Coastguard Worker * @see utext_replace() 784*0e209d39SAndroid Build Coastguard Worker * @see utext_copy() 785*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 786*0e209d39SAndroid Build Coastguard Worker * 787*0e209d39SAndroid Build Coastguard Worker */ 788*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2 789*0e209d39SAndroid Build Coastguard Worker utext_isWritable(const UText *ut); 790*0e209d39SAndroid Build Coastguard Worker 791*0e209d39SAndroid Build Coastguard Worker 792*0e209d39SAndroid Build Coastguard Worker /** 793*0e209d39SAndroid Build Coastguard Worker * Test whether there is meta data associated with the text. 794*0e209d39SAndroid Build Coastguard Worker * @see Replaceable::hasMetaData() 795*0e209d39SAndroid Build Coastguard Worker * 796*0e209d39SAndroid Build Coastguard Worker * @param ut The UText to be tested 797*0e209d39SAndroid Build Coastguard Worker * @return true if the underlying text includes meta data. 798*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 799*0e209d39SAndroid Build Coastguard Worker */ 800*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2 801*0e209d39SAndroid Build Coastguard Worker utext_hasMetaData(const UText *ut); 802*0e209d39SAndroid Build Coastguard Worker 803*0e209d39SAndroid Build Coastguard Worker 804*0e209d39SAndroid Build Coastguard Worker /** 805*0e209d39SAndroid Build Coastguard Worker * Replace a range of the original text with a replacement text. 806*0e209d39SAndroid Build Coastguard Worker * 807*0e209d39SAndroid Build Coastguard Worker * Leaves the current iteration position at the position following the 808*0e209d39SAndroid Build Coastguard Worker * newly inserted replacement text. 809*0e209d39SAndroid Build Coastguard Worker * 810*0e209d39SAndroid Build Coastguard Worker * This function is only available on UText types that support writing, 811*0e209d39SAndroid Build Coastguard Worker * that is, ones where utext_isWritable() returns true. 812*0e209d39SAndroid Build Coastguard Worker * 813*0e209d39SAndroid Build Coastguard Worker * When using this function, there should be only a single UText opened onto the 814*0e209d39SAndroid Build Coastguard Worker * underlying native text string. Behavior after a replace operation 815*0e209d39SAndroid Build Coastguard Worker * on a UText is undefined for any other additional UTexts that refer to the 816*0e209d39SAndroid Build Coastguard Worker * modified string. 817*0e209d39SAndroid Build Coastguard Worker * 818*0e209d39SAndroid Build Coastguard Worker * @param ut the UText representing the text to be operated on. 819*0e209d39SAndroid Build Coastguard Worker * @param nativeStart the native index of the start of the region to be replaced 820*0e209d39SAndroid Build Coastguard Worker * @param nativeLimit the native index of the character following the region to be replaced. 821*0e209d39SAndroid Build Coastguard Worker * @param replacementText pointer to the replacement text 822*0e209d39SAndroid Build Coastguard Worker * @param replacementLength length of the replacement text, or -1 if the text is NUL terminated. 823*0e209d39SAndroid Build Coastguard Worker * @param status receives any error status. Possible errors include 824*0e209d39SAndroid Build Coastguard Worker * U_NO_WRITE_PERMISSION 825*0e209d39SAndroid Build Coastguard Worker * 826*0e209d39SAndroid Build Coastguard Worker * @return The signed number of (native) storage units by which 827*0e209d39SAndroid Build Coastguard Worker * the length of the text expanded or contracted. 828*0e209d39SAndroid Build Coastguard Worker * 829*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 830*0e209d39SAndroid Build Coastguard Worker */ 831*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2 832*0e209d39SAndroid Build Coastguard Worker utext_replace(UText *ut, 833*0e209d39SAndroid Build Coastguard Worker int64_t nativeStart, int64_t nativeLimit, 834*0e209d39SAndroid Build Coastguard Worker const UChar *replacementText, int32_t replacementLength, 835*0e209d39SAndroid Build Coastguard Worker UErrorCode *status); 836*0e209d39SAndroid Build Coastguard Worker 837*0e209d39SAndroid Build Coastguard Worker 838*0e209d39SAndroid Build Coastguard Worker 839*0e209d39SAndroid Build Coastguard Worker /** 840*0e209d39SAndroid Build Coastguard Worker * 841*0e209d39SAndroid Build Coastguard Worker * Copy or move a substring from one position to another within the text, 842*0e209d39SAndroid Build Coastguard Worker * while retaining any metadata associated with the text. 843*0e209d39SAndroid Build Coastguard Worker * This function is used to duplicate or reorder substrings. 844*0e209d39SAndroid Build Coastguard Worker * The destination index must not overlap the source range. 845*0e209d39SAndroid Build Coastguard Worker * 846*0e209d39SAndroid Build Coastguard Worker * The text to be copied or moved is inserted at destIndex; 847*0e209d39SAndroid Build Coastguard Worker * it does not replace or overwrite any existing text. 848*0e209d39SAndroid Build Coastguard Worker * 849*0e209d39SAndroid Build Coastguard Worker * The iteration position is left following the newly inserted text 850*0e209d39SAndroid Build Coastguard Worker * at the destination position. 851*0e209d39SAndroid Build Coastguard Worker * 852*0e209d39SAndroid Build Coastguard Worker * This function is only available on UText types that support writing, 853*0e209d39SAndroid Build Coastguard Worker * that is, ones where utext_isWritable() returns true. 854*0e209d39SAndroid Build Coastguard Worker * 855*0e209d39SAndroid Build Coastguard Worker * When using this function, there should be only a single UText opened onto the 856*0e209d39SAndroid Build Coastguard Worker * underlying native text string. Behavior after a copy operation 857*0e209d39SAndroid Build Coastguard Worker * on a UText is undefined in any other additional UTexts that refer to the 858*0e209d39SAndroid Build Coastguard Worker * modified string. 859*0e209d39SAndroid Build Coastguard Worker * 860*0e209d39SAndroid Build Coastguard Worker * @param ut The UText representing the text to be operated on. 861*0e209d39SAndroid Build Coastguard Worker * @param nativeStart The native index of the start of the region to be copied or moved 862*0e209d39SAndroid Build Coastguard Worker * @param nativeLimit The native index of the character position following the region 863*0e209d39SAndroid Build Coastguard Worker * to be copied. 864*0e209d39SAndroid Build Coastguard Worker * @param destIndex The native destination index to which the source substring is 865*0e209d39SAndroid Build Coastguard Worker * copied or moved. 866*0e209d39SAndroid Build Coastguard Worker * @param move If true, then the substring is moved, not copied/duplicated. 867*0e209d39SAndroid Build Coastguard Worker * @param status receives any error status. Possible errors include U_NO_WRITE_PERMISSION 868*0e209d39SAndroid Build Coastguard Worker * 869*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 870*0e209d39SAndroid Build Coastguard Worker */ 871*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 872*0e209d39SAndroid Build Coastguard Worker utext_copy(UText *ut, 873*0e209d39SAndroid Build Coastguard Worker int64_t nativeStart, int64_t nativeLimit, 874*0e209d39SAndroid Build Coastguard Worker int64_t destIndex, 875*0e209d39SAndroid Build Coastguard Worker UBool move, 876*0e209d39SAndroid Build Coastguard Worker UErrorCode *status); 877*0e209d39SAndroid Build Coastguard Worker 878*0e209d39SAndroid Build Coastguard Worker 879*0e209d39SAndroid Build Coastguard Worker /** 880*0e209d39SAndroid Build Coastguard Worker * <p> 881*0e209d39SAndroid Build Coastguard Worker * Freeze a UText. This prevents any modification to the underlying text itself 882*0e209d39SAndroid Build Coastguard Worker * by means of functions operating on this UText. 883*0e209d39SAndroid Build Coastguard Worker * </p> 884*0e209d39SAndroid Build Coastguard Worker * <p> 885*0e209d39SAndroid Build Coastguard Worker * Once frozen, a UText can not be unfrozen. The intent is to ensure 886*0e209d39SAndroid Build Coastguard Worker * that a the text underlying a frozen UText wrapper cannot be modified via that UText. 887*0e209d39SAndroid Build Coastguard Worker * </p> 888*0e209d39SAndroid Build Coastguard Worker * <p> 889*0e209d39SAndroid Build Coastguard Worker * Caution: freezing a UText will disable changes made via the specific 890*0e209d39SAndroid Build Coastguard Worker * frozen UText wrapper only; it will not have any effect on the ability to 891*0e209d39SAndroid Build Coastguard Worker * directly modify the text by bypassing the UText. Any such backdoor modifications 892*0e209d39SAndroid Build Coastguard Worker * are always an error while UText access is occurring because the underlying 893*0e209d39SAndroid Build Coastguard Worker * text can get out of sync with UText's buffering. 894*0e209d39SAndroid Build Coastguard Worker * </p> 895*0e209d39SAndroid Build Coastguard Worker * 896*0e209d39SAndroid Build Coastguard Worker * @param ut The UText to be frozen. 897*0e209d39SAndroid Build Coastguard Worker * @see utext_isWritable() 898*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 899*0e209d39SAndroid Build Coastguard Worker */ 900*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 901*0e209d39SAndroid Build Coastguard Worker utext_freeze(UText *ut); 902*0e209d39SAndroid Build Coastguard Worker 903*0e209d39SAndroid Build Coastguard Worker 904*0e209d39SAndroid Build Coastguard Worker /** 905*0e209d39SAndroid Build Coastguard Worker * UText provider properties (bit field indexes). 906*0e209d39SAndroid Build Coastguard Worker * 907*0e209d39SAndroid Build Coastguard Worker * @see UText 908*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 909*0e209d39SAndroid Build Coastguard Worker */ 910*0e209d39SAndroid Build Coastguard Worker enum { 911*0e209d39SAndroid Build Coastguard Worker /** 912*0e209d39SAndroid Build Coastguard Worker * It is potentially time consuming for the provider to determine the length of the text. 913*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 914*0e209d39SAndroid Build Coastguard Worker */ 915*0e209d39SAndroid Build Coastguard Worker UTEXT_PROVIDER_LENGTH_IS_EXPENSIVE = 1, 916*0e209d39SAndroid Build Coastguard Worker /** 917*0e209d39SAndroid Build Coastguard Worker * Text chunks remain valid and usable until the text object is modified or 918*0e209d39SAndroid Build Coastguard Worker * deleted, not just until the next time the access() function is called 919*0e209d39SAndroid Build Coastguard Worker * (which is the default). 920*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 921*0e209d39SAndroid Build Coastguard Worker */ 922*0e209d39SAndroid Build Coastguard Worker UTEXT_PROVIDER_STABLE_CHUNKS = 2, 923*0e209d39SAndroid Build Coastguard Worker /** 924*0e209d39SAndroid Build Coastguard Worker * The provider supports modifying the text via the replace() and copy() 925*0e209d39SAndroid Build Coastguard Worker * functions. 926*0e209d39SAndroid Build Coastguard Worker * @see Replaceable 927*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 928*0e209d39SAndroid Build Coastguard Worker */ 929*0e209d39SAndroid Build Coastguard Worker UTEXT_PROVIDER_WRITABLE = 3, 930*0e209d39SAndroid Build Coastguard Worker /** 931*0e209d39SAndroid Build Coastguard Worker * There is meta data associated with the text. 932*0e209d39SAndroid Build Coastguard Worker * @see Replaceable::hasMetaData() 933*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 934*0e209d39SAndroid Build Coastguard Worker */ 935*0e209d39SAndroid Build Coastguard Worker UTEXT_PROVIDER_HAS_META_DATA = 4, 936*0e209d39SAndroid Build Coastguard Worker /** 937*0e209d39SAndroid Build Coastguard Worker * Text provider owns the text storage. 938*0e209d39SAndroid Build Coastguard Worker * Generally occurs as the result of a deep clone of the UText. 939*0e209d39SAndroid Build Coastguard Worker * When closing the UText, the associated text must 940*0e209d39SAndroid Build Coastguard Worker * also be closed/deleted/freed/ whatever is appropriate. 941*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 942*0e209d39SAndroid Build Coastguard Worker */ 943*0e209d39SAndroid Build Coastguard Worker UTEXT_PROVIDER_OWNS_TEXT = 5 944*0e209d39SAndroid Build Coastguard Worker }; 945*0e209d39SAndroid Build Coastguard Worker 946*0e209d39SAndroid Build Coastguard Worker /** 947*0e209d39SAndroid Build Coastguard Worker * Function type declaration for UText.clone(). 948*0e209d39SAndroid Build Coastguard Worker * 949*0e209d39SAndroid Build Coastguard Worker * clone a UText. Much like opening a UText where the source text is itself 950*0e209d39SAndroid Build Coastguard Worker * another UText. 951*0e209d39SAndroid Build Coastguard Worker * 952*0e209d39SAndroid Build Coastguard Worker * A deep clone will copy both the UText data structures and the underlying text. 953*0e209d39SAndroid Build Coastguard Worker * The original and cloned UText will operate completely independently; modifications 954*0e209d39SAndroid Build Coastguard Worker * made to the text in one will not effect the other. Text providers are not 955*0e209d39SAndroid Build Coastguard Worker * required to support deep clones. The user of clone() must check the status return 956*0e209d39SAndroid Build Coastguard Worker * and be prepared to handle failures. 957*0e209d39SAndroid Build Coastguard Worker * 958*0e209d39SAndroid Build Coastguard Worker * A shallow clone replicates only the UText data structures; it does not make 959*0e209d39SAndroid Build Coastguard Worker * a copy of the underlying text. Shallow clones can be used as an efficient way to 960*0e209d39SAndroid Build Coastguard Worker * have multiple iterators active in a single text string that is not being 961*0e209d39SAndroid Build Coastguard Worker * modified. 962*0e209d39SAndroid Build Coastguard Worker * 963*0e209d39SAndroid Build Coastguard Worker * A shallow clone operation must not fail except for truly exceptional conditions such 964*0e209d39SAndroid Build Coastguard Worker * as memory allocation failures. 965*0e209d39SAndroid Build Coastguard Worker * 966*0e209d39SAndroid Build Coastguard Worker * A UText and its clone may be safely concurrently accessed by separate threads. 967*0e209d39SAndroid Build Coastguard Worker * This is true for both shallow and deep clones. 968*0e209d39SAndroid Build Coastguard Worker * It is the responsibility of the Text Provider to ensure that this thread safety 969*0e209d39SAndroid Build Coastguard Worker * constraint is met. 970*0e209d39SAndroid Build Coastguard Worker 971*0e209d39SAndroid Build Coastguard Worker * 972*0e209d39SAndroid Build Coastguard Worker * @param dest A UText struct to be filled in with the result of the clone operation, 973*0e209d39SAndroid Build Coastguard Worker * or NULL if the clone function should heap-allocate a new UText struct. 974*0e209d39SAndroid Build Coastguard Worker * @param src The UText to be cloned. 975*0e209d39SAndroid Build Coastguard Worker * @param deep true to request a deep clone, false for a shallow clone. 976*0e209d39SAndroid Build Coastguard Worker * @param status Errors are returned here. For deep clones, U_UNSUPPORTED_ERROR 977*0e209d39SAndroid Build Coastguard Worker * should be returned if the text provider is unable to clone the 978*0e209d39SAndroid Build Coastguard Worker * original text. 979*0e209d39SAndroid Build Coastguard Worker * @return The newly created clone, or NULL if the clone operation failed. 980*0e209d39SAndroid Build Coastguard Worker * 981*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 982*0e209d39SAndroid Build Coastguard Worker */ 983*0e209d39SAndroid Build Coastguard Worker typedef UText * U_CALLCONV 984*0e209d39SAndroid Build Coastguard Worker UTextClone(UText *dest, const UText *src, UBool deep, UErrorCode *status); 985*0e209d39SAndroid Build Coastguard Worker 986*0e209d39SAndroid Build Coastguard Worker 987*0e209d39SAndroid Build Coastguard Worker /** 988*0e209d39SAndroid Build Coastguard Worker * Function type declaration for UText.nativeLength(). 989*0e209d39SAndroid Build Coastguard Worker * 990*0e209d39SAndroid Build Coastguard Worker * @param ut the UText to get the length of. 991*0e209d39SAndroid Build Coastguard Worker * @return the length, in the native units of the original text string. 992*0e209d39SAndroid Build Coastguard Worker * @see UText 993*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 994*0e209d39SAndroid Build Coastguard Worker */ 995*0e209d39SAndroid Build Coastguard Worker typedef int64_t U_CALLCONV 996*0e209d39SAndroid Build Coastguard Worker UTextNativeLength(UText *ut); 997*0e209d39SAndroid Build Coastguard Worker 998*0e209d39SAndroid Build Coastguard Worker /** 999*0e209d39SAndroid Build Coastguard Worker * Function type declaration for UText.access(). Get the description of the text chunk 1000*0e209d39SAndroid Build Coastguard Worker * containing the text at a requested native index. The UText's iteration 1001*0e209d39SAndroid Build Coastguard Worker * position will be left at the requested index. If the index is out 1002*0e209d39SAndroid Build Coastguard Worker * of bounds, the iteration position will be left at the start or end 1003*0e209d39SAndroid Build Coastguard Worker * of the string, as appropriate. 1004*0e209d39SAndroid Build Coastguard Worker * 1005*0e209d39SAndroid Build Coastguard Worker * Chunks must begin and end on code point boundaries. A single code point 1006*0e209d39SAndroid Build Coastguard Worker * comprised of multiple storage units must never span a chunk boundary. 1007*0e209d39SAndroid Build Coastguard Worker * 1008*0e209d39SAndroid Build Coastguard Worker * 1009*0e209d39SAndroid Build Coastguard Worker * @param ut the UText being accessed. 1010*0e209d39SAndroid Build Coastguard Worker * @param nativeIndex Requested index of the text to be accessed. 1011*0e209d39SAndroid Build Coastguard Worker * @param forward If true, then the returned chunk must contain text 1012*0e209d39SAndroid Build Coastguard Worker * starting from the index, so that start<=index<limit. 1013*0e209d39SAndroid Build Coastguard Worker * If false, then the returned chunk must contain text 1014*0e209d39SAndroid Build Coastguard Worker * before the index, so that start<index<=limit. 1015*0e209d39SAndroid Build Coastguard Worker * @return True if the requested index could be accessed. The chunk 1016*0e209d39SAndroid Build Coastguard Worker * will contain the requested text. 1017*0e209d39SAndroid Build Coastguard Worker * False value if a chunk cannot be accessed 1018*0e209d39SAndroid Build Coastguard Worker * (the requested index is out of bounds). 1019*0e209d39SAndroid Build Coastguard Worker * 1020*0e209d39SAndroid Build Coastguard Worker * @see UText 1021*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1022*0e209d39SAndroid Build Coastguard Worker */ 1023*0e209d39SAndroid Build Coastguard Worker typedef UBool U_CALLCONV 1024*0e209d39SAndroid Build Coastguard Worker UTextAccess(UText *ut, int64_t nativeIndex, UBool forward); 1025*0e209d39SAndroid Build Coastguard Worker 1026*0e209d39SAndroid Build Coastguard Worker /** 1027*0e209d39SAndroid Build Coastguard Worker * Function type declaration for UText.extract(). 1028*0e209d39SAndroid Build Coastguard Worker * 1029*0e209d39SAndroid Build Coastguard Worker * Extract text from a UText into a UChar buffer. The range of text to be extracted 1030*0e209d39SAndroid Build Coastguard Worker * is specified in the native indices of the UText provider. These may not necessarily 1031*0e209d39SAndroid Build Coastguard Worker * be UTF-16 indices. 1032*0e209d39SAndroid Build Coastguard Worker * <p> 1033*0e209d39SAndroid Build Coastguard Worker * The size (number of 16 bit UChars) in the data to be extracted is returned. The 1034*0e209d39SAndroid Build Coastguard Worker * full amount is returned, even when the specified buffer size is smaller. 1035*0e209d39SAndroid Build Coastguard Worker * <p> 1036*0e209d39SAndroid Build Coastguard Worker * The extracted string will (if you are a user) / must (if you are a text provider) 1037*0e209d39SAndroid Build Coastguard Worker * be NUL-terminated if there is sufficient space in the destination buffer. 1038*0e209d39SAndroid Build Coastguard Worker * 1039*0e209d39SAndroid Build Coastguard Worker * @param ut the UText from which to extract data. 1040*0e209d39SAndroid Build Coastguard Worker * @param nativeStart the native index of the first character to extract. 1041*0e209d39SAndroid Build Coastguard Worker * @param nativeLimit the native string index of the position following the last 1042*0e209d39SAndroid Build Coastguard Worker * character to extract. 1043*0e209d39SAndroid Build Coastguard Worker * @param dest the UChar (UTF-16) buffer into which the extracted text is placed 1044*0e209d39SAndroid Build Coastguard Worker * @param destCapacity The size, in UChars, of the destination buffer. May be zero 1045*0e209d39SAndroid Build Coastguard Worker * for precomputing the required size. 1046*0e209d39SAndroid Build Coastguard Worker * @param status receives any error status. 1047*0e209d39SAndroid Build Coastguard Worker * If U_BUFFER_OVERFLOW_ERROR: Returns number of UChars for 1048*0e209d39SAndroid Build Coastguard Worker * preflighting. 1049*0e209d39SAndroid Build Coastguard Worker * @return Number of UChars in the data. Does not include a trailing NUL. 1050*0e209d39SAndroid Build Coastguard Worker * 1051*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1052*0e209d39SAndroid Build Coastguard Worker */ 1053*0e209d39SAndroid Build Coastguard Worker typedef int32_t U_CALLCONV 1054*0e209d39SAndroid Build Coastguard Worker UTextExtract(UText *ut, 1055*0e209d39SAndroid Build Coastguard Worker int64_t nativeStart, int64_t nativeLimit, 1056*0e209d39SAndroid Build Coastguard Worker UChar *dest, int32_t destCapacity, 1057*0e209d39SAndroid Build Coastguard Worker UErrorCode *status); 1058*0e209d39SAndroid Build Coastguard Worker 1059*0e209d39SAndroid Build Coastguard Worker /** 1060*0e209d39SAndroid Build Coastguard Worker * Function type declaration for UText.replace(). 1061*0e209d39SAndroid Build Coastguard Worker * 1062*0e209d39SAndroid Build Coastguard Worker * Replace a range of the original text with a replacement text. 1063*0e209d39SAndroid Build Coastguard Worker * 1064*0e209d39SAndroid Build Coastguard Worker * Leaves the current iteration position at the position following the 1065*0e209d39SAndroid Build Coastguard Worker * newly inserted replacement text. 1066*0e209d39SAndroid Build Coastguard Worker * 1067*0e209d39SAndroid Build Coastguard Worker * This function need only be implemented on UText types that support writing. 1068*0e209d39SAndroid Build Coastguard Worker * 1069*0e209d39SAndroid Build Coastguard Worker * When using this function, there should be only a single UText opened onto the 1070*0e209d39SAndroid Build Coastguard Worker * underlying native text string. The function is responsible for updating the 1071*0e209d39SAndroid Build Coastguard Worker * text chunk within the UText to reflect the updated iteration position, 1072*0e209d39SAndroid Build Coastguard Worker * taking into account any changes to the underlying string's structure caused 1073*0e209d39SAndroid Build Coastguard Worker * by the replace operation. 1074*0e209d39SAndroid Build Coastguard Worker * 1075*0e209d39SAndroid Build Coastguard Worker * @param ut the UText representing the text to be operated on. 1076*0e209d39SAndroid Build Coastguard Worker * @param nativeStart the index of the start of the region to be replaced 1077*0e209d39SAndroid Build Coastguard Worker * @param nativeLimit the index of the character following the region to be replaced. 1078*0e209d39SAndroid Build Coastguard Worker * @param replacementText pointer to the replacement text 1079*0e209d39SAndroid Build Coastguard Worker * @param replacmentLength length of the replacement text in UChars, or -1 if the text is NUL terminated. 1080*0e209d39SAndroid Build Coastguard Worker * @param status receives any error status. Possible errors include 1081*0e209d39SAndroid Build Coastguard Worker * U_NO_WRITE_PERMISSION 1082*0e209d39SAndroid Build Coastguard Worker * 1083*0e209d39SAndroid Build Coastguard Worker * @return The signed number of (native) storage units by which 1084*0e209d39SAndroid Build Coastguard Worker * the length of the text expanded or contracted. 1085*0e209d39SAndroid Build Coastguard Worker * 1086*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1087*0e209d39SAndroid Build Coastguard Worker */ 1088*0e209d39SAndroid Build Coastguard Worker typedef int32_t U_CALLCONV 1089*0e209d39SAndroid Build Coastguard Worker UTextReplace(UText *ut, 1090*0e209d39SAndroid Build Coastguard Worker int64_t nativeStart, int64_t nativeLimit, 1091*0e209d39SAndroid Build Coastguard Worker const UChar *replacementText, int32_t replacmentLength, 1092*0e209d39SAndroid Build Coastguard Worker UErrorCode *status); 1093*0e209d39SAndroid Build Coastguard Worker 1094*0e209d39SAndroid Build Coastguard Worker /** 1095*0e209d39SAndroid Build Coastguard Worker * Function type declaration for UText.copy(). 1096*0e209d39SAndroid Build Coastguard Worker * 1097*0e209d39SAndroid Build Coastguard Worker * Copy or move a substring from one position to another within the text, 1098*0e209d39SAndroid Build Coastguard Worker * while retaining any metadata associated with the text. 1099*0e209d39SAndroid Build Coastguard Worker * This function is used to duplicate or reorder substrings. 1100*0e209d39SAndroid Build Coastguard Worker * The destination index must not overlap the source range. 1101*0e209d39SAndroid Build Coastguard Worker * 1102*0e209d39SAndroid Build Coastguard Worker * The text to be copied or moved is inserted at destIndex; 1103*0e209d39SAndroid Build Coastguard Worker * it does not replace or overwrite any existing text. 1104*0e209d39SAndroid Build Coastguard Worker * 1105*0e209d39SAndroid Build Coastguard Worker * This function need only be implemented for UText types that support writing. 1106*0e209d39SAndroid Build Coastguard Worker * 1107*0e209d39SAndroid Build Coastguard Worker * When using this function, there should be only a single UText opened onto the 1108*0e209d39SAndroid Build Coastguard Worker * underlying native text string. The function is responsible for updating the 1109*0e209d39SAndroid Build Coastguard Worker * text chunk within the UText to reflect the updated iteration position, 1110*0e209d39SAndroid Build Coastguard Worker * taking into account any changes to the underlying string's structure caused 1111*0e209d39SAndroid Build Coastguard Worker * by the replace operation. 1112*0e209d39SAndroid Build Coastguard Worker * 1113*0e209d39SAndroid Build Coastguard Worker * @param ut The UText representing the text to be operated on. 1114*0e209d39SAndroid Build Coastguard Worker * @param nativeStart The index of the start of the region to be copied or moved 1115*0e209d39SAndroid Build Coastguard Worker * @param nativeLimit The index of the character following the region to be replaced. 1116*0e209d39SAndroid Build Coastguard Worker * @param nativeDest The destination index to which the source substring is copied or moved. 1117*0e209d39SAndroid Build Coastguard Worker * @param move If true, then the substring is moved, not copied/duplicated. 1118*0e209d39SAndroid Build Coastguard Worker * @param status receives any error status. Possible errors include U_NO_WRITE_PERMISSION 1119*0e209d39SAndroid Build Coastguard Worker * 1120*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1121*0e209d39SAndroid Build Coastguard Worker */ 1122*0e209d39SAndroid Build Coastguard Worker typedef void U_CALLCONV 1123*0e209d39SAndroid Build Coastguard Worker UTextCopy(UText *ut, 1124*0e209d39SAndroid Build Coastguard Worker int64_t nativeStart, int64_t nativeLimit, 1125*0e209d39SAndroid Build Coastguard Worker int64_t nativeDest, 1126*0e209d39SAndroid Build Coastguard Worker UBool move, 1127*0e209d39SAndroid Build Coastguard Worker UErrorCode *status); 1128*0e209d39SAndroid Build Coastguard Worker 1129*0e209d39SAndroid Build Coastguard Worker /** 1130*0e209d39SAndroid Build Coastguard Worker * Function type declaration for UText.mapOffsetToNative(). 1131*0e209d39SAndroid Build Coastguard Worker * Map from the current UChar offset within the current text chunk to 1132*0e209d39SAndroid Build Coastguard Worker * the corresponding native index in the original source text. 1133*0e209d39SAndroid Build Coastguard Worker * 1134*0e209d39SAndroid Build Coastguard Worker * This is required only for text providers that do not use native UTF-16 indexes. 1135*0e209d39SAndroid Build Coastguard Worker * 1136*0e209d39SAndroid Build Coastguard Worker * @param ut the UText. 1137*0e209d39SAndroid Build Coastguard Worker * @return Absolute (native) index corresponding to chunkOffset in the current chunk. 1138*0e209d39SAndroid Build Coastguard Worker * The returned native index should always be to a code point boundary. 1139*0e209d39SAndroid Build Coastguard Worker * 1140*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1141*0e209d39SAndroid Build Coastguard Worker */ 1142*0e209d39SAndroid Build Coastguard Worker typedef int64_t U_CALLCONV 1143*0e209d39SAndroid Build Coastguard Worker UTextMapOffsetToNative(const UText *ut); 1144*0e209d39SAndroid Build Coastguard Worker 1145*0e209d39SAndroid Build Coastguard Worker /** 1146*0e209d39SAndroid Build Coastguard Worker * Function type declaration for UText.mapIndexToUTF16(). 1147*0e209d39SAndroid Build Coastguard Worker * Map from a native index to a UChar offset within a text chunk. 1148*0e209d39SAndroid Build Coastguard Worker * Behavior is undefined if the native index does not fall within the 1149*0e209d39SAndroid Build Coastguard Worker * current chunk. 1150*0e209d39SAndroid Build Coastguard Worker * 1151*0e209d39SAndroid Build Coastguard Worker * This function is required only for text providers that do not use native UTF-16 indexes. 1152*0e209d39SAndroid Build Coastguard Worker * 1153*0e209d39SAndroid Build Coastguard Worker * @param ut The UText containing the text chunk. 1154*0e209d39SAndroid Build Coastguard Worker * @param nativeIndex Absolute (native) text index, chunk->start<=index<=chunk->limit. 1155*0e209d39SAndroid Build Coastguard Worker * @return Chunk-relative UTF-16 offset corresponding to the specified native 1156*0e209d39SAndroid Build Coastguard Worker * index. 1157*0e209d39SAndroid Build Coastguard Worker * 1158*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1159*0e209d39SAndroid Build Coastguard Worker */ 1160*0e209d39SAndroid Build Coastguard Worker typedef int32_t U_CALLCONV 1161*0e209d39SAndroid Build Coastguard Worker UTextMapNativeIndexToUTF16(const UText *ut, int64_t nativeIndex); 1162*0e209d39SAndroid Build Coastguard Worker 1163*0e209d39SAndroid Build Coastguard Worker 1164*0e209d39SAndroid Build Coastguard Worker /** 1165*0e209d39SAndroid Build Coastguard Worker * Function type declaration for UText.utextClose(). 1166*0e209d39SAndroid Build Coastguard Worker * 1167*0e209d39SAndroid Build Coastguard Worker * A Text Provider close function is only required for provider types that make 1168*0e209d39SAndroid Build Coastguard Worker * allocations in their open function (or other functions) that must be 1169*0e209d39SAndroid Build Coastguard Worker * cleaned when the UText is closed. 1170*0e209d39SAndroid Build Coastguard Worker * 1171*0e209d39SAndroid Build Coastguard Worker * The allocation of the UText struct itself and any "extra" storage 1172*0e209d39SAndroid Build Coastguard Worker * associated with the UText is handled by the common UText implementation 1173*0e209d39SAndroid Build Coastguard Worker * and does not require provider specific cleanup in a close function. 1174*0e209d39SAndroid Build Coastguard Worker * 1175*0e209d39SAndroid Build Coastguard Worker * Most UText provider implementations do not need to implement this function. 1176*0e209d39SAndroid Build Coastguard Worker * 1177*0e209d39SAndroid Build Coastguard Worker * @param ut A UText object to be closed. 1178*0e209d39SAndroid Build Coastguard Worker * 1179*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1180*0e209d39SAndroid Build Coastguard Worker */ 1181*0e209d39SAndroid Build Coastguard Worker typedef void U_CALLCONV 1182*0e209d39SAndroid Build Coastguard Worker UTextClose(UText *ut); 1183*0e209d39SAndroid Build Coastguard Worker 1184*0e209d39SAndroid Build Coastguard Worker 1185*0e209d39SAndroid Build Coastguard Worker /** 1186*0e209d39SAndroid Build Coastguard Worker * (public) Function dispatch table for UText. 1187*0e209d39SAndroid Build Coastguard Worker * Conceptually very much like a C++ Virtual Function Table. 1188*0e209d39SAndroid Build Coastguard Worker * This struct defines the organization of the table. 1189*0e209d39SAndroid Build Coastguard Worker * Each text provider implementation must provide an 1190*0e209d39SAndroid Build Coastguard Worker * actual table that is initialized with the appropriate functions 1191*0e209d39SAndroid Build Coastguard Worker * for the type of text being handled. 1192*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1193*0e209d39SAndroid Build Coastguard Worker */ 1194*0e209d39SAndroid Build Coastguard Worker struct UTextFuncs { 1195*0e209d39SAndroid Build Coastguard Worker /** 1196*0e209d39SAndroid Build Coastguard Worker * (public) Function table size, sizeof(UTextFuncs) 1197*0e209d39SAndroid Build Coastguard Worker * Intended for use should the table grow to accommodate added 1198*0e209d39SAndroid Build Coastguard Worker * functions in the future, to allow tests for older format 1199*0e209d39SAndroid Build Coastguard Worker * function tables that do not contain the extensions. 1200*0e209d39SAndroid Build Coastguard Worker * 1201*0e209d39SAndroid Build Coastguard Worker * Fields are placed for optimal alignment on 1202*0e209d39SAndroid Build Coastguard Worker * 32/64/128-bit-pointer machines, by normally grouping together 1203*0e209d39SAndroid Build Coastguard Worker * 4 32-bit fields, 1204*0e209d39SAndroid Build Coastguard Worker * 4 pointers, 1205*0e209d39SAndroid Build Coastguard Worker * 2 64-bit fields 1206*0e209d39SAndroid Build Coastguard Worker * in sequence. 1207*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1208*0e209d39SAndroid Build Coastguard Worker */ 1209*0e209d39SAndroid Build Coastguard Worker int32_t tableSize; 1210*0e209d39SAndroid Build Coastguard Worker 1211*0e209d39SAndroid Build Coastguard Worker /** 1212*0e209d39SAndroid Build Coastguard Worker * (private) Alignment padding. 1213*0e209d39SAndroid Build Coastguard Worker * Do not use, reserved for use by the UText framework only. 1214*0e209d39SAndroid Build Coastguard Worker * @internal 1215*0e209d39SAndroid Build Coastguard Worker */ 1216*0e209d39SAndroid Build Coastguard Worker int32_t reserved1, /** @internal */ reserved2, /** @internal */ reserved3; 1217*0e209d39SAndroid Build Coastguard Worker 1218*0e209d39SAndroid Build Coastguard Worker 1219*0e209d39SAndroid Build Coastguard Worker /** 1220*0e209d39SAndroid Build Coastguard Worker * (public) Function pointer for UTextClone 1221*0e209d39SAndroid Build Coastguard Worker * 1222*0e209d39SAndroid Build Coastguard Worker * @see UTextClone 1223*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1224*0e209d39SAndroid Build Coastguard Worker */ 1225*0e209d39SAndroid Build Coastguard Worker UTextClone *clone; 1226*0e209d39SAndroid Build Coastguard Worker 1227*0e209d39SAndroid Build Coastguard Worker /** 1228*0e209d39SAndroid Build Coastguard Worker * (public) function pointer for UTextLength 1229*0e209d39SAndroid Build Coastguard Worker * May be expensive to compute! 1230*0e209d39SAndroid Build Coastguard Worker * 1231*0e209d39SAndroid Build Coastguard Worker * @see UTextLength 1232*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1233*0e209d39SAndroid Build Coastguard Worker */ 1234*0e209d39SAndroid Build Coastguard Worker UTextNativeLength *nativeLength; 1235*0e209d39SAndroid Build Coastguard Worker 1236*0e209d39SAndroid Build Coastguard Worker /** 1237*0e209d39SAndroid Build Coastguard Worker * (public) Function pointer for UTextAccess. 1238*0e209d39SAndroid Build Coastguard Worker * 1239*0e209d39SAndroid Build Coastguard Worker * @see UTextAccess 1240*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1241*0e209d39SAndroid Build Coastguard Worker */ 1242*0e209d39SAndroid Build Coastguard Worker UTextAccess *access; 1243*0e209d39SAndroid Build Coastguard Worker 1244*0e209d39SAndroid Build Coastguard Worker /** 1245*0e209d39SAndroid Build Coastguard Worker * (public) Function pointer for UTextExtract. 1246*0e209d39SAndroid Build Coastguard Worker * 1247*0e209d39SAndroid Build Coastguard Worker * @see UTextExtract 1248*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1249*0e209d39SAndroid Build Coastguard Worker */ 1250*0e209d39SAndroid Build Coastguard Worker UTextExtract *extract; 1251*0e209d39SAndroid Build Coastguard Worker 1252*0e209d39SAndroid Build Coastguard Worker /** 1253*0e209d39SAndroid Build Coastguard Worker * (public) Function pointer for UTextReplace. 1254*0e209d39SAndroid Build Coastguard Worker * 1255*0e209d39SAndroid Build Coastguard Worker * @see UTextReplace 1256*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1257*0e209d39SAndroid Build Coastguard Worker */ 1258*0e209d39SAndroid Build Coastguard Worker UTextReplace *replace; 1259*0e209d39SAndroid Build Coastguard Worker 1260*0e209d39SAndroid Build Coastguard Worker /** 1261*0e209d39SAndroid Build Coastguard Worker * (public) Function pointer for UTextCopy. 1262*0e209d39SAndroid Build Coastguard Worker * 1263*0e209d39SAndroid Build Coastguard Worker * @see UTextCopy 1264*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1265*0e209d39SAndroid Build Coastguard Worker */ 1266*0e209d39SAndroid Build Coastguard Worker UTextCopy *copy; 1267*0e209d39SAndroid Build Coastguard Worker 1268*0e209d39SAndroid Build Coastguard Worker /** 1269*0e209d39SAndroid Build Coastguard Worker * (public) Function pointer for UTextMapOffsetToNative. 1270*0e209d39SAndroid Build Coastguard Worker * 1271*0e209d39SAndroid Build Coastguard Worker * @see UTextMapOffsetToNative 1272*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1273*0e209d39SAndroid Build Coastguard Worker */ 1274*0e209d39SAndroid Build Coastguard Worker UTextMapOffsetToNative *mapOffsetToNative; 1275*0e209d39SAndroid Build Coastguard Worker 1276*0e209d39SAndroid Build Coastguard Worker /** 1277*0e209d39SAndroid Build Coastguard Worker * (public) Function pointer for UTextMapNativeIndexToUTF16. 1278*0e209d39SAndroid Build Coastguard Worker * 1279*0e209d39SAndroid Build Coastguard Worker * @see UTextMapNativeIndexToUTF16 1280*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1281*0e209d39SAndroid Build Coastguard Worker */ 1282*0e209d39SAndroid Build Coastguard Worker UTextMapNativeIndexToUTF16 *mapNativeIndexToUTF16; 1283*0e209d39SAndroid Build Coastguard Worker 1284*0e209d39SAndroid Build Coastguard Worker /** 1285*0e209d39SAndroid Build Coastguard Worker * (public) Function pointer for UTextClose. 1286*0e209d39SAndroid Build Coastguard Worker * 1287*0e209d39SAndroid Build Coastguard Worker * @see UTextClose 1288*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1289*0e209d39SAndroid Build Coastguard Worker */ 1290*0e209d39SAndroid Build Coastguard Worker UTextClose *close; 1291*0e209d39SAndroid Build Coastguard Worker 1292*0e209d39SAndroid Build Coastguard Worker /** 1293*0e209d39SAndroid Build Coastguard Worker * (private) Spare function pointer 1294*0e209d39SAndroid Build Coastguard Worker * @internal 1295*0e209d39SAndroid Build Coastguard Worker */ 1296*0e209d39SAndroid Build Coastguard Worker UTextClose *spare1; 1297*0e209d39SAndroid Build Coastguard Worker 1298*0e209d39SAndroid Build Coastguard Worker /** 1299*0e209d39SAndroid Build Coastguard Worker * (private) Spare function pointer 1300*0e209d39SAndroid Build Coastguard Worker * @internal 1301*0e209d39SAndroid Build Coastguard Worker */ 1302*0e209d39SAndroid Build Coastguard Worker UTextClose *spare2; 1303*0e209d39SAndroid Build Coastguard Worker 1304*0e209d39SAndroid Build Coastguard Worker /** 1305*0e209d39SAndroid Build Coastguard Worker * (private) Spare function pointer 1306*0e209d39SAndroid Build Coastguard Worker * @internal 1307*0e209d39SAndroid Build Coastguard Worker */ 1308*0e209d39SAndroid Build Coastguard Worker UTextClose *spare3; 1309*0e209d39SAndroid Build Coastguard Worker 1310*0e209d39SAndroid Build Coastguard Worker }; 1311*0e209d39SAndroid Build Coastguard Worker /** 1312*0e209d39SAndroid Build Coastguard Worker * Function dispatch table for UText 1313*0e209d39SAndroid Build Coastguard Worker * @see UTextFuncs 1314*0e209d39SAndroid Build Coastguard Worker */ 1315*0e209d39SAndroid Build Coastguard Worker typedef struct UTextFuncs UTextFuncs; 1316*0e209d39SAndroid Build Coastguard Worker 1317*0e209d39SAndroid Build Coastguard Worker /** 1318*0e209d39SAndroid Build Coastguard Worker * UText struct. Provides the interface between the generic UText access code 1319*0e209d39SAndroid Build Coastguard Worker * and the UText provider code that works on specific kinds of 1320*0e209d39SAndroid Build Coastguard Worker * text (UTF-8, noncontiguous UTF-16, whatever.) 1321*0e209d39SAndroid Build Coastguard Worker * 1322*0e209d39SAndroid Build Coastguard Worker * Applications that are using predefined types of text providers 1323*0e209d39SAndroid Build Coastguard Worker * to pass text data to ICU services will have no need to view the 1324*0e209d39SAndroid Build Coastguard Worker * internals of the UText structs that they open. 1325*0e209d39SAndroid Build Coastguard Worker * 1326*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1327*0e209d39SAndroid Build Coastguard Worker */ 1328*0e209d39SAndroid Build Coastguard Worker struct UText { 1329*0e209d39SAndroid Build Coastguard Worker /** 1330*0e209d39SAndroid Build Coastguard Worker * (private) Magic. Used to help detect when UText functions are handed 1331*0e209d39SAndroid Build Coastguard Worker * invalid or uninitialized UText structs. 1332*0e209d39SAndroid Build Coastguard Worker * utext_openXYZ() functions take an initialized, 1333*0e209d39SAndroid Build Coastguard Worker * but not necessarily open, UText struct as an 1334*0e209d39SAndroid Build Coastguard Worker * optional fill-in parameter. This magic field 1335*0e209d39SAndroid Build Coastguard Worker * is used to check for that initialization. 1336*0e209d39SAndroid Build Coastguard Worker * Text provider close functions must NOT clear 1337*0e209d39SAndroid Build Coastguard Worker * the magic field because that would prevent 1338*0e209d39SAndroid Build Coastguard Worker * reuse of the UText struct. 1339*0e209d39SAndroid Build Coastguard Worker * @internal 1340*0e209d39SAndroid Build Coastguard Worker */ 1341*0e209d39SAndroid Build Coastguard Worker uint32_t magic; 1342*0e209d39SAndroid Build Coastguard Worker 1343*0e209d39SAndroid Build Coastguard Worker 1344*0e209d39SAndroid Build Coastguard Worker /** 1345*0e209d39SAndroid Build Coastguard Worker * (private) Flags for managing the allocation and freeing of 1346*0e209d39SAndroid Build Coastguard Worker * memory associated with this UText. 1347*0e209d39SAndroid Build Coastguard Worker * @internal 1348*0e209d39SAndroid Build Coastguard Worker */ 1349*0e209d39SAndroid Build Coastguard Worker int32_t flags; 1350*0e209d39SAndroid Build Coastguard Worker 1351*0e209d39SAndroid Build Coastguard Worker 1352*0e209d39SAndroid Build Coastguard Worker /** 1353*0e209d39SAndroid Build Coastguard Worker * Text provider properties. This set of flags is maintained by the 1354*0e209d39SAndroid Build Coastguard Worker * text provider implementation. 1355*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1356*0e209d39SAndroid Build Coastguard Worker */ 1357*0e209d39SAndroid Build Coastguard Worker int32_t providerProperties; 1358*0e209d39SAndroid Build Coastguard Worker 1359*0e209d39SAndroid Build Coastguard Worker /** 1360*0e209d39SAndroid Build Coastguard Worker * (public) sizeOfStruct=sizeof(UText) 1361*0e209d39SAndroid Build Coastguard Worker * Allows possible backward compatible extension. 1362*0e209d39SAndroid Build Coastguard Worker * 1363*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1364*0e209d39SAndroid Build Coastguard Worker */ 1365*0e209d39SAndroid Build Coastguard Worker int32_t sizeOfStruct; 1366*0e209d39SAndroid Build Coastguard Worker 1367*0e209d39SAndroid Build Coastguard Worker /* ------ 16 byte alignment boundary ----------- */ 1368*0e209d39SAndroid Build Coastguard Worker 1369*0e209d39SAndroid Build Coastguard Worker 1370*0e209d39SAndroid Build Coastguard Worker /** 1371*0e209d39SAndroid Build Coastguard Worker * (protected) Native index of the first character position following 1372*0e209d39SAndroid Build Coastguard Worker * the current chunk. 1373*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1374*0e209d39SAndroid Build Coastguard Worker */ 1375*0e209d39SAndroid Build Coastguard Worker int64_t chunkNativeLimit; 1376*0e209d39SAndroid Build Coastguard Worker 1377*0e209d39SAndroid Build Coastguard Worker /** 1378*0e209d39SAndroid Build Coastguard Worker * (protected) Size in bytes of the extra space (pExtra). 1379*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1380*0e209d39SAndroid Build Coastguard Worker */ 1381*0e209d39SAndroid Build Coastguard Worker int32_t extraSize; 1382*0e209d39SAndroid Build Coastguard Worker 1383*0e209d39SAndroid Build Coastguard Worker /** 1384*0e209d39SAndroid Build Coastguard Worker * (protected) The highest chunk offset where native indexing and 1385*0e209d39SAndroid Build Coastguard Worker * chunk (UTF-16) indexing correspond. For UTF-16 sources, value 1386*0e209d39SAndroid Build Coastguard Worker * will be equal to chunkLength. 1387*0e209d39SAndroid Build Coastguard Worker * 1388*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1389*0e209d39SAndroid Build Coastguard Worker */ 1390*0e209d39SAndroid Build Coastguard Worker int32_t nativeIndexingLimit; 1391*0e209d39SAndroid Build Coastguard Worker 1392*0e209d39SAndroid Build Coastguard Worker /* ---- 16 byte alignment boundary------ */ 1393*0e209d39SAndroid Build Coastguard Worker 1394*0e209d39SAndroid Build Coastguard Worker /** 1395*0e209d39SAndroid Build Coastguard Worker * (protected) Native index of the first character in the text chunk. 1396*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1397*0e209d39SAndroid Build Coastguard Worker */ 1398*0e209d39SAndroid Build Coastguard Worker int64_t chunkNativeStart; 1399*0e209d39SAndroid Build Coastguard Worker 1400*0e209d39SAndroid Build Coastguard Worker /** 1401*0e209d39SAndroid Build Coastguard Worker * (protected) Current iteration position within the text chunk (UTF-16 buffer). 1402*0e209d39SAndroid Build Coastguard Worker * This is the index to the character that will be returned by utext_next32(). 1403*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1404*0e209d39SAndroid Build Coastguard Worker */ 1405*0e209d39SAndroid Build Coastguard Worker int32_t chunkOffset; 1406*0e209d39SAndroid Build Coastguard Worker 1407*0e209d39SAndroid Build Coastguard Worker /** 1408*0e209d39SAndroid Build Coastguard Worker * (protected) Length the text chunk (UTF-16 buffer), in UChars. 1409*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1410*0e209d39SAndroid Build Coastguard Worker */ 1411*0e209d39SAndroid Build Coastguard Worker int32_t chunkLength; 1412*0e209d39SAndroid Build Coastguard Worker 1413*0e209d39SAndroid Build Coastguard Worker /* ---- 16 byte alignment boundary-- */ 1414*0e209d39SAndroid Build Coastguard Worker 1415*0e209d39SAndroid Build Coastguard Worker 1416*0e209d39SAndroid Build Coastguard Worker /** 1417*0e209d39SAndroid Build Coastguard Worker * (protected) pointer to a chunk of text in UTF-16 format. 1418*0e209d39SAndroid Build Coastguard Worker * May refer either to original storage of the source of the text, or 1419*0e209d39SAndroid Build Coastguard Worker * if conversion was required, to a buffer owned by the UText. 1420*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1421*0e209d39SAndroid Build Coastguard Worker */ 1422*0e209d39SAndroid Build Coastguard Worker const UChar *chunkContents; 1423*0e209d39SAndroid Build Coastguard Worker 1424*0e209d39SAndroid Build Coastguard Worker /** 1425*0e209d39SAndroid Build Coastguard Worker * (public) Pointer to Dispatch table for accessing functions for this UText. 1426*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1427*0e209d39SAndroid Build Coastguard Worker */ 1428*0e209d39SAndroid Build Coastguard Worker const UTextFuncs *pFuncs; 1429*0e209d39SAndroid Build Coastguard Worker 1430*0e209d39SAndroid Build Coastguard Worker /** 1431*0e209d39SAndroid Build Coastguard Worker * (protected) Pointer to additional space requested by the 1432*0e209d39SAndroid Build Coastguard Worker * text provider during the utext_open operation. 1433*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1434*0e209d39SAndroid Build Coastguard Worker */ 1435*0e209d39SAndroid Build Coastguard Worker void *pExtra; 1436*0e209d39SAndroid Build Coastguard Worker 1437*0e209d39SAndroid Build Coastguard Worker /** 1438*0e209d39SAndroid Build Coastguard Worker * (protected) Pointer to string or text-containing object or similar. 1439*0e209d39SAndroid Build Coastguard Worker * This is the source of the text that this UText is wrapping, in a format 1440*0e209d39SAndroid Build Coastguard Worker * that is known to the text provider functions. 1441*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1442*0e209d39SAndroid Build Coastguard Worker */ 1443*0e209d39SAndroid Build Coastguard Worker const void *context; 1444*0e209d39SAndroid Build Coastguard Worker 1445*0e209d39SAndroid Build Coastguard Worker /* --- 16 byte alignment boundary--- */ 1446*0e209d39SAndroid Build Coastguard Worker 1447*0e209d39SAndroid Build Coastguard Worker /** 1448*0e209d39SAndroid Build Coastguard Worker * (protected) Pointer fields available for use by the text provider. 1449*0e209d39SAndroid Build Coastguard Worker * Not used by UText common code. 1450*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1451*0e209d39SAndroid Build Coastguard Worker */ 1452*0e209d39SAndroid Build Coastguard Worker const void *p; 1453*0e209d39SAndroid Build Coastguard Worker /** 1454*0e209d39SAndroid Build Coastguard Worker * (protected) Pointer fields available for use by the text provider. 1455*0e209d39SAndroid Build Coastguard Worker * Not used by UText common code. 1456*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1457*0e209d39SAndroid Build Coastguard Worker */ 1458*0e209d39SAndroid Build Coastguard Worker const void *q; 1459*0e209d39SAndroid Build Coastguard Worker /** 1460*0e209d39SAndroid Build Coastguard Worker * (protected) Pointer fields available for use by the text provider. 1461*0e209d39SAndroid Build Coastguard Worker * Not used by UText common code. 1462*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1463*0e209d39SAndroid Build Coastguard Worker */ 1464*0e209d39SAndroid Build Coastguard Worker const void *r; 1465*0e209d39SAndroid Build Coastguard Worker 1466*0e209d39SAndroid Build Coastguard Worker /** 1467*0e209d39SAndroid Build Coastguard Worker * Private field reserved for future use by the UText framework 1468*0e209d39SAndroid Build Coastguard Worker * itself. This is not to be touched by the text providers. 1469*0e209d39SAndroid Build Coastguard Worker * @internal ICU 3.4 1470*0e209d39SAndroid Build Coastguard Worker */ 1471*0e209d39SAndroid Build Coastguard Worker void *privP; 1472*0e209d39SAndroid Build Coastguard Worker 1473*0e209d39SAndroid Build Coastguard Worker 1474*0e209d39SAndroid Build Coastguard Worker /* --- 16 byte alignment boundary--- */ 1475*0e209d39SAndroid Build Coastguard Worker 1476*0e209d39SAndroid Build Coastguard Worker 1477*0e209d39SAndroid Build Coastguard Worker /** 1478*0e209d39SAndroid Build Coastguard Worker * (protected) Integer field reserved for use by the text provider. 1479*0e209d39SAndroid Build Coastguard Worker * Not used by the UText framework, or by the client (user) of the UText. 1480*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1481*0e209d39SAndroid Build Coastguard Worker */ 1482*0e209d39SAndroid Build Coastguard Worker int64_t a; 1483*0e209d39SAndroid Build Coastguard Worker 1484*0e209d39SAndroid Build Coastguard Worker /** 1485*0e209d39SAndroid Build Coastguard Worker * (protected) Integer field reserved for use by the text provider. 1486*0e209d39SAndroid Build Coastguard Worker * Not used by the UText framework, or by the client (user) of the UText. 1487*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1488*0e209d39SAndroid Build Coastguard Worker */ 1489*0e209d39SAndroid Build Coastguard Worker int32_t b; 1490*0e209d39SAndroid Build Coastguard Worker 1491*0e209d39SAndroid Build Coastguard Worker /** 1492*0e209d39SAndroid Build Coastguard Worker * (protected) Integer field reserved for use by the text provider. 1493*0e209d39SAndroid Build Coastguard Worker * Not used by the UText framework, or by the client (user) of the UText. 1494*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1495*0e209d39SAndroid Build Coastguard Worker */ 1496*0e209d39SAndroid Build Coastguard Worker int32_t c; 1497*0e209d39SAndroid Build Coastguard Worker 1498*0e209d39SAndroid Build Coastguard Worker /* ---- 16 byte alignment boundary---- */ 1499*0e209d39SAndroid Build Coastguard Worker 1500*0e209d39SAndroid Build Coastguard Worker 1501*0e209d39SAndroid Build Coastguard Worker /** 1502*0e209d39SAndroid Build Coastguard Worker * Private field reserved for future use by the UText framework 1503*0e209d39SAndroid Build Coastguard Worker * itself. This is not to be touched by the text providers. 1504*0e209d39SAndroid Build Coastguard Worker * @internal ICU 3.4 1505*0e209d39SAndroid Build Coastguard Worker */ 1506*0e209d39SAndroid Build Coastguard Worker int64_t privA; 1507*0e209d39SAndroid Build Coastguard Worker /** 1508*0e209d39SAndroid Build Coastguard Worker * Private field reserved for future use by the UText framework 1509*0e209d39SAndroid Build Coastguard Worker * itself. This is not to be touched by the text providers. 1510*0e209d39SAndroid Build Coastguard Worker * @internal ICU 3.4 1511*0e209d39SAndroid Build Coastguard Worker */ 1512*0e209d39SAndroid Build Coastguard Worker int32_t privB; 1513*0e209d39SAndroid Build Coastguard Worker /** 1514*0e209d39SAndroid Build Coastguard Worker * Private field reserved for future use by the UText framework 1515*0e209d39SAndroid Build Coastguard Worker * itself. This is not to be touched by the text providers. 1516*0e209d39SAndroid Build Coastguard Worker * @internal ICU 3.4 1517*0e209d39SAndroid Build Coastguard Worker */ 1518*0e209d39SAndroid Build Coastguard Worker int32_t privC; 1519*0e209d39SAndroid Build Coastguard Worker }; 1520*0e209d39SAndroid Build Coastguard Worker 1521*0e209d39SAndroid Build Coastguard Worker 1522*0e209d39SAndroid Build Coastguard Worker /** 1523*0e209d39SAndroid Build Coastguard Worker * Common function for use by Text Provider implementations to allocate and/or initialize 1524*0e209d39SAndroid Build Coastguard Worker * a new UText struct. To be called in the implementation of utext_open() functions. 1525*0e209d39SAndroid Build Coastguard Worker * If the supplied UText parameter is null, a new UText struct will be allocated on the heap. 1526*0e209d39SAndroid Build Coastguard Worker * If the supplied UText is already open, the provider's close function will be called 1527*0e209d39SAndroid Build Coastguard Worker * so that the struct can be reused by the open that is in progress. 1528*0e209d39SAndroid Build Coastguard Worker * 1529*0e209d39SAndroid Build Coastguard Worker * @param ut pointer to a UText struct to be re-used, or null if a new UText 1530*0e209d39SAndroid Build Coastguard Worker * should be allocated. 1531*0e209d39SAndroid Build Coastguard Worker * @param extraSpace The amount of additional space to be allocated as part 1532*0e209d39SAndroid Build Coastguard Worker * of this UText, for use by types of providers that require 1533*0e209d39SAndroid Build Coastguard Worker * additional storage. 1534*0e209d39SAndroid Build Coastguard Worker * @param status Errors are returned here. 1535*0e209d39SAndroid Build Coastguard Worker * @return pointer to the UText, allocated if necessary, with extra space set up if requested. 1536*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.4 1537*0e209d39SAndroid Build Coastguard Worker */ 1538*0e209d39SAndroid Build Coastguard Worker U_CAPI UText * U_EXPORT2 1539*0e209d39SAndroid Build Coastguard Worker utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status); 1540*0e209d39SAndroid Build Coastguard Worker 1541*0e209d39SAndroid Build Coastguard Worker // do not use #ifndef U_HIDE_INTERNAL_API around the following! 1542*0e209d39SAndroid Build Coastguard Worker /** 1543*0e209d39SAndroid Build Coastguard Worker * @internal 1544*0e209d39SAndroid Build Coastguard Worker * Value used to help identify correctly initialized UText structs. 1545*0e209d39SAndroid Build Coastguard Worker * Note: must be publicly visible so that UTEXT_INITIALIZER can access it. 1546*0e209d39SAndroid Build Coastguard Worker */ 1547*0e209d39SAndroid Build Coastguard Worker enum { 1548*0e209d39SAndroid Build Coastguard Worker UTEXT_MAGIC = 0x345ad82c 1549*0e209d39SAndroid Build Coastguard Worker }; 1550*0e209d39SAndroid Build Coastguard Worker 1551*0e209d39SAndroid Build Coastguard Worker /** 1552*0e209d39SAndroid Build Coastguard Worker * initializer to be used with local (stack) instances of a UText 1553*0e209d39SAndroid Build Coastguard Worker * struct. UText structs must be initialized before passing 1554*0e209d39SAndroid Build Coastguard Worker * them to one of the utext_open functions. 1555*0e209d39SAndroid Build Coastguard Worker * 1556*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6 1557*0e209d39SAndroid Build Coastguard Worker */ 1558*0e209d39SAndroid Build Coastguard Worker #define UTEXT_INITIALIZER { \ 1559*0e209d39SAndroid Build Coastguard Worker UTEXT_MAGIC, /* magic */ \ 1560*0e209d39SAndroid Build Coastguard Worker 0, /* flags */ \ 1561*0e209d39SAndroid Build Coastguard Worker 0, /* providerProps */ \ 1562*0e209d39SAndroid Build Coastguard Worker sizeof(UText), /* sizeOfStruct */ \ 1563*0e209d39SAndroid Build Coastguard Worker 0, /* chunkNativeLimit */ \ 1564*0e209d39SAndroid Build Coastguard Worker 0, /* extraSize */ \ 1565*0e209d39SAndroid Build Coastguard Worker 0, /* nativeIndexingLimit */ \ 1566*0e209d39SAndroid Build Coastguard Worker 0, /* chunkNativeStart */ \ 1567*0e209d39SAndroid Build Coastguard Worker 0, /* chunkOffset */ \ 1568*0e209d39SAndroid Build Coastguard Worker 0, /* chunkLength */ \ 1569*0e209d39SAndroid Build Coastguard Worker NULL, /* chunkContents */ \ 1570*0e209d39SAndroid Build Coastguard Worker NULL, /* pFuncs */ \ 1571*0e209d39SAndroid Build Coastguard Worker NULL, /* pExtra */ \ 1572*0e209d39SAndroid Build Coastguard Worker NULL, /* context */ \ 1573*0e209d39SAndroid Build Coastguard Worker NULL, NULL, NULL, /* p, q, r */ \ 1574*0e209d39SAndroid Build Coastguard Worker NULL, /* privP */ \ 1575*0e209d39SAndroid Build Coastguard Worker 0, 0, 0, /* a, b, c */ \ 1576*0e209d39SAndroid Build Coastguard Worker 0, 0, 0 /* privA,B,C, */ \ 1577*0e209d39SAndroid Build Coastguard Worker } 1578*0e209d39SAndroid Build Coastguard Worker 1579*0e209d39SAndroid Build Coastguard Worker 1580*0e209d39SAndroid Build Coastguard Worker U_CDECL_END 1581*0e209d39SAndroid Build Coastguard Worker 1582*0e209d39SAndroid Build Coastguard Worker 1583*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API 1584*0e209d39SAndroid Build Coastguard Worker 1585*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN 1586*0e209d39SAndroid Build Coastguard Worker 1587*0e209d39SAndroid Build Coastguard Worker /** 1588*0e209d39SAndroid Build Coastguard Worker * \class LocalUTextPointer 1589*0e209d39SAndroid Build Coastguard Worker * "Smart pointer" class, closes a UText via utext_close(). 1590*0e209d39SAndroid Build Coastguard Worker * For most methods see the LocalPointerBase base class. 1591*0e209d39SAndroid Build Coastguard Worker * 1592*0e209d39SAndroid Build Coastguard Worker * @see LocalPointerBase 1593*0e209d39SAndroid Build Coastguard Worker * @see LocalPointer 1594*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4 1595*0e209d39SAndroid Build Coastguard Worker */ 1596*0e209d39SAndroid Build Coastguard Worker U_DEFINE_LOCAL_OPEN_POINTER(LocalUTextPointer, UText, utext_close); 1597*0e209d39SAndroid Build Coastguard Worker 1598*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END 1599*0e209d39SAndroid Build Coastguard Worker 1600*0e209d39SAndroid Build Coastguard Worker #endif 1601*0e209d39SAndroid Build Coastguard Worker 1602*0e209d39SAndroid Build Coastguard Worker 1603*0e209d39SAndroid Build Coastguard Worker #endif 1604