xref: /aosp_15_r20/external/icu/libicu/ndk_headers/unicode/utext.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
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  * @addtogroup icu4c ICU4C
24*0e209d39SAndroid Build Coastguard Worker  * @{
25*0e209d39SAndroid Build Coastguard Worker  * \file
26*0e209d39SAndroid Build Coastguard Worker  * \brief C API: Abstract Unicode Text API
27*0e209d39SAndroid Build Coastguard Worker  *
28*0e209d39SAndroid Build Coastguard Worker  * The Text Access API provides a means to allow text that is stored in alternative
29*0e209d39SAndroid Build Coastguard Worker  * formats to work with ICU services.  ICU normally operates on text that is
30*0e209d39SAndroid Build Coastguard Worker  * stored in UTF-16 format, in (UChar *) arrays for the C APIs or as type
31*0e209d39SAndroid Build Coastguard Worker  * UnicodeString for C++ APIs.
32*0e209d39SAndroid Build Coastguard Worker  *
33*0e209d39SAndroid Build Coastguard Worker  * ICU Text Access allows other formats, such as UTF-8 or non-contiguous
34*0e209d39SAndroid Build Coastguard Worker  * UTF-16 strings, to be placed in a UText wrapper and then passed to ICU services.
35*0e209d39SAndroid Build Coastguard Worker  *
36*0e209d39SAndroid Build Coastguard Worker  * There are three general classes of usage for UText:
37*0e209d39SAndroid Build Coastguard Worker  *
38*0e209d39SAndroid Build Coastguard Worker  *     Application Level Use.  This is the simplest usage - applications would
39*0e209d39SAndroid Build Coastguard Worker  *     use one of the utext_open() functions on their input text, and pass
40*0e209d39SAndroid Build Coastguard Worker  *     the resulting UText to the desired ICU service.
41*0e209d39SAndroid Build Coastguard Worker  *
42*0e209d39SAndroid Build Coastguard Worker  *     Second is usage in ICU Services, such as break iteration, that will need to
43*0e209d39SAndroid Build Coastguard Worker  *     operate on input presented to them as a UText.  These implementations
44*0e209d39SAndroid Build Coastguard Worker  *     will need to use the iteration and related UText functions to gain
45*0e209d39SAndroid Build Coastguard Worker  *     access to the actual text.
46*0e209d39SAndroid Build Coastguard Worker  *
47*0e209d39SAndroid Build Coastguard Worker  *     The third class of UText users are "text providers."  These are the
48*0e209d39SAndroid Build Coastguard Worker  *     UText implementations for the various text storage formats.  An application
49*0e209d39SAndroid Build Coastguard Worker  *     or system with a unique text storage format can implement a set of
50*0e209d39SAndroid Build Coastguard Worker  *     UText provider functions for that format, which will then allow
51*0e209d39SAndroid Build Coastguard Worker  *     ICU services to operate on that format.
52*0e209d39SAndroid Build Coastguard Worker  *
53*0e209d39SAndroid Build Coastguard Worker  *
54*0e209d39SAndroid Build Coastguard Worker  * <em>Iterating over text</em>
55*0e209d39SAndroid Build Coastguard Worker  *
56*0e209d39SAndroid Build Coastguard Worker  * Here is sample code for a forward iteration over the contents of a UText
57*0e209d39SAndroid Build Coastguard Worker  *
58*0e209d39SAndroid Build Coastguard Worker  * \code
59*0e209d39SAndroid Build Coastguard Worker  *    UChar32  c;
60*0e209d39SAndroid Build Coastguard Worker  *    UText    *ut = whatever();
61*0e209d39SAndroid Build Coastguard Worker  *
62*0e209d39SAndroid Build Coastguard Worker  *    for (c=utext_next32From(ut, 0); c>=0; c=utext_next32(ut)) {
63*0e209d39SAndroid Build Coastguard Worker  *       // do whatever with the codepoint c here.
64*0e209d39SAndroid Build Coastguard Worker  *    }
65*0e209d39SAndroid Build Coastguard Worker  * \endcode
66*0e209d39SAndroid Build Coastguard Worker  *
67*0e209d39SAndroid Build Coastguard Worker  * And here is similar code to iterate in the reverse direction, from the end
68*0e209d39SAndroid Build Coastguard Worker  * of the text towards the beginning.
69*0e209d39SAndroid Build Coastguard Worker  *
70*0e209d39SAndroid Build Coastguard Worker  * \code
71*0e209d39SAndroid Build Coastguard Worker  *    UChar32  c;
72*0e209d39SAndroid Build Coastguard Worker  *    UText    *ut = whatever();
73*0e209d39SAndroid Build Coastguard Worker  *    int      textLength = utext_nativeLength(ut);
74*0e209d39SAndroid Build Coastguard Worker  *    for (c=utext_previous32From(ut, textLength); c>=0; c=utext_previous32(ut)) {
75*0e209d39SAndroid Build Coastguard Worker  *       // do whatever with the codepoint c here.
76*0e209d39SAndroid Build Coastguard Worker  *    }
77*0e209d39SAndroid Build Coastguard Worker  * \endcode
78*0e209d39SAndroid Build Coastguard Worker  *
79*0e209d39SAndroid Build Coastguard Worker  * <em>Characters and Indexing</em>
80*0e209d39SAndroid Build Coastguard Worker  *
81*0e209d39SAndroid Build Coastguard Worker  * Indexing into text by UText functions is nearly always in terms of the native
82*0e209d39SAndroid Build Coastguard Worker  * indexing of the underlying text storage.  The storage format could be UTF-8
83*0e209d39SAndroid Build Coastguard Worker  * or UTF-32, for example.  When coding to the UText access API, no assumptions
84*0e209d39SAndroid Build Coastguard Worker  * can be made regarding the size of characters, or how far an index
85*0e209d39SAndroid Build Coastguard Worker  * may move when iterating between characters.
86*0e209d39SAndroid Build Coastguard Worker  *
87*0e209d39SAndroid Build Coastguard Worker  * All indices supplied to UText functions are pinned to the length of the
88*0e209d39SAndroid Build Coastguard Worker  * text.  An out-of-bounds index is not considered to be an error, but is
89*0e209d39SAndroid Build Coastguard Worker  * adjusted to be in the range  0 <= index <= length of input text.
90*0e209d39SAndroid Build Coastguard Worker  *
91*0e209d39SAndroid Build Coastguard Worker  *
92*0e209d39SAndroid Build Coastguard Worker  * When an index position is returned from a UText function, it will be
93*0e209d39SAndroid Build Coastguard Worker  * a native index to the underlying text.  In the case of multi-unit characters,
94*0e209d39SAndroid Build Coastguard Worker  * it will  always refer to the first position of the character,
95*0e209d39SAndroid Build Coastguard Worker  * never to the interior.  This is essentially the same thing as saying that
96*0e209d39SAndroid Build Coastguard Worker  * a returned index will always point to a boundary between characters.
97*0e209d39SAndroid Build Coastguard Worker  *
98*0e209d39SAndroid Build Coastguard Worker  * When a native index is supplied to a UText function, all indices that
99*0e209d39SAndroid Build Coastguard Worker  * refer to any part of a multi-unit character representation are considered
100*0e209d39SAndroid Build Coastguard Worker  * to be equivalent.  In the case of multi-unit characters, an incoming index
101*0e209d39SAndroid Build Coastguard Worker  * will be logically normalized to refer to the start of the character.
102*0e209d39SAndroid Build Coastguard Worker  *
103*0e209d39SAndroid Build Coastguard Worker  * It is possible to test whether a native index is on a code point boundary
104*0e209d39SAndroid Build Coastguard Worker  * by doing a utext_setNativeIndex() followed by a utext_getNativeIndex().
105*0e209d39SAndroid Build Coastguard Worker  * If the index is returned unchanged, it was on a code point boundary.  If
106*0e209d39SAndroid Build Coastguard Worker  * an adjusted index is returned, the original index referred to the
107*0e209d39SAndroid Build Coastguard Worker  * interior of a character.
108*0e209d39SAndroid Build Coastguard Worker  *
109*0e209d39SAndroid Build Coastguard Worker  * <em>Conventions for calling UText functions</em>
110*0e209d39SAndroid Build Coastguard Worker  *
111*0e209d39SAndroid Build Coastguard Worker  * Most UText access functions have as their first parameter a (UText *) pointer,
112*0e209d39SAndroid Build Coastguard Worker  * which specifies the UText to be used.  Unless otherwise noted, the
113*0e209d39SAndroid Build Coastguard Worker  * pointer must refer to a valid, open UText.  Attempting to
114*0e209d39SAndroid Build Coastguard Worker  * use a closed UText or passing a NULL pointer is a programming error and
115*0e209d39SAndroid Build Coastguard Worker  * will produce undefined results or NULL pointer exceptions.
116*0e209d39SAndroid Build Coastguard Worker  *
117*0e209d39SAndroid Build Coastguard Worker  * The UText_Open family of functions can either open an existing (closed)
118*0e209d39SAndroid Build Coastguard Worker  * UText, or heap allocate a new UText.  Here is sample code for creating
119*0e209d39SAndroid Build Coastguard Worker  * a stack-allocated UText.
120*0e209d39SAndroid Build Coastguard Worker  *
121*0e209d39SAndroid Build Coastguard Worker  * \code
122*0e209d39SAndroid Build Coastguard Worker  *    char     *s = whatever();  // A utf-8 string
123*0e209d39SAndroid Build Coastguard Worker  *    U_ErrorCode status = U_ZERO_ERROR;
124*0e209d39SAndroid Build Coastguard Worker  *    UText    ut = UTEXT_INITIALIZER;
125*0e209d39SAndroid Build Coastguard Worker  *    utext_openUTF8(ut, s, -1, &status);
126*0e209d39SAndroid Build Coastguard Worker  *    if (U_FAILURE(status)) {
127*0e209d39SAndroid Build Coastguard Worker  *        // error handling
128*0e209d39SAndroid Build Coastguard Worker  *    } else {
129*0e209d39SAndroid Build Coastguard Worker  *        // work with the UText
130*0e209d39SAndroid Build Coastguard Worker  *    }
131*0e209d39SAndroid Build Coastguard Worker  * \endcode
132*0e209d39SAndroid Build Coastguard Worker  *
133*0e209d39SAndroid Build Coastguard Worker  * Any existing UText passed to an open function _must_ have been initialized,
134*0e209d39SAndroid Build Coastguard Worker  * either by the UTEXT_INITIALIZER, or by having been originally heap-allocated
135*0e209d39SAndroid Build Coastguard Worker  * by an open function.  Passing NULL will cause the open function to
136*0e209d39SAndroid Build Coastguard Worker  * heap-allocate and fully initialize a new UText.
137*0e209d39SAndroid Build Coastguard Worker  *
138*0e209d39SAndroid Build Coastguard Worker  */
139*0e209d39SAndroid Build Coastguard Worker 
140*0e209d39SAndroid Build Coastguard Worker 
141*0e209d39SAndroid Build Coastguard Worker 
142*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
143*0e209d39SAndroid Build Coastguard Worker #include "unicode/uchar.h"
144*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
145*0e209d39SAndroid Build Coastguard Worker #include "unicode/localpointer.h"
146*0e209d39SAndroid Build Coastguard Worker #include "unicode/rep.h"
147*0e209d39SAndroid Build Coastguard Worker #include "unicode/unistr.h"
148*0e209d39SAndroid Build Coastguard Worker #include "unicode/chariter.h"
149*0e209d39SAndroid Build Coastguard Worker #endif
150*0e209d39SAndroid Build Coastguard Worker 
151*0e209d39SAndroid Build Coastguard Worker 
152*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN
153*0e209d39SAndroid Build Coastguard Worker 
154*0e209d39SAndroid Build Coastguard Worker struct UText;
155*0e209d39SAndroid Build Coastguard Worker typedef struct UText UText; /**< C typedef for struct UText. \xrefitem stable "Stable" "Stable List" ICU 3.6 */
156*0e209d39SAndroid Build Coastguard Worker 
157*0e209d39SAndroid Build Coastguard Worker 
158*0e209d39SAndroid Build Coastguard Worker /***************************************************************************************
159*0e209d39SAndroid Build Coastguard Worker  *
160*0e209d39SAndroid Build Coastguard Worker  *   C Functions for creating UText wrappers around various kinds of text strings.
161*0e209d39SAndroid Build Coastguard Worker  *
162*0e209d39SAndroid Build Coastguard Worker  ****************************************************************************************/
163*0e209d39SAndroid Build Coastguard Worker 
164*0e209d39SAndroid Build Coastguard Worker 
165*0e209d39SAndroid Build Coastguard Worker /**
166*0e209d39SAndroid Build Coastguard Worker   * Close function for UText instances.
167*0e209d39SAndroid Build Coastguard Worker   * Cleans up, releases any resources being held by an open UText.
168*0e209d39SAndroid Build Coastguard Worker   * <p>
169*0e209d39SAndroid Build Coastguard Worker   *   If the UText was originally allocated by one of the utext_open functions,
170*0e209d39SAndroid Build Coastguard Worker   *   the storage associated with the utext will also be freed.
171*0e209d39SAndroid Build Coastguard Worker   *   If the UText storage originated with the application, as it would with
172*0e209d39SAndroid Build Coastguard Worker   *   a local or static instance, the storage will not be deleted.
173*0e209d39SAndroid Build Coastguard Worker   *
174*0e209d39SAndroid Build Coastguard Worker   *   An open UText can be reset to refer to new string by using one of the utext_open()
175*0e209d39SAndroid Build Coastguard Worker   *   functions without first closing the UText.
176*0e209d39SAndroid Build Coastguard Worker   *
177*0e209d39SAndroid Build Coastguard Worker   * @param ut  The UText to be closed.
178*0e209d39SAndroid Build Coastguard Worker   * @return    NULL if the UText struct was deleted by the close.  If the UText struct
179*0e209d39SAndroid Build Coastguard Worker   *            was originally provided by the caller to the open function, it is
180*0e209d39SAndroid Build Coastguard Worker   *            returned by this function, and may be safely used again in
181*0e209d39SAndroid Build Coastguard Worker   *            a subsequent utext_open.
182*0e209d39SAndroid Build Coastguard Worker   *
183*0e209d39SAndroid Build Coastguard Worker   * \xrefitem stable "Stable" "Stable List" ICU 3.4
184*0e209d39SAndroid Build Coastguard Worker   */
185*0e209d39SAndroid Build Coastguard Worker U_CAPI UText * U_EXPORT2
186*0e209d39SAndroid Build Coastguard Worker utext_close(UText *ut) __INTRODUCED_IN(31);
187*0e209d39SAndroid Build Coastguard Worker 
188*0e209d39SAndroid Build Coastguard Worker 
189*0e209d39SAndroid Build Coastguard Worker 
190*0e209d39SAndroid Build Coastguard Worker /**
191*0e209d39SAndroid Build Coastguard Worker  * Open a read-only UText implementation for UTF-8 strings.
192*0e209d39SAndroid Build Coastguard Worker  *
193*0e209d39SAndroid Build Coastguard Worker  * \htmlonly
194*0e209d39SAndroid Build Coastguard Worker  * Any invalid UTF-8 in the input will be handled in this way:
195*0e209d39SAndroid Build Coastguard Worker  * a sequence of bytes that has the form of a truncated, but otherwise valid,
196*0e209d39SAndroid Build Coastguard Worker  * UTF-8 sequence will be replaced by a single unicode replacement character, \uFFFD.
197*0e209d39SAndroid Build Coastguard Worker  * Any other illegal bytes will each be replaced by a \uFFFD.
198*0e209d39SAndroid Build Coastguard Worker  * \endhtmlonly
199*0e209d39SAndroid Build Coastguard Worker  *
200*0e209d39SAndroid Build Coastguard Worker  * @param ut     Pointer to a UText struct.  If NULL, a new UText will be created.
201*0e209d39SAndroid Build Coastguard Worker  *               If non-NULL, must refer to an initialized UText struct, which will then
202*0e209d39SAndroid Build Coastguard Worker  *               be reset to reference the specified UTF-8 string.
203*0e209d39SAndroid Build Coastguard Worker  * @param s      A UTF-8 string.  Must not be NULL.
204*0e209d39SAndroid Build Coastguard Worker  * @param length The length of the UTF-8 string in bytes, or -1 if the string is
205*0e209d39SAndroid Build Coastguard Worker  *               zero terminated.
206*0e209d39SAndroid Build Coastguard Worker  * @param status Errors are returned here.
207*0e209d39SAndroid Build Coastguard Worker  * @return       A pointer to the UText.  If a pre-allocated UText was provided, it
208*0e209d39SAndroid Build Coastguard Worker  *               will always be used and returned.
209*0e209d39SAndroid Build Coastguard Worker  * \xrefitem stable "Stable" "Stable List" ICU 3.4
210*0e209d39SAndroid Build Coastguard Worker  */
211*0e209d39SAndroid Build Coastguard Worker U_CAPI UText * U_EXPORT2
212*0e209d39SAndroid Build Coastguard Worker utext_openUTF8(UText *ut, const char *s, int64_t length, UErrorCode *status) __INTRODUCED_IN(31);
213*0e209d39SAndroid Build Coastguard Worker 
214*0e209d39SAndroid Build Coastguard Worker 
215*0e209d39SAndroid Build Coastguard Worker 
216*0e209d39SAndroid Build Coastguard Worker 
217*0e209d39SAndroid Build Coastguard Worker /**
218*0e209d39SAndroid Build Coastguard Worker  * Open a read-only UText for UChar * string.
219*0e209d39SAndroid Build Coastguard Worker  *
220*0e209d39SAndroid Build Coastguard Worker  * @param ut     Pointer to a UText struct.  If NULL, a new UText will be created.
221*0e209d39SAndroid Build Coastguard Worker  *               If non-NULL, must refer to an initialized UText struct, which will then
222*0e209d39SAndroid Build Coastguard Worker  *               be reset to reference the specified UChar string.
223*0e209d39SAndroid Build Coastguard Worker  * @param s      A UChar (UTF-16) string
224*0e209d39SAndroid Build Coastguard Worker  * @param length The number of UChars in the input string, or -1 if the string is
225*0e209d39SAndroid Build Coastguard Worker  *               zero terminated.
226*0e209d39SAndroid Build Coastguard Worker  * @param status Errors are returned here.
227*0e209d39SAndroid Build Coastguard Worker  * @return       A pointer to the UText.  If a pre-allocated UText was provided, it
228*0e209d39SAndroid Build Coastguard Worker  *               will always be used and returned.
229*0e209d39SAndroid Build Coastguard Worker  * \xrefitem stable "Stable" "Stable List" ICU 3.4
230*0e209d39SAndroid Build Coastguard Worker  */
231*0e209d39SAndroid Build Coastguard Worker U_CAPI UText * U_EXPORT2
232*0e209d39SAndroid Build Coastguard Worker utext_openUChars(UText *ut, const UChar *s, int64_t length, UErrorCode *status) __INTRODUCED_IN(31);
233*0e209d39SAndroid Build Coastguard Worker 
234*0e209d39SAndroid Build Coastguard Worker 
235*0e209d39SAndroid Build Coastguard Worker 
236*0e209d39SAndroid Build Coastguard Worker 
237*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
238*0e209d39SAndroid Build Coastguard Worker 
239*0e209d39SAndroid Build Coastguard Worker 
240*0e209d39SAndroid Build Coastguard Worker 
241*0e209d39SAndroid Build Coastguard Worker 
242*0e209d39SAndroid Build Coastguard Worker 
243*0e209d39SAndroid Build Coastguard Worker 
244*0e209d39SAndroid Build Coastguard Worker 
245*0e209d39SAndroid Build Coastguard Worker 
246*0e209d39SAndroid Build Coastguard Worker 
247*0e209d39SAndroid Build Coastguard Worker 
248*0e209d39SAndroid Build Coastguard Worker #endif
249*0e209d39SAndroid Build Coastguard Worker 
250*0e209d39SAndroid Build Coastguard Worker 
251*0e209d39SAndroid Build Coastguard Worker /**
252*0e209d39SAndroid Build Coastguard Worker   *  Clone a UText.  This is much like opening a UText where the source text is itself
253*0e209d39SAndroid Build Coastguard Worker   *  another UText.
254*0e209d39SAndroid Build Coastguard Worker   *
255*0e209d39SAndroid Build Coastguard Worker   *  A deep clone will copy both the UText data structures and the underlying text.
256*0e209d39SAndroid Build Coastguard Worker   *  The original and cloned UText will operate completely independently; modifications
257*0e209d39SAndroid Build Coastguard Worker   *  made to the text in one will not affect the other.  Text providers are not
258*0e209d39SAndroid Build Coastguard Worker   *  required to support deep clones.  The user of clone() must check the status return
259*0e209d39SAndroid Build Coastguard Worker   *  and be prepared to handle failures.
260*0e209d39SAndroid Build Coastguard Worker   *
261*0e209d39SAndroid Build Coastguard Worker   *  The standard UText implementations for UTF8, UChar *, UnicodeString and
262*0e209d39SAndroid Build Coastguard Worker   *  Replaceable all support deep cloning.
263*0e209d39SAndroid Build Coastguard Worker   *
264*0e209d39SAndroid Build Coastguard Worker   *  The UText returned from a deep clone will be writable, assuming that the text
265*0e209d39SAndroid Build Coastguard Worker   *  provider is able to support writing, even if the source UText had been made
266*0e209d39SAndroid Build Coastguard Worker   *  non-writable by means of UText_freeze().
267*0e209d39SAndroid Build Coastguard Worker   *
268*0e209d39SAndroid Build Coastguard Worker   *  A shallow clone replicates only the UText data structures; it does not make
269*0e209d39SAndroid Build Coastguard Worker   *  a copy of the underlying text.  Shallow clones can be used as an efficient way to
270*0e209d39SAndroid Build Coastguard Worker   *  have multiple iterators active in a single text string that is not being
271*0e209d39SAndroid Build Coastguard Worker   *  modified.
272*0e209d39SAndroid Build Coastguard Worker   *
273*0e209d39SAndroid Build Coastguard Worker   *  A shallow clone operation will not fail, barring truly exceptional conditions such
274*0e209d39SAndroid Build Coastguard Worker   *  as memory allocation failures.
275*0e209d39SAndroid Build Coastguard Worker   *
276*0e209d39SAndroid Build Coastguard Worker   *  Shallow UText clones should be avoided if the UText functions that modify the
277*0e209d39SAndroid Build Coastguard Worker   *  text are expected to be used, either on the original or the cloned UText.
278*0e209d39SAndroid Build Coastguard Worker   *  Any such modifications  can cause unpredictable behavior.  Read Only
279*0e209d39SAndroid Build Coastguard Worker   *  shallow clones provide some protection against errors of this type by
280*0e209d39SAndroid Build Coastguard Worker   *  disabling text modification via the cloned UText.
281*0e209d39SAndroid Build Coastguard Worker   *
282*0e209d39SAndroid Build Coastguard Worker   *  A shallow clone made with the readOnly parameter == false will preserve the
283*0e209d39SAndroid Build Coastguard Worker   *  utext_isWritable() state of the source object.  Note, however, that
284*0e209d39SAndroid Build Coastguard Worker   *  write operations must be avoided while more than one UText exists that refer
285*0e209d39SAndroid Build Coastguard Worker   *  to the same underlying text.
286*0e209d39SAndroid Build Coastguard Worker   *
287*0e209d39SAndroid Build Coastguard Worker   *  A UText and its clone may be safely concurrently accessed by separate threads.
288*0e209d39SAndroid Build Coastguard Worker   *  This is true for read access only with shallow clones, and for both read and
289*0e209d39SAndroid Build Coastguard Worker   *  write access with deep clones.
290*0e209d39SAndroid Build Coastguard Worker   *  It is the responsibility of the Text Provider to ensure that this thread safety
291*0e209d39SAndroid Build Coastguard Worker   *  constraint is met.
292*0e209d39SAndroid Build Coastguard Worker   *
293*0e209d39SAndroid Build Coastguard Worker   *  @param dest   A UText struct to be filled in with the result of the clone operation,
294*0e209d39SAndroid Build Coastguard Worker   *                or NULL if the clone function should heap-allocate a new UText struct.
295*0e209d39SAndroid Build Coastguard Worker   *                If non-NULL, must refer to an already existing UText, which will then
296*0e209d39SAndroid Build Coastguard Worker   *                be reset to become the clone.
297*0e209d39SAndroid Build Coastguard Worker   *  @param src    The UText to be cloned.
298*0e209d39SAndroid Build Coastguard Worker   *  @param deep   true to request a deep clone, false for a shallow clone.
299*0e209d39SAndroid Build Coastguard Worker   *  @param readOnly true to request that the cloned UText have read only access to the
300*0e209d39SAndroid Build Coastguard Worker   *                underlying text.
301*0e209d39SAndroid Build Coastguard Worker 
302*0e209d39SAndroid Build Coastguard Worker   *  @param status Errors are returned here.  For deep clones, U_UNSUPPORTED_ERROR
303*0e209d39SAndroid Build Coastguard Worker   *                will be returned if the text provider is unable to clone the
304*0e209d39SAndroid Build Coastguard Worker   *                original text.
305*0e209d39SAndroid Build Coastguard Worker   *  @return       The newly created clone, or NULL if the clone operation failed.
306*0e209d39SAndroid Build Coastguard Worker   *  \xrefitem stable "Stable" "Stable List" ICU 3.4
307*0e209d39SAndroid Build Coastguard Worker   */
308*0e209d39SAndroid Build Coastguard Worker U_CAPI UText * U_EXPORT2
309*0e209d39SAndroid Build Coastguard Worker utext_clone(UText *dest, const UText *src, UBool deep, UBool readOnly, UErrorCode *status) __INTRODUCED_IN(31);
310*0e209d39SAndroid Build Coastguard Worker 
311*0e209d39SAndroid Build Coastguard Worker 
312*0e209d39SAndroid Build Coastguard Worker 
313*0e209d39SAndroid Build Coastguard Worker 
314*0e209d39SAndroid Build Coastguard Worker /**
315*0e209d39SAndroid Build Coastguard Worker   *  Compare two UText objects for equality.
316*0e209d39SAndroid Build Coastguard Worker   *  UTexts are equal if they are iterating over the same text, and
317*0e209d39SAndroid Build Coastguard Worker   *    have the same iteration position within the text.
318*0e209d39SAndroid Build Coastguard Worker   *    If either or both of the parameters are NULL, the comparison is false.
319*0e209d39SAndroid Build Coastguard Worker   *
320*0e209d39SAndroid Build Coastguard Worker   *  @param a   The first of the two UTexts to compare.
321*0e209d39SAndroid Build Coastguard Worker   *  @param b   The other UText to be compared.
322*0e209d39SAndroid Build Coastguard Worker   *  @return    true if the two UTexts are equal.
323*0e209d39SAndroid Build Coastguard Worker   *  \xrefitem stable "Stable" "Stable List" ICU 3.6
324*0e209d39SAndroid Build Coastguard Worker   */
325*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
326*0e209d39SAndroid Build Coastguard Worker utext_equals(const UText *a, const UText *b) __INTRODUCED_IN(31);
327*0e209d39SAndroid Build Coastguard Worker 
328*0e209d39SAndroid Build Coastguard Worker 
329*0e209d39SAndroid Build Coastguard Worker 
330*0e209d39SAndroid Build Coastguard Worker 
331*0e209d39SAndroid Build Coastguard Worker /*****************************************************************************
332*0e209d39SAndroid Build Coastguard Worker  *
333*0e209d39SAndroid Build Coastguard Worker  *   Functions to work with the text represented by a UText wrapper
334*0e209d39SAndroid Build Coastguard Worker  *
335*0e209d39SAndroid Build Coastguard Worker  *****************************************************************************/
336*0e209d39SAndroid Build Coastguard Worker 
337*0e209d39SAndroid Build Coastguard Worker /**
338*0e209d39SAndroid Build Coastguard Worker   * Get the length of the text.  Depending on the characteristics
339*0e209d39SAndroid Build Coastguard Worker   * of the underlying text representation, this may be expensive.
340*0e209d39SAndroid Build Coastguard Worker   * @see  utext_isLengthExpensive()
341*0e209d39SAndroid Build Coastguard Worker   *
342*0e209d39SAndroid Build Coastguard Worker   *
343*0e209d39SAndroid Build Coastguard Worker   * @param ut  the text to be accessed.
344*0e209d39SAndroid Build Coastguard Worker   * @return the length of the text, expressed in native units.
345*0e209d39SAndroid Build Coastguard Worker   *
346*0e209d39SAndroid Build Coastguard Worker   * \xrefitem stable "Stable" "Stable List" ICU 3.4
347*0e209d39SAndroid Build Coastguard Worker   */
348*0e209d39SAndroid Build Coastguard Worker U_CAPI int64_t U_EXPORT2
349*0e209d39SAndroid Build Coastguard Worker utext_nativeLength(UText *ut) __INTRODUCED_IN(31);
350*0e209d39SAndroid Build Coastguard Worker 
351*0e209d39SAndroid Build Coastguard Worker 
352*0e209d39SAndroid Build Coastguard Worker 
353*0e209d39SAndroid Build Coastguard Worker 
354*0e209d39SAndroid Build Coastguard Worker 
355*0e209d39SAndroid Build Coastguard Worker /**
356*0e209d39SAndroid Build Coastguard Worker  * Returns the code point at the requested index,
357*0e209d39SAndroid Build Coastguard Worker  * or U_SENTINEL (-1) if it is out of bounds.
358*0e209d39SAndroid Build Coastguard Worker  *
359*0e209d39SAndroid Build Coastguard Worker  * If the specified index points to the interior of a multi-unit
360*0e209d39SAndroid Build Coastguard Worker  * character - one of the trail bytes of a UTF-8 sequence, for example -
361*0e209d39SAndroid Build Coastguard Worker  * the complete code point will be returned.
362*0e209d39SAndroid Build Coastguard Worker  *
363*0e209d39SAndroid Build Coastguard Worker  * The iteration position will be set to the start of the returned code point.
364*0e209d39SAndroid Build Coastguard Worker  *
365*0e209d39SAndroid Build Coastguard Worker  * This function is roughly equivalent to the sequence
366*0e209d39SAndroid Build Coastguard Worker  *    utext_setNativeIndex(index);
367*0e209d39SAndroid Build Coastguard Worker  *    utext_current32();
368*0e209d39SAndroid Build Coastguard Worker  * (There is a subtle difference if the index is out of bounds by being less than zero -
369*0e209d39SAndroid Build Coastguard Worker  * utext_setNativeIndex(negative value) sets the index to zero, after which utext_current()
370*0e209d39SAndroid Build Coastguard Worker  * will return the char at zero.  utext_char32At(negative index), on the other hand, will
371*0e209d39SAndroid Build Coastguard Worker  * return the U_SENTINEL value of -1.)
372*0e209d39SAndroid Build Coastguard Worker  *
373*0e209d39SAndroid Build Coastguard Worker  * @param ut the text to be accessed
374*0e209d39SAndroid Build Coastguard Worker  * @param nativeIndex the native index of the character to be accessed.  If the index points
375*0e209d39SAndroid Build Coastguard Worker  *        to other than the first unit of a multi-unit character, it will be adjusted
376*0e209d39SAndroid Build Coastguard Worker  *        to the start of the character.
377*0e209d39SAndroid Build Coastguard Worker  * @return the code point at the specified index.
378*0e209d39SAndroid Build Coastguard Worker  * \xrefitem stable "Stable" "Stable List" ICU 3.4
379*0e209d39SAndroid Build Coastguard Worker  */
380*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2
381*0e209d39SAndroid Build Coastguard Worker utext_char32At(UText *ut, int64_t nativeIndex) __INTRODUCED_IN(31);
382*0e209d39SAndroid Build Coastguard Worker 
383*0e209d39SAndroid Build Coastguard Worker 
384*0e209d39SAndroid Build Coastguard Worker 
385*0e209d39SAndroid Build Coastguard Worker 
386*0e209d39SAndroid Build Coastguard Worker /**
387*0e209d39SAndroid Build Coastguard Worker  *
388*0e209d39SAndroid Build Coastguard Worker  * Get the code point at the current iteration position,
389*0e209d39SAndroid Build Coastguard Worker  * or U_SENTINEL (-1) if the iteration has reached the end of
390*0e209d39SAndroid Build Coastguard Worker  * the input text.
391*0e209d39SAndroid Build Coastguard Worker  *
392*0e209d39SAndroid Build Coastguard Worker  * @param ut the text to be accessed.
393*0e209d39SAndroid Build Coastguard Worker  * @return the Unicode code point at the current iterator position.
394*0e209d39SAndroid Build Coastguard Worker  * \xrefitem stable "Stable" "Stable List" ICU 3.4
395*0e209d39SAndroid Build Coastguard Worker  */
396*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2
397*0e209d39SAndroid Build Coastguard Worker utext_current32(UText *ut) __INTRODUCED_IN(31);
398*0e209d39SAndroid Build Coastguard Worker 
399*0e209d39SAndroid Build Coastguard Worker 
400*0e209d39SAndroid Build Coastguard Worker 
401*0e209d39SAndroid Build Coastguard Worker 
402*0e209d39SAndroid Build Coastguard Worker /**
403*0e209d39SAndroid Build Coastguard Worker  * Get the code point at the current iteration position of the UText, and
404*0e209d39SAndroid Build Coastguard Worker  * advance the position to the first index following the character.
405*0e209d39SAndroid Build Coastguard Worker  *
406*0e209d39SAndroid Build Coastguard Worker  * If the position is at the end of the text (the index following
407*0e209d39SAndroid Build Coastguard Worker  * the last character, which is also the length of the text),
408*0e209d39SAndroid Build Coastguard Worker  * return U_SENTINEL (-1) and do not advance the index.
409*0e209d39SAndroid Build Coastguard Worker  *
410*0e209d39SAndroid Build Coastguard Worker  * This is a post-increment operation.
411*0e209d39SAndroid Build Coastguard Worker  *
412*0e209d39SAndroid Build Coastguard Worker  * An inline macro version of this function, UTEXT_NEXT32(),
413*0e209d39SAndroid Build Coastguard Worker  * is available for performance critical use.
414*0e209d39SAndroid Build Coastguard Worker  *
415*0e209d39SAndroid Build Coastguard Worker  * @param ut the text to be accessed.
416*0e209d39SAndroid Build Coastguard Worker  * @return the Unicode code point at the iteration position.
417*0e209d39SAndroid Build Coastguard Worker  * @see UTEXT_NEXT32
418*0e209d39SAndroid Build Coastguard Worker  * \xrefitem stable "Stable" "Stable List" ICU 3.4
419*0e209d39SAndroid Build Coastguard Worker  */
420*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2
421*0e209d39SAndroid Build Coastguard Worker utext_next32(UText *ut) __INTRODUCED_IN(31);
422*0e209d39SAndroid Build Coastguard Worker 
423*0e209d39SAndroid Build Coastguard Worker 
424*0e209d39SAndroid Build Coastguard Worker 
425*0e209d39SAndroid Build Coastguard Worker 
426*0e209d39SAndroid Build Coastguard Worker /**
427*0e209d39SAndroid Build Coastguard Worker  *  Move the iterator position to the character (code point) whose
428*0e209d39SAndroid Build Coastguard Worker  *  index precedes the current position, and return that character.
429*0e209d39SAndroid Build Coastguard Worker  *  This is a pre-decrement operation.
430*0e209d39SAndroid Build Coastguard Worker  *
431*0e209d39SAndroid Build Coastguard Worker  *  If the initial position is at the start of the text (index of 0)
432*0e209d39SAndroid Build Coastguard Worker  *  return U_SENTINEL (-1), and leave the position unchanged.
433*0e209d39SAndroid Build Coastguard Worker  *
434*0e209d39SAndroid Build Coastguard Worker  *  An inline macro version of this function, UTEXT_PREVIOUS32(),
435*0e209d39SAndroid Build Coastguard Worker  *  is available for performance critical use.
436*0e209d39SAndroid Build Coastguard Worker  *
437*0e209d39SAndroid Build Coastguard Worker  *  @param ut the text to be accessed.
438*0e209d39SAndroid Build Coastguard Worker  *  @return the previous UChar32 code point, or U_SENTINEL (-1)
439*0e209d39SAndroid Build Coastguard Worker  *          if the iteration has reached the start of the text.
440*0e209d39SAndroid Build Coastguard Worker  *  @see UTEXT_PREVIOUS32
441*0e209d39SAndroid Build Coastguard Worker  *  \xrefitem stable "Stable" "Stable List" ICU 3.4
442*0e209d39SAndroid Build Coastguard Worker  */
443*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2
444*0e209d39SAndroid Build Coastguard Worker utext_previous32(UText *ut) __INTRODUCED_IN(31);
445*0e209d39SAndroid Build Coastguard Worker 
446*0e209d39SAndroid Build Coastguard Worker 
447*0e209d39SAndroid Build Coastguard Worker 
448*0e209d39SAndroid Build Coastguard Worker 
449*0e209d39SAndroid Build Coastguard Worker /**
450*0e209d39SAndroid Build Coastguard Worker   * Set the iteration index and return the code point at that index.
451*0e209d39SAndroid Build Coastguard Worker   * Leave the iteration index at the start of the following code point.
452*0e209d39SAndroid Build Coastguard Worker   *
453*0e209d39SAndroid Build Coastguard Worker   * This function is the most efficient and convenient way to
454*0e209d39SAndroid Build Coastguard Worker   * begin a forward iteration.  The results are identical to the those
455*0e209d39SAndroid Build Coastguard Worker   * from the sequence
456*0e209d39SAndroid Build Coastguard Worker   * \code
457*0e209d39SAndroid Build Coastguard Worker   *    utext_setIndex();
458*0e209d39SAndroid Build Coastguard Worker   *    utext_next32();
459*0e209d39SAndroid Build Coastguard Worker   * \endcode
460*0e209d39SAndroid Build Coastguard Worker   *
461*0e209d39SAndroid Build Coastguard Worker   *  @param ut the text to be accessed.
462*0e209d39SAndroid Build Coastguard Worker   *  @param nativeIndex Iteration index, in the native units of the text provider.
463*0e209d39SAndroid Build Coastguard Worker   *  @return Code point which starts at or before index,
464*0e209d39SAndroid Build Coastguard Worker   *         or U_SENTINEL (-1) if it is out of bounds.
465*0e209d39SAndroid Build Coastguard Worker   * \xrefitem stable "Stable" "Stable List" ICU 3.4
466*0e209d39SAndroid Build Coastguard Worker   */
467*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2
468*0e209d39SAndroid Build Coastguard Worker utext_next32From(UText *ut, int64_t nativeIndex) __INTRODUCED_IN(31);
469*0e209d39SAndroid Build Coastguard Worker 
470*0e209d39SAndroid Build Coastguard Worker 
471*0e209d39SAndroid Build Coastguard Worker 
472*0e209d39SAndroid Build Coastguard Worker 
473*0e209d39SAndroid Build Coastguard Worker 
474*0e209d39SAndroid Build Coastguard Worker /**
475*0e209d39SAndroid Build Coastguard Worker   * Set the iteration index, and return the code point preceding the
476*0e209d39SAndroid Build Coastguard Worker   * one specified by the initial index.  Leave the iteration position
477*0e209d39SAndroid Build Coastguard Worker   * at the start of the returned code point.
478*0e209d39SAndroid Build Coastguard Worker   *
479*0e209d39SAndroid Build Coastguard Worker   * This function is the most efficient and convenient way to
480*0e209d39SAndroid Build Coastguard Worker   * begin a backwards iteration.
481*0e209d39SAndroid Build Coastguard Worker   *
482*0e209d39SAndroid Build Coastguard Worker   * @param ut the text to be accessed.
483*0e209d39SAndroid Build Coastguard Worker   * @param nativeIndex Iteration index in the native units of the text provider.
484*0e209d39SAndroid Build Coastguard Worker   * @return Code point preceding the one at the initial index,
485*0e209d39SAndroid Build Coastguard Worker   *         or U_SENTINEL (-1) if it is out of bounds.
486*0e209d39SAndroid Build Coastguard Worker   *
487*0e209d39SAndroid Build Coastguard Worker   * \xrefitem stable "Stable" "Stable List" ICU 3.4
488*0e209d39SAndroid Build Coastguard Worker   */
489*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2
490*0e209d39SAndroid Build Coastguard Worker utext_previous32From(UText *ut, int64_t nativeIndex) __INTRODUCED_IN(31);
491*0e209d39SAndroid Build Coastguard Worker 
492*0e209d39SAndroid Build Coastguard Worker 
493*0e209d39SAndroid Build Coastguard Worker 
494*0e209d39SAndroid Build Coastguard Worker /**
495*0e209d39SAndroid Build Coastguard Worker   * Get the current iterator position, which can range from 0 to
496*0e209d39SAndroid Build Coastguard Worker   * the length of the text.
497*0e209d39SAndroid Build Coastguard Worker   * The position is a native index into the input text, in whatever format it
498*0e209d39SAndroid Build Coastguard Worker   * may have (possibly UTF-8 for example), and may not always be the same as
499*0e209d39SAndroid Build Coastguard Worker   * the corresponding UChar (UTF-16) index.
500*0e209d39SAndroid Build Coastguard Worker   * The returned position will always be aligned to a code point boundary.
501*0e209d39SAndroid Build Coastguard Worker   *
502*0e209d39SAndroid Build Coastguard Worker   * @param ut the text to be accessed.
503*0e209d39SAndroid Build Coastguard Worker   * @return the current index position, in the native units of the text provider.
504*0e209d39SAndroid Build Coastguard Worker   * \xrefitem stable "Stable" "Stable List" ICU 3.4
505*0e209d39SAndroid Build Coastguard Worker   */
506*0e209d39SAndroid Build Coastguard Worker U_CAPI int64_t U_EXPORT2
507*0e209d39SAndroid Build Coastguard Worker utext_getNativeIndex(const UText *ut) __INTRODUCED_IN(31);
508*0e209d39SAndroid Build Coastguard Worker 
509*0e209d39SAndroid Build Coastguard Worker 
510*0e209d39SAndroid Build Coastguard Worker 
511*0e209d39SAndroid Build Coastguard Worker /**
512*0e209d39SAndroid Build Coastguard Worker  * Set the current iteration position to the nearest code point
513*0e209d39SAndroid Build Coastguard Worker  * boundary at or preceding the specified index.
514*0e209d39SAndroid Build Coastguard Worker  * The index is in the native units of the original input text.
515*0e209d39SAndroid Build Coastguard Worker  * If the index is out of range, it will be pinned to be within
516*0e209d39SAndroid Build Coastguard Worker  * the range of the input text.
517*0e209d39SAndroid Build Coastguard Worker  * <p>
518*0e209d39SAndroid Build Coastguard Worker  * It will usually be more efficient to begin an iteration
519*0e209d39SAndroid Build Coastguard Worker  * using the functions utext_next32From() or utext_previous32From()
520*0e209d39SAndroid Build Coastguard Worker  * rather than setIndex().
521*0e209d39SAndroid Build Coastguard Worker  * <p>
522*0e209d39SAndroid Build Coastguard Worker  * Moving the index position to an adjacent character is best done
523*0e209d39SAndroid Build Coastguard Worker  * with utext_next32(), utext_previous32() or utext_moveIndex32().
524*0e209d39SAndroid Build Coastguard Worker  * Attempting to do direct arithmetic on the index position is
525*0e209d39SAndroid Build Coastguard Worker  * complicated by the fact that the size (in native units) of a
526*0e209d39SAndroid Build Coastguard Worker  * character depends on the underlying representation of the character
527*0e209d39SAndroid Build Coastguard Worker  * (UTF-8, UTF-16, UTF-32, arbitrary codepage), and is not
528*0e209d39SAndroid Build Coastguard Worker  * easily knowable.
529*0e209d39SAndroid Build Coastguard Worker  *
530*0e209d39SAndroid Build Coastguard Worker  * @param ut the text to be accessed.
531*0e209d39SAndroid Build Coastguard Worker  * @param nativeIndex the native unit index of the new iteration position.
532*0e209d39SAndroid Build Coastguard Worker  * \xrefitem stable "Stable" "Stable List" ICU 3.4
533*0e209d39SAndroid Build Coastguard Worker  */
534*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
535*0e209d39SAndroid Build Coastguard Worker utext_setNativeIndex(UText *ut, int64_t nativeIndex) __INTRODUCED_IN(31);
536*0e209d39SAndroid Build Coastguard Worker 
537*0e209d39SAndroid Build Coastguard Worker 
538*0e209d39SAndroid Build Coastguard Worker 
539*0e209d39SAndroid Build Coastguard Worker /**
540*0e209d39SAndroid Build Coastguard Worker  * Move the iterator position by delta code points.  The number of code points
541*0e209d39SAndroid Build Coastguard Worker  * is a signed number; a negative delta will move the iterator backwards,
542*0e209d39SAndroid Build Coastguard Worker  * towards the start of the text.
543*0e209d39SAndroid Build Coastguard Worker  * <p>
544*0e209d39SAndroid Build Coastguard Worker  * The index is moved by <code>delta</code> code points
545*0e209d39SAndroid Build Coastguard Worker  * forward or backward, but no further backward than to 0 and
546*0e209d39SAndroid Build Coastguard Worker  * no further forward than to utext_nativeLength().
547*0e209d39SAndroid Build Coastguard Worker  * The resulting index value will be in between 0 and length, inclusive.
548*0e209d39SAndroid Build Coastguard Worker  *
549*0e209d39SAndroid Build Coastguard Worker  * @param ut the text to be accessed.
550*0e209d39SAndroid Build Coastguard Worker  * @param delta the signed number of code points to move the iteration position.
551*0e209d39SAndroid Build Coastguard Worker  * @return true if the position could be moved the requested number of positions while
552*0e209d39SAndroid Build Coastguard Worker  *              staying within the range [0 - text length].
553*0e209d39SAndroid Build Coastguard Worker  * \xrefitem stable "Stable" "Stable List" ICU 3.4
554*0e209d39SAndroid Build Coastguard Worker  */
555*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
556*0e209d39SAndroid Build Coastguard Worker utext_moveIndex32(UText *ut, int32_t delta) __INTRODUCED_IN(31);
557*0e209d39SAndroid Build Coastguard Worker 
558*0e209d39SAndroid Build Coastguard Worker 
559*0e209d39SAndroid Build Coastguard Worker 
560*0e209d39SAndroid Build Coastguard Worker /**
561*0e209d39SAndroid Build Coastguard Worker  * Get the native index of the character preceding the current position.
562*0e209d39SAndroid Build Coastguard Worker  * If the iteration position is already at the start of the text, zero
563*0e209d39SAndroid Build Coastguard Worker  * is returned.
564*0e209d39SAndroid Build Coastguard Worker  * The value returned is the same as that obtained from the following sequence,
565*0e209d39SAndroid Build Coastguard Worker  * but without the side effect of changing the iteration position.
566*0e209d39SAndroid Build Coastguard Worker  *
567*0e209d39SAndroid Build Coastguard Worker  * \code
568*0e209d39SAndroid Build Coastguard Worker  *    UText  *ut = whatever;
569*0e209d39SAndroid Build Coastguard Worker  *      ...
570*0e209d39SAndroid Build Coastguard Worker  *    utext_previous(ut)
571*0e209d39SAndroid Build Coastguard Worker  *    utext_getNativeIndex(ut);
572*0e209d39SAndroid Build Coastguard Worker  * \endcode
573*0e209d39SAndroid Build Coastguard Worker  *
574*0e209d39SAndroid Build Coastguard Worker  * This function is most useful during forwards iteration, where it will get the
575*0e209d39SAndroid Build Coastguard Worker  *   native index of the character most recently returned from utext_next().
576*0e209d39SAndroid Build Coastguard Worker  *
577*0e209d39SAndroid Build Coastguard Worker  * @param ut the text to be accessed
578*0e209d39SAndroid Build Coastguard Worker  * @return the native index of the character preceding the current index position,
579*0e209d39SAndroid Build Coastguard Worker  *         or zero if the current position is at the start of the text.
580*0e209d39SAndroid Build Coastguard Worker  * \xrefitem stable "Stable" "Stable List" ICU 3.6
581*0e209d39SAndroid Build Coastguard Worker  */
582*0e209d39SAndroid Build Coastguard Worker U_CAPI int64_t U_EXPORT2
583*0e209d39SAndroid Build Coastguard Worker utext_getPreviousNativeIndex(UText *ut);
584*0e209d39SAndroid Build Coastguard Worker 
585*0e209d39SAndroid Build Coastguard Worker 
586*0e209d39SAndroid Build Coastguard Worker /**
587*0e209d39SAndroid Build Coastguard Worker  *
588*0e209d39SAndroid Build Coastguard Worker  * Extract text from a UText into a UChar buffer.  The range of text to be extracted
589*0e209d39SAndroid Build Coastguard Worker  * is specified in the native indices of the UText provider.  These may not necessarily
590*0e209d39SAndroid Build Coastguard Worker  * be UTF-16 indices.
591*0e209d39SAndroid Build Coastguard Worker  * <p>
592*0e209d39SAndroid Build Coastguard Worker  * The size (number of 16 bit UChars) of the data to be extracted is returned.  The
593*0e209d39SAndroid Build Coastguard Worker  * full number of UChars is returned, even when the extracted text is truncated
594*0e209d39SAndroid Build Coastguard Worker  * because the specified buffer size is too small.
595*0e209d39SAndroid Build Coastguard Worker  * <p>
596*0e209d39SAndroid Build Coastguard Worker  * The extracted string will (if you are a user) / must (if you are a text provider)
597*0e209d39SAndroid Build Coastguard Worker  * be NUL-terminated if there is sufficient space in the destination buffer.  This
598*0e209d39SAndroid Build Coastguard Worker  * terminating NUL is not included in the returned length.
599*0e209d39SAndroid Build Coastguard Worker  * <p>
600*0e209d39SAndroid Build Coastguard Worker  * The iteration index is left at the position following the last extracted character.
601*0e209d39SAndroid Build Coastguard Worker  *
602*0e209d39SAndroid Build Coastguard Worker  * @param  ut    the UText from which to extract data.
603*0e209d39SAndroid Build Coastguard Worker  * @param  nativeStart the native index of the first character to extract.\
604*0e209d39SAndroid Build Coastguard Worker  *               If the specified index is out of range,
605*0e209d39SAndroid Build Coastguard Worker  *               it will be pinned to be within 0 <= index <= textLength
606*0e209d39SAndroid Build Coastguard Worker  * @param  nativeLimit the native string index of the position following the last
607*0e209d39SAndroid Build Coastguard Worker  *               character to extract.  If the specified index is out of range,
608*0e209d39SAndroid Build Coastguard Worker  *               it will be pinned to be within 0 <= index <= textLength.
609*0e209d39SAndroid Build Coastguard Worker  *               nativeLimit must be >= nativeStart.
610*0e209d39SAndroid Build Coastguard Worker  * @param  dest  the UChar (UTF-16) buffer into which the extracted text is placed
611*0e209d39SAndroid Build Coastguard Worker  * @param  destCapacity  The size, in UChars, of the destination buffer.  May be zero
612*0e209d39SAndroid Build Coastguard Worker  *               for precomputing the required size.
613*0e209d39SAndroid Build Coastguard Worker  * @param  status receives any error status.
614*0e209d39SAndroid Build Coastguard Worker  *         U_BUFFER_OVERFLOW_ERROR: the extracted text was truncated because the
615*0e209d39SAndroid Build Coastguard Worker  *         buffer was too small.  Returns number of UChars for preflighting.
616*0e209d39SAndroid Build Coastguard Worker  * @return Number of UChars in the data to be extracted.  Does not include a trailing NUL.
617*0e209d39SAndroid Build Coastguard Worker  *
618*0e209d39SAndroid Build Coastguard Worker  * \xrefitem stable "Stable" "Stable List" ICU 3.4
619*0e209d39SAndroid Build Coastguard Worker  */
620*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
621*0e209d39SAndroid Build Coastguard Worker utext_extract(UText *ut,
622*0e209d39SAndroid Build Coastguard Worker              int64_t nativeStart, int64_t nativeLimit,
623*0e209d39SAndroid Build Coastguard Worker              UChar *dest, int32_t destCapacity,
624*0e209d39SAndroid Build Coastguard Worker              UErrorCode *status) __INTRODUCED_IN(31);
625*0e209d39SAndroid Build Coastguard Worker 
626*0e209d39SAndroid Build Coastguard Worker 
627*0e209d39SAndroid Build Coastguard Worker 
628*0e209d39SAndroid Build Coastguard Worker 
629*0e209d39SAndroid Build Coastguard Worker 
630*0e209d39SAndroid Build Coastguard Worker 
631*0e209d39SAndroid Build Coastguard Worker 
632*0e209d39SAndroid Build Coastguard Worker U_CDECL_END
633*0e209d39SAndroid Build Coastguard Worker 
634*0e209d39SAndroid Build Coastguard Worker 
635*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
636*0e209d39SAndroid Build Coastguard Worker 
637*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
638*0e209d39SAndroid Build Coastguard Worker 
639*0e209d39SAndroid Build Coastguard Worker /**
640*0e209d39SAndroid Build Coastguard Worker  * \class LocalUTextPointer
641*0e209d39SAndroid Build Coastguard Worker  * "Smart pointer" class, closes a UText via utext_close().
642*0e209d39SAndroid Build Coastguard Worker  * For most methods see the LocalPointerBase base class.
643*0e209d39SAndroid Build Coastguard Worker  *
644*0e209d39SAndroid Build Coastguard Worker  * @see LocalPointerBase
645*0e209d39SAndroid Build Coastguard Worker  * @see LocalPointer
646*0e209d39SAndroid Build Coastguard Worker  * \xrefitem stable "Stable" "Stable List" ICU 4.4
647*0e209d39SAndroid Build Coastguard Worker  */
648*0e209d39SAndroid Build Coastguard Worker U_DEFINE_LOCAL_OPEN_POINTER(LocalUTextPointer, UText, utext_close);
649*0e209d39SAndroid Build Coastguard Worker 
650*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
651*0e209d39SAndroid Build Coastguard Worker 
652*0e209d39SAndroid Build Coastguard Worker #endif
653*0e209d39SAndroid Build Coastguard Worker 
654*0e209d39SAndroid Build Coastguard Worker 
655*0e209d39SAndroid Build Coastguard Worker #endif
656*0e209d39SAndroid Build Coastguard Worker 
657*0e209d39SAndroid Build Coastguard Worker /** @} */ // addtogroup
658