xref: /aosp_15_r20/external/icu/libandroidicu/include/unicode/uformattedvalue.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2018 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 #ifndef __UFORMATTEDVALUE_H__
5*0e209d39SAndroid Build Coastguard Worker #define __UFORMATTEDVALUE_H__
6*0e209d39SAndroid Build Coastguard Worker 
7*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
8*0e209d39SAndroid Build Coastguard Worker 
9*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING
10*0e209d39SAndroid Build Coastguard Worker 
11*0e209d39SAndroid Build Coastguard Worker #include "unicode/ufieldpositer.h"
12*0e209d39SAndroid Build Coastguard Worker 
13*0e209d39SAndroid Build Coastguard Worker /**
14*0e209d39SAndroid Build Coastguard Worker  * \file
15*0e209d39SAndroid Build Coastguard Worker  * \brief C API: Abstract operations for localized strings.
16*0e209d39SAndroid Build Coastguard Worker  *
17*0e209d39SAndroid Build Coastguard Worker  * This file contains declarations for classes that deal with formatted strings. A number
18*0e209d39SAndroid Build Coastguard Worker  * of APIs throughout ICU use these classes for expressing their localized output.
19*0e209d39SAndroid Build Coastguard Worker  */
20*0e209d39SAndroid Build Coastguard Worker 
21*0e209d39SAndroid Build Coastguard Worker 
22*0e209d39SAndroid Build Coastguard Worker /**
23*0e209d39SAndroid Build Coastguard Worker  * All possible field categories in ICU. Every entry in this enum corresponds
24*0e209d39SAndroid Build Coastguard Worker  * to another enum that exists in ICU.
25*0e209d39SAndroid Build Coastguard Worker  *
26*0e209d39SAndroid Build Coastguard Worker  * In the APIs that take a UFieldCategory, an int32_t type is used. Field
27*0e209d39SAndroid Build Coastguard Worker  * categories having any of the top four bits turned on are reserved as
28*0e209d39SAndroid Build Coastguard Worker  * private-use for external APIs implementing FormattedValue. This means that
29*0e209d39SAndroid Build Coastguard Worker  * categories 2^28 and higher or below zero (with the highest bit turned on)
30*0e209d39SAndroid Build Coastguard Worker  * are private-use and will not be used by ICU in the future.
31*0e209d39SAndroid Build Coastguard Worker  *
32*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
33*0e209d39SAndroid Build Coastguard Worker  */
34*0e209d39SAndroid Build Coastguard Worker typedef enum UFieldCategory {
35*0e209d39SAndroid Build Coastguard Worker     /**
36*0e209d39SAndroid Build Coastguard Worker      * For an undefined field category.
37*0e209d39SAndroid Build Coastguard Worker      *
38*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 64
39*0e209d39SAndroid Build Coastguard Worker      */
40*0e209d39SAndroid Build Coastguard Worker     UFIELD_CATEGORY_UNDEFINED = 0,
41*0e209d39SAndroid Build Coastguard Worker 
42*0e209d39SAndroid Build Coastguard Worker     /**
43*0e209d39SAndroid Build Coastguard Worker      * For fields in UDateFormatField (udat.h), from ICU 3.0.
44*0e209d39SAndroid Build Coastguard Worker      *
45*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 64
46*0e209d39SAndroid Build Coastguard Worker      */
47*0e209d39SAndroid Build Coastguard Worker     UFIELD_CATEGORY_DATE,
48*0e209d39SAndroid Build Coastguard Worker 
49*0e209d39SAndroid Build Coastguard Worker     /**
50*0e209d39SAndroid Build Coastguard Worker      * For fields in UNumberFormatFields (unum.h), from ICU 49.
51*0e209d39SAndroid Build Coastguard Worker      *
52*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 64
53*0e209d39SAndroid Build Coastguard Worker      */
54*0e209d39SAndroid Build Coastguard Worker     UFIELD_CATEGORY_NUMBER,
55*0e209d39SAndroid Build Coastguard Worker 
56*0e209d39SAndroid Build Coastguard Worker     /**
57*0e209d39SAndroid Build Coastguard Worker      * For fields in UListFormatterField (ulistformatter.h), from ICU 63.
58*0e209d39SAndroid Build Coastguard Worker      *
59*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 64
60*0e209d39SAndroid Build Coastguard Worker      */
61*0e209d39SAndroid Build Coastguard Worker     UFIELD_CATEGORY_LIST,
62*0e209d39SAndroid Build Coastguard Worker 
63*0e209d39SAndroid Build Coastguard Worker     /**
64*0e209d39SAndroid Build Coastguard Worker      * For fields in URelativeDateTimeFormatterField (ureldatefmt.h), from ICU 64.
65*0e209d39SAndroid Build Coastguard Worker      *
66*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 64
67*0e209d39SAndroid Build Coastguard Worker      */
68*0e209d39SAndroid Build Coastguard Worker     UFIELD_CATEGORY_RELATIVE_DATETIME,
69*0e209d39SAndroid Build Coastguard Worker 
70*0e209d39SAndroid Build Coastguard Worker     /**
71*0e209d39SAndroid Build Coastguard Worker      * Reserved for possible future fields in UDateIntervalFormatField.
72*0e209d39SAndroid Build Coastguard Worker      *
73*0e209d39SAndroid Build Coastguard Worker      * @internal
74*0e209d39SAndroid Build Coastguard Worker      */
75*0e209d39SAndroid Build Coastguard Worker     UFIELD_CATEGORY_DATE_INTERVAL,
76*0e209d39SAndroid Build Coastguard Worker 
77*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
78*0e209d39SAndroid Build Coastguard Worker     /** @internal */
79*0e209d39SAndroid Build Coastguard Worker     UFIELD_CATEGORY_COUNT,
80*0e209d39SAndroid Build Coastguard Worker #endif  /* U_HIDE_INTERNAL_API */
81*0e209d39SAndroid Build Coastguard Worker 
82*0e209d39SAndroid Build Coastguard Worker     /**
83*0e209d39SAndroid Build Coastguard Worker      * Category for spans in a list.
84*0e209d39SAndroid Build Coastguard Worker      *
85*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 64
86*0e209d39SAndroid Build Coastguard Worker      */
87*0e209d39SAndroid Build Coastguard Worker     UFIELD_CATEGORY_LIST_SPAN = 0x1000 + UFIELD_CATEGORY_LIST,
88*0e209d39SAndroid Build Coastguard Worker 
89*0e209d39SAndroid Build Coastguard Worker     /**
90*0e209d39SAndroid Build Coastguard Worker      * Category for spans in a date interval.
91*0e209d39SAndroid Build Coastguard Worker      *
92*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 64
93*0e209d39SAndroid Build Coastguard Worker      */
94*0e209d39SAndroid Build Coastguard Worker     UFIELD_CATEGORY_DATE_INTERVAL_SPAN = 0x1000 + UFIELD_CATEGORY_DATE_INTERVAL,
95*0e209d39SAndroid Build Coastguard Worker 
96*0e209d39SAndroid Build Coastguard Worker     /**
97*0e209d39SAndroid Build Coastguard Worker      * Category for spans in a number range.
98*0e209d39SAndroid Build Coastguard Worker      *
99*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 69
100*0e209d39SAndroid Build Coastguard Worker      */
101*0e209d39SAndroid Build Coastguard Worker     UFIELD_CATEGORY_NUMBER_RANGE_SPAN = 0x1000 + UFIELD_CATEGORY_NUMBER,
102*0e209d39SAndroid Build Coastguard Worker 
103*0e209d39SAndroid Build Coastguard Worker } UFieldCategory;
104*0e209d39SAndroid Build Coastguard Worker 
105*0e209d39SAndroid Build Coastguard Worker 
106*0e209d39SAndroid Build Coastguard Worker struct UConstrainedFieldPosition;
107*0e209d39SAndroid Build Coastguard Worker /**
108*0e209d39SAndroid Build Coastguard Worker  * Represents a span of a string containing a given field.
109*0e209d39SAndroid Build Coastguard Worker  *
110*0e209d39SAndroid Build Coastguard Worker  * This struct differs from UFieldPosition in the following ways:
111*0e209d39SAndroid Build Coastguard Worker  *
112*0e209d39SAndroid Build Coastguard Worker  *   1. It has information on the field category.
113*0e209d39SAndroid Build Coastguard Worker  *   2. It allows you to set constraints to use when iterating over field positions.
114*0e209d39SAndroid Build Coastguard Worker  *   3. It is used for the newer FormattedValue APIs.
115*0e209d39SAndroid Build Coastguard Worker  *
116*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
117*0e209d39SAndroid Build Coastguard Worker  */
118*0e209d39SAndroid Build Coastguard Worker typedef struct UConstrainedFieldPosition UConstrainedFieldPosition;
119*0e209d39SAndroid Build Coastguard Worker 
120*0e209d39SAndroid Build Coastguard Worker 
121*0e209d39SAndroid Build Coastguard Worker /**
122*0e209d39SAndroid Build Coastguard Worker  * Creates a new UConstrainedFieldPosition.
123*0e209d39SAndroid Build Coastguard Worker  *
124*0e209d39SAndroid Build Coastguard Worker  * By default, the UConstrainedFieldPosition has no iteration constraints.
125*0e209d39SAndroid Build Coastguard Worker  *
126*0e209d39SAndroid Build Coastguard Worker  * @param ec Set if an error occurs.
127*0e209d39SAndroid Build Coastguard Worker  * @return The new object, or NULL if an error occurs.
128*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
129*0e209d39SAndroid Build Coastguard Worker  */
130*0e209d39SAndroid Build Coastguard Worker U_CAPI UConstrainedFieldPosition* U_EXPORT2
131*0e209d39SAndroid Build Coastguard Worker ucfpos_open(UErrorCode* ec);
132*0e209d39SAndroid Build Coastguard Worker 
133*0e209d39SAndroid Build Coastguard Worker 
134*0e209d39SAndroid Build Coastguard Worker /**
135*0e209d39SAndroid Build Coastguard Worker  * Resets a UConstrainedFieldPosition to its initial state, as if it were newly created.
136*0e209d39SAndroid Build Coastguard Worker  *
137*0e209d39SAndroid Build Coastguard Worker  * Removes any constraints that may have been set on the instance.
138*0e209d39SAndroid Build Coastguard Worker  *
139*0e209d39SAndroid Build Coastguard Worker  * @param ucfpos The instance of UConstrainedFieldPosition.
140*0e209d39SAndroid Build Coastguard Worker  * @param ec Set if an error occurs.
141*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
142*0e209d39SAndroid Build Coastguard Worker  */
143*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
144*0e209d39SAndroid Build Coastguard Worker ucfpos_reset(
145*0e209d39SAndroid Build Coastguard Worker     UConstrainedFieldPosition* ucfpos,
146*0e209d39SAndroid Build Coastguard Worker     UErrorCode* ec);
147*0e209d39SAndroid Build Coastguard Worker 
148*0e209d39SAndroid Build Coastguard Worker 
149*0e209d39SAndroid Build Coastguard Worker /**
150*0e209d39SAndroid Build Coastguard Worker  * Destroys a UConstrainedFieldPosition and releases its memory.
151*0e209d39SAndroid Build Coastguard Worker  *
152*0e209d39SAndroid Build Coastguard Worker  * @param ucfpos The instance of UConstrainedFieldPosition.
153*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
154*0e209d39SAndroid Build Coastguard Worker  */
155*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
156*0e209d39SAndroid Build Coastguard Worker ucfpos_close(UConstrainedFieldPosition* ucfpos);
157*0e209d39SAndroid Build Coastguard Worker 
158*0e209d39SAndroid Build Coastguard Worker 
159*0e209d39SAndroid Build Coastguard Worker /**
160*0e209d39SAndroid Build Coastguard Worker  * Sets a constraint on the field category.
161*0e209d39SAndroid Build Coastguard Worker  *
162*0e209d39SAndroid Build Coastguard Worker  * When this instance of UConstrainedFieldPosition is passed to ufmtval_nextPosition,
163*0e209d39SAndroid Build Coastguard Worker  * positions are skipped unless they have the given category.
164*0e209d39SAndroid Build Coastguard Worker  *
165*0e209d39SAndroid Build Coastguard Worker  * Any previously set constraints are cleared.
166*0e209d39SAndroid Build Coastguard Worker  *
167*0e209d39SAndroid Build Coastguard Worker  * For example, to loop over only the number-related fields:
168*0e209d39SAndroid Build Coastguard Worker  *
169*0e209d39SAndroid Build Coastguard Worker  *     UConstrainedFieldPosition* ucfpos = ucfpos_open(ec);
170*0e209d39SAndroid Build Coastguard Worker  *     ucfpos_constrainCategory(ucfpos, UFIELDCATEGORY_NUMBER_FORMAT, ec);
171*0e209d39SAndroid Build Coastguard Worker  *     while (ufmtval_nextPosition(ufmtval, ucfpos, ec)) {
172*0e209d39SAndroid Build Coastguard Worker  *         // handle the number-related field position
173*0e209d39SAndroid Build Coastguard Worker  *     }
174*0e209d39SAndroid Build Coastguard Worker  *     ucfpos_close(ucfpos);
175*0e209d39SAndroid Build Coastguard Worker  *
176*0e209d39SAndroid Build Coastguard Worker  * Changing the constraint while in the middle of iterating over a FormattedValue
177*0e209d39SAndroid Build Coastguard Worker  * does not generally have well-defined behavior.
178*0e209d39SAndroid Build Coastguard Worker  *
179*0e209d39SAndroid Build Coastguard Worker  * @param ucfpos The instance of UConstrainedFieldPosition.
180*0e209d39SAndroid Build Coastguard Worker  * @param category The field category to fix when iterating.
181*0e209d39SAndroid Build Coastguard Worker  * @param ec Set if an error occurs.
182*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
183*0e209d39SAndroid Build Coastguard Worker  */
184*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
185*0e209d39SAndroid Build Coastguard Worker ucfpos_constrainCategory(
186*0e209d39SAndroid Build Coastguard Worker     UConstrainedFieldPosition* ucfpos,
187*0e209d39SAndroid Build Coastguard Worker     int32_t category,
188*0e209d39SAndroid Build Coastguard Worker     UErrorCode* ec);
189*0e209d39SAndroid Build Coastguard Worker 
190*0e209d39SAndroid Build Coastguard Worker 
191*0e209d39SAndroid Build Coastguard Worker /**
192*0e209d39SAndroid Build Coastguard Worker  * Sets a constraint on the category and field.
193*0e209d39SAndroid Build Coastguard Worker  *
194*0e209d39SAndroid Build Coastguard Worker  * When this instance of UConstrainedFieldPosition is passed to ufmtval_nextPosition,
195*0e209d39SAndroid Build Coastguard Worker  * positions are skipped unless they have the given category and field.
196*0e209d39SAndroid Build Coastguard Worker  *
197*0e209d39SAndroid Build Coastguard Worker  * Any previously set constraints are cleared.
198*0e209d39SAndroid Build Coastguard Worker  *
199*0e209d39SAndroid Build Coastguard Worker  * For example, to loop over all grouping separators:
200*0e209d39SAndroid Build Coastguard Worker  *
201*0e209d39SAndroid Build Coastguard Worker  *     UConstrainedFieldPosition* ucfpos = ucfpos_open(ec);
202*0e209d39SAndroid Build Coastguard Worker  *     ucfpos_constrainField(ucfpos, UFIELDCATEGORY_NUMBER_FORMAT, UNUM_GROUPING_SEPARATOR_FIELD, ec);
203*0e209d39SAndroid Build Coastguard Worker  *     while (ufmtval_nextPosition(ufmtval, ucfpos, ec)) {
204*0e209d39SAndroid Build Coastguard Worker  *         // handle the grouping separator position
205*0e209d39SAndroid Build Coastguard Worker  *     }
206*0e209d39SAndroid Build Coastguard Worker  *     ucfpos_close(ucfpos);
207*0e209d39SAndroid Build Coastguard Worker  *
208*0e209d39SAndroid Build Coastguard Worker  * Changing the constraint while in the middle of iterating over a FormattedValue
209*0e209d39SAndroid Build Coastguard Worker  * does not generally have well-defined behavior.
210*0e209d39SAndroid Build Coastguard Worker  *
211*0e209d39SAndroid Build Coastguard Worker  * @param ucfpos The instance of UConstrainedFieldPosition.
212*0e209d39SAndroid Build Coastguard Worker  * @param category The field category to fix when iterating.
213*0e209d39SAndroid Build Coastguard Worker  * @param field The field to fix when iterating.
214*0e209d39SAndroid Build Coastguard Worker  * @param ec Set if an error occurs.
215*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
216*0e209d39SAndroid Build Coastguard Worker  */
217*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
218*0e209d39SAndroid Build Coastguard Worker ucfpos_constrainField(
219*0e209d39SAndroid Build Coastguard Worker     UConstrainedFieldPosition* ucfpos,
220*0e209d39SAndroid Build Coastguard Worker     int32_t category,
221*0e209d39SAndroid Build Coastguard Worker     int32_t field,
222*0e209d39SAndroid Build Coastguard Worker     UErrorCode* ec);
223*0e209d39SAndroid Build Coastguard Worker 
224*0e209d39SAndroid Build Coastguard Worker 
225*0e209d39SAndroid Build Coastguard Worker /**
226*0e209d39SAndroid Build Coastguard Worker  * Gets the field category for the current position.
227*0e209d39SAndroid Build Coastguard Worker  *
228*0e209d39SAndroid Build Coastguard Worker  * If a category or field constraint was set, this function returns the constrained
229*0e209d39SAndroid Build Coastguard Worker  * category. Otherwise, the return value is well-defined only after
230*0e209d39SAndroid Build Coastguard Worker  * ufmtval_nextPosition returns true.
231*0e209d39SAndroid Build Coastguard Worker  *
232*0e209d39SAndroid Build Coastguard Worker  * @param ucfpos The instance of UConstrainedFieldPosition.
233*0e209d39SAndroid Build Coastguard Worker  * @param ec Set if an error occurs.
234*0e209d39SAndroid Build Coastguard Worker  * @return The field category saved in the instance.
235*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
236*0e209d39SAndroid Build Coastguard Worker  */
237*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
238*0e209d39SAndroid Build Coastguard Worker ucfpos_getCategory(
239*0e209d39SAndroid Build Coastguard Worker     const UConstrainedFieldPosition* ucfpos,
240*0e209d39SAndroid Build Coastguard Worker     UErrorCode* ec);
241*0e209d39SAndroid Build Coastguard Worker 
242*0e209d39SAndroid Build Coastguard Worker 
243*0e209d39SAndroid Build Coastguard Worker /**
244*0e209d39SAndroid Build Coastguard Worker  * Gets the field for the current position.
245*0e209d39SAndroid Build Coastguard Worker  *
246*0e209d39SAndroid Build Coastguard Worker  * If a field constraint was set, this function returns the constrained
247*0e209d39SAndroid Build Coastguard Worker  * field. Otherwise, the return value is well-defined only after
248*0e209d39SAndroid Build Coastguard Worker  * ufmtval_nextPosition returns true.
249*0e209d39SAndroid Build Coastguard Worker  *
250*0e209d39SAndroid Build Coastguard Worker  * @param ucfpos The instance of UConstrainedFieldPosition.
251*0e209d39SAndroid Build Coastguard Worker  * @param ec Set if an error occurs.
252*0e209d39SAndroid Build Coastguard Worker  * @return The field saved in the instance.
253*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
254*0e209d39SAndroid Build Coastguard Worker  */
255*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
256*0e209d39SAndroid Build Coastguard Worker ucfpos_getField(
257*0e209d39SAndroid Build Coastguard Worker     const UConstrainedFieldPosition* ucfpos,
258*0e209d39SAndroid Build Coastguard Worker     UErrorCode* ec);
259*0e209d39SAndroid Build Coastguard Worker 
260*0e209d39SAndroid Build Coastguard Worker 
261*0e209d39SAndroid Build Coastguard Worker /**
262*0e209d39SAndroid Build Coastguard Worker  * Gets the INCLUSIVE start and EXCLUSIVE end index stored for the current position.
263*0e209d39SAndroid Build Coastguard Worker  *
264*0e209d39SAndroid Build Coastguard Worker  * The output values are well-defined only after ufmtval_nextPosition returns true.
265*0e209d39SAndroid Build Coastguard Worker  *
266*0e209d39SAndroid Build Coastguard Worker  * @param ucfpos The instance of UConstrainedFieldPosition.
267*0e209d39SAndroid Build Coastguard Worker  * @param pStart Set to the start index saved in the instance. Ignored if nullptr.
268*0e209d39SAndroid Build Coastguard Worker  * @param pLimit Set to the end index saved in the instance. Ignored if nullptr.
269*0e209d39SAndroid Build Coastguard Worker  * @param ec Set if an error occurs.
270*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
271*0e209d39SAndroid Build Coastguard Worker  */
272*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
273*0e209d39SAndroid Build Coastguard Worker ucfpos_getIndexes(
274*0e209d39SAndroid Build Coastguard Worker     const UConstrainedFieldPosition* ucfpos,
275*0e209d39SAndroid Build Coastguard Worker     int32_t* pStart,
276*0e209d39SAndroid Build Coastguard Worker     int32_t* pLimit,
277*0e209d39SAndroid Build Coastguard Worker     UErrorCode* ec);
278*0e209d39SAndroid Build Coastguard Worker 
279*0e209d39SAndroid Build Coastguard Worker 
280*0e209d39SAndroid Build Coastguard Worker /**
281*0e209d39SAndroid Build Coastguard Worker  * Gets an int64 that FormattedValue implementations may use for storage.
282*0e209d39SAndroid Build Coastguard Worker  *
283*0e209d39SAndroid Build Coastguard Worker  * The initial value is zero.
284*0e209d39SAndroid Build Coastguard Worker  *
285*0e209d39SAndroid Build Coastguard Worker  * Users of FormattedValue should not need to call this method.
286*0e209d39SAndroid Build Coastguard Worker  *
287*0e209d39SAndroid Build Coastguard Worker  * @param ucfpos The instance of UConstrainedFieldPosition.
288*0e209d39SAndroid Build Coastguard Worker  * @param ec Set if an error occurs.
289*0e209d39SAndroid Build Coastguard Worker  * @return The current iteration context from ucfpos_setInt64IterationContext.
290*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
291*0e209d39SAndroid Build Coastguard Worker  */
292*0e209d39SAndroid Build Coastguard Worker U_CAPI int64_t U_EXPORT2
293*0e209d39SAndroid Build Coastguard Worker ucfpos_getInt64IterationContext(
294*0e209d39SAndroid Build Coastguard Worker     const UConstrainedFieldPosition* ucfpos,
295*0e209d39SAndroid Build Coastguard Worker     UErrorCode* ec);
296*0e209d39SAndroid Build Coastguard Worker 
297*0e209d39SAndroid Build Coastguard Worker 
298*0e209d39SAndroid Build Coastguard Worker /**
299*0e209d39SAndroid Build Coastguard Worker  * Sets an int64 that FormattedValue implementations may use for storage.
300*0e209d39SAndroid Build Coastguard Worker  *
301*0e209d39SAndroid Build Coastguard Worker  * Intended to be used by FormattedValue implementations.
302*0e209d39SAndroid Build Coastguard Worker  *
303*0e209d39SAndroid Build Coastguard Worker  * @param ucfpos The instance of UConstrainedFieldPosition.
304*0e209d39SAndroid Build Coastguard Worker  * @param context The new iteration context.
305*0e209d39SAndroid Build Coastguard Worker  * @param ec Set if an error occurs.
306*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
307*0e209d39SAndroid Build Coastguard Worker  */
308*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
309*0e209d39SAndroid Build Coastguard Worker ucfpos_setInt64IterationContext(
310*0e209d39SAndroid Build Coastguard Worker     UConstrainedFieldPosition* ucfpos,
311*0e209d39SAndroid Build Coastguard Worker     int64_t context,
312*0e209d39SAndroid Build Coastguard Worker     UErrorCode* ec);
313*0e209d39SAndroid Build Coastguard Worker 
314*0e209d39SAndroid Build Coastguard Worker 
315*0e209d39SAndroid Build Coastguard Worker /**
316*0e209d39SAndroid Build Coastguard Worker  * Determines whether a given field should be included given the
317*0e209d39SAndroid Build Coastguard Worker  * constraints.
318*0e209d39SAndroid Build Coastguard Worker  *
319*0e209d39SAndroid Build Coastguard Worker  * Intended to be used by FormattedValue implementations.
320*0e209d39SAndroid Build Coastguard Worker  *
321*0e209d39SAndroid Build Coastguard Worker  * @param ucfpos The instance of UConstrainedFieldPosition.
322*0e209d39SAndroid Build Coastguard Worker  * @param category The category to test.
323*0e209d39SAndroid Build Coastguard Worker  * @param field The field to test.
324*0e209d39SAndroid Build Coastguard Worker  * @param ec Set if an error occurs.
325*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
326*0e209d39SAndroid Build Coastguard Worker  */
327*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
328*0e209d39SAndroid Build Coastguard Worker ucfpos_matchesField(
329*0e209d39SAndroid Build Coastguard Worker     const UConstrainedFieldPosition* ucfpos,
330*0e209d39SAndroid Build Coastguard Worker     int32_t category,
331*0e209d39SAndroid Build Coastguard Worker     int32_t field,
332*0e209d39SAndroid Build Coastguard Worker     UErrorCode* ec);
333*0e209d39SAndroid Build Coastguard Worker 
334*0e209d39SAndroid Build Coastguard Worker 
335*0e209d39SAndroid Build Coastguard Worker /**
336*0e209d39SAndroid Build Coastguard Worker  * Sets new values for the primary public getters.
337*0e209d39SAndroid Build Coastguard Worker  *
338*0e209d39SAndroid Build Coastguard Worker  * Intended to be used by FormattedValue implementations.
339*0e209d39SAndroid Build Coastguard Worker  *
340*0e209d39SAndroid Build Coastguard Worker  * It is up to the implementation to ensure that the user-requested
341*0e209d39SAndroid Build Coastguard Worker  * constraints are satisfied. This method does not check!
342*0e209d39SAndroid Build Coastguard Worker  *
343*0e209d39SAndroid Build Coastguard Worker  * @param ucfpos The instance of UConstrainedFieldPosition.
344*0e209d39SAndroid Build Coastguard Worker  * @param category The new field category.
345*0e209d39SAndroid Build Coastguard Worker  * @param field The new field.
346*0e209d39SAndroid Build Coastguard Worker  * @param start The new inclusive start index.
347*0e209d39SAndroid Build Coastguard Worker  * @param limit The new exclusive end index.
348*0e209d39SAndroid Build Coastguard Worker  * @param ec Set if an error occurs.
349*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
350*0e209d39SAndroid Build Coastguard Worker  */
351*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
352*0e209d39SAndroid Build Coastguard Worker ucfpos_setState(
353*0e209d39SAndroid Build Coastguard Worker     UConstrainedFieldPosition* ucfpos,
354*0e209d39SAndroid Build Coastguard Worker     int32_t category,
355*0e209d39SAndroid Build Coastguard Worker     int32_t field,
356*0e209d39SAndroid Build Coastguard Worker     int32_t start,
357*0e209d39SAndroid Build Coastguard Worker     int32_t limit,
358*0e209d39SAndroid Build Coastguard Worker     UErrorCode* ec);
359*0e209d39SAndroid Build Coastguard Worker 
360*0e209d39SAndroid Build Coastguard Worker 
361*0e209d39SAndroid Build Coastguard Worker struct UFormattedValue;
362*0e209d39SAndroid Build Coastguard Worker /**
363*0e209d39SAndroid Build Coastguard Worker  * An abstract formatted value: a string with associated field attributes.
364*0e209d39SAndroid Build Coastguard Worker  * Many formatters format to types compatible with UFormattedValue.
365*0e209d39SAndroid Build Coastguard Worker  *
366*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
367*0e209d39SAndroid Build Coastguard Worker  */
368*0e209d39SAndroid Build Coastguard Worker typedef struct UFormattedValue UFormattedValue;
369*0e209d39SAndroid Build Coastguard Worker 
370*0e209d39SAndroid Build Coastguard Worker 
371*0e209d39SAndroid Build Coastguard Worker /**
372*0e209d39SAndroid Build Coastguard Worker  * Returns a pointer to the formatted string. The pointer is owned by the UFormattedValue. The
373*0e209d39SAndroid Build Coastguard Worker  * return value is valid only as long as the UFormattedValue is present and unchanged in memory.
374*0e209d39SAndroid Build Coastguard Worker  *
375*0e209d39SAndroid Build Coastguard Worker  * The return value is NUL-terminated but could contain internal NULs.
376*0e209d39SAndroid Build Coastguard Worker  *
377*0e209d39SAndroid Build Coastguard Worker  * @param ufmtval
378*0e209d39SAndroid Build Coastguard Worker  *         The object containing the formatted string and attributes.
379*0e209d39SAndroid Build Coastguard Worker  * @param pLength Output variable for the length of the string. Ignored if NULL.
380*0e209d39SAndroid Build Coastguard Worker  * @param ec Set if an error occurs.
381*0e209d39SAndroid Build Coastguard Worker  * @return A NUL-terminated char16 string owned by the UFormattedValue.
382*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
383*0e209d39SAndroid Build Coastguard Worker  */
384*0e209d39SAndroid Build Coastguard Worker U_CAPI const UChar* U_EXPORT2
385*0e209d39SAndroid Build Coastguard Worker ufmtval_getString(
386*0e209d39SAndroid Build Coastguard Worker     const UFormattedValue* ufmtval,
387*0e209d39SAndroid Build Coastguard Worker     int32_t* pLength,
388*0e209d39SAndroid Build Coastguard Worker     UErrorCode* ec);
389*0e209d39SAndroid Build Coastguard Worker 
390*0e209d39SAndroid Build Coastguard Worker 
391*0e209d39SAndroid Build Coastguard Worker /**
392*0e209d39SAndroid Build Coastguard Worker  * Iterates over field positions in the UFormattedValue. This lets you determine the position
393*0e209d39SAndroid Build Coastguard Worker  * of specific types of substrings, like a month or a decimal separator.
394*0e209d39SAndroid Build Coastguard Worker  *
395*0e209d39SAndroid Build Coastguard Worker  * To loop over all field positions:
396*0e209d39SAndroid Build Coastguard Worker  *
397*0e209d39SAndroid Build Coastguard Worker  *     UConstrainedFieldPosition* ucfpos = ucfpos_open(ec);
398*0e209d39SAndroid Build Coastguard Worker  *     while (ufmtval_nextPosition(ufmtval, ucfpos, ec)) {
399*0e209d39SAndroid Build Coastguard Worker  *         // handle the field position; get information from ucfpos
400*0e209d39SAndroid Build Coastguard Worker  *     }
401*0e209d39SAndroid Build Coastguard Worker  *     ucfpos_close(ucfpos);
402*0e209d39SAndroid Build Coastguard Worker  *
403*0e209d39SAndroid Build Coastguard Worker  * @param ufmtval
404*0e209d39SAndroid Build Coastguard Worker  *         The object containing the formatted string and attributes.
405*0e209d39SAndroid Build Coastguard Worker  * @param ucfpos
406*0e209d39SAndroid Build Coastguard Worker  *         The object used for iteration state; can provide constraints to iterate over only
407*0e209d39SAndroid Build Coastguard Worker  *         one specific category or field;
408*0e209d39SAndroid Build Coastguard Worker  *         see ucfpos_constrainCategory
409*0e209d39SAndroid Build Coastguard Worker  *         and ucfpos_constrainField.
410*0e209d39SAndroid Build Coastguard Worker  * @param ec Set if an error occurs.
411*0e209d39SAndroid Build Coastguard Worker  * @return true if another position was found; false otherwise.
412*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
413*0e209d39SAndroid Build Coastguard Worker  */
414*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
415*0e209d39SAndroid Build Coastguard Worker ufmtval_nextPosition(
416*0e209d39SAndroid Build Coastguard Worker     const UFormattedValue* ufmtval,
417*0e209d39SAndroid Build Coastguard Worker     UConstrainedFieldPosition* ucfpos,
418*0e209d39SAndroid Build Coastguard Worker     UErrorCode* ec);
419*0e209d39SAndroid Build Coastguard Worker 
420*0e209d39SAndroid Build Coastguard Worker 
421*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
422*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
423*0e209d39SAndroid Build Coastguard Worker 
424*0e209d39SAndroid Build Coastguard Worker /**
425*0e209d39SAndroid Build Coastguard Worker  * \class LocalUConstrainedFieldPositionPointer
426*0e209d39SAndroid Build Coastguard Worker  * "Smart pointer" class; closes a UConstrainedFieldPosition via ucfpos_close().
427*0e209d39SAndroid Build Coastguard Worker  * For most methods see the LocalPointerBase base class.
428*0e209d39SAndroid Build Coastguard Worker  *
429*0e209d39SAndroid Build Coastguard Worker  * Usage:
430*0e209d39SAndroid Build Coastguard Worker  *
431*0e209d39SAndroid Build Coastguard Worker  *     LocalUConstrainedFieldPositionPointer ucfpos(ucfpos_open(ec));
432*0e209d39SAndroid Build Coastguard Worker  *     // no need to explicitly call ucfpos_close()
433*0e209d39SAndroid Build Coastguard Worker  *
434*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 64
435*0e209d39SAndroid Build Coastguard Worker  */
436*0e209d39SAndroid Build Coastguard Worker U_DEFINE_LOCAL_OPEN_POINTER(LocalUConstrainedFieldPositionPointer,
437*0e209d39SAndroid Build Coastguard Worker     UConstrainedFieldPosition,
438*0e209d39SAndroid Build Coastguard Worker     ucfpos_close);
439*0e209d39SAndroid Build Coastguard Worker 
440*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
441*0e209d39SAndroid Build Coastguard Worker #endif // U_SHOW_CPLUSPLUS_API
442*0e209d39SAndroid Build Coastguard Worker 
443*0e209d39SAndroid Build Coastguard Worker 
444*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_FORMATTING */
445*0e209d39SAndroid Build Coastguard Worker #endif // __UFORMATTEDVALUE_H__
446