xref: /aosp_15_r20/external/icu/libandroidicu/include/unicode/ucpmap.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 // ucpmap.h
5*0e209d39SAndroid Build Coastguard Worker // created: 2018sep03 Markus W. Scherer
6*0e209d39SAndroid Build Coastguard Worker 
7*0e209d39SAndroid Build Coastguard Worker #ifndef __UCPMAP_H__
8*0e209d39SAndroid Build Coastguard Worker #define __UCPMAP_H__
9*0e209d39SAndroid Build Coastguard Worker 
10*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
11*0e209d39SAndroid Build Coastguard Worker 
12*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN
13*0e209d39SAndroid Build Coastguard Worker 
14*0e209d39SAndroid Build Coastguard Worker /**
15*0e209d39SAndroid Build Coastguard Worker  * \file
16*0e209d39SAndroid Build Coastguard Worker  * \brief C API: This file defines an abstract map from Unicode code points to integer values.
17*0e209d39SAndroid Build Coastguard Worker  *
18*0e209d39SAndroid Build Coastguard Worker  * @see UCPMap
19*0e209d39SAndroid Build Coastguard Worker  * @see UCPTrie
20*0e209d39SAndroid Build Coastguard Worker  * @see UMutableCPTrie
21*0e209d39SAndroid Build Coastguard Worker  */
22*0e209d39SAndroid Build Coastguard Worker 
23*0e209d39SAndroid Build Coastguard Worker /**
24*0e209d39SAndroid Build Coastguard Worker  * Abstract map from Unicode code points (U+0000..U+10FFFF) to integer values.
25*0e209d39SAndroid Build Coastguard Worker  *
26*0e209d39SAndroid Build Coastguard Worker  * @see UCPTrie
27*0e209d39SAndroid Build Coastguard Worker  * @see UMutableCPTrie
28*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 63
29*0e209d39SAndroid Build Coastguard Worker  */
30*0e209d39SAndroid Build Coastguard Worker typedef struct UCPMap UCPMap;
31*0e209d39SAndroid Build Coastguard Worker 
32*0e209d39SAndroid Build Coastguard Worker /**
33*0e209d39SAndroid Build Coastguard Worker  * Selectors for how ucpmap_getRange() etc. should report value ranges overlapping with surrogates.
34*0e209d39SAndroid Build Coastguard Worker  * Most users should use UCPMAP_RANGE_NORMAL.
35*0e209d39SAndroid Build Coastguard Worker  *
36*0e209d39SAndroid Build Coastguard Worker  * @see ucpmap_getRange
37*0e209d39SAndroid Build Coastguard Worker  * @see ucptrie_getRange
38*0e209d39SAndroid Build Coastguard Worker  * @see umutablecptrie_getRange
39*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 63
40*0e209d39SAndroid Build Coastguard Worker  */
41*0e209d39SAndroid Build Coastguard Worker enum UCPMapRangeOption {
42*0e209d39SAndroid Build Coastguard Worker     /**
43*0e209d39SAndroid Build Coastguard Worker      * ucpmap_getRange() enumerates all same-value ranges as stored in the map.
44*0e209d39SAndroid Build Coastguard Worker      * Most users should use this option.
45*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 63
46*0e209d39SAndroid Build Coastguard Worker      */
47*0e209d39SAndroid Build Coastguard Worker     UCPMAP_RANGE_NORMAL,
48*0e209d39SAndroid Build Coastguard Worker     /**
49*0e209d39SAndroid Build Coastguard Worker      * ucpmap_getRange() enumerates all same-value ranges as stored in the map,
50*0e209d39SAndroid Build Coastguard Worker      * except that lead surrogates (U+D800..U+DBFF) are treated as having the
51*0e209d39SAndroid Build Coastguard Worker      * surrogateValue, which is passed to getRange() as a separate parameter.
52*0e209d39SAndroid Build Coastguard Worker      * The surrogateValue is not transformed via filter().
53*0e209d39SAndroid Build Coastguard Worker      * See U_IS_LEAD(c).
54*0e209d39SAndroid Build Coastguard Worker      *
55*0e209d39SAndroid Build Coastguard Worker      * Most users should use UCPMAP_RANGE_NORMAL instead.
56*0e209d39SAndroid Build Coastguard Worker      *
57*0e209d39SAndroid Build Coastguard Worker      * This option is useful for maps that map surrogate code *units* to
58*0e209d39SAndroid Build Coastguard Worker      * special values optimized for UTF-16 string processing
59*0e209d39SAndroid Build Coastguard Worker      * or for special error behavior for unpaired surrogates,
60*0e209d39SAndroid Build Coastguard Worker      * but those values are not to be associated with the lead surrogate code *points*.
61*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 63
62*0e209d39SAndroid Build Coastguard Worker      */
63*0e209d39SAndroid Build Coastguard Worker     UCPMAP_RANGE_FIXED_LEAD_SURROGATES,
64*0e209d39SAndroid Build Coastguard Worker     /**
65*0e209d39SAndroid Build Coastguard Worker      * ucpmap_getRange() enumerates all same-value ranges as stored in the map,
66*0e209d39SAndroid Build Coastguard Worker      * except that all surrogates (U+D800..U+DFFF) are treated as having the
67*0e209d39SAndroid Build Coastguard Worker      * surrogateValue, which is passed to getRange() as a separate parameter.
68*0e209d39SAndroid Build Coastguard Worker      * The surrogateValue is not transformed via filter().
69*0e209d39SAndroid Build Coastguard Worker      * See U_IS_SURROGATE(c).
70*0e209d39SAndroid Build Coastguard Worker      *
71*0e209d39SAndroid Build Coastguard Worker      * Most users should use UCPMAP_RANGE_NORMAL instead.
72*0e209d39SAndroid Build Coastguard Worker      *
73*0e209d39SAndroid Build Coastguard Worker      * This option is useful for maps that map surrogate code *units* to
74*0e209d39SAndroid Build Coastguard Worker      * special values optimized for UTF-16 string processing
75*0e209d39SAndroid Build Coastguard Worker      * or for special error behavior for unpaired surrogates,
76*0e209d39SAndroid Build Coastguard Worker      * but those values are not to be associated with the lead surrogate code *points*.
77*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 63
78*0e209d39SAndroid Build Coastguard Worker      */
79*0e209d39SAndroid Build Coastguard Worker     UCPMAP_RANGE_FIXED_ALL_SURROGATES
80*0e209d39SAndroid Build Coastguard Worker };
81*0e209d39SAndroid Build Coastguard Worker #ifndef U_IN_DOXYGEN
82*0e209d39SAndroid Build Coastguard Worker typedef enum UCPMapRangeOption UCPMapRangeOption;
83*0e209d39SAndroid Build Coastguard Worker #endif
84*0e209d39SAndroid Build Coastguard Worker 
85*0e209d39SAndroid Build Coastguard Worker /**
86*0e209d39SAndroid Build Coastguard Worker  * Returns the value for a code point as stored in the map, with range checking.
87*0e209d39SAndroid Build Coastguard Worker  * Returns an implementation-defined error value if c is not in the range 0..U+10FFFF.
88*0e209d39SAndroid Build Coastguard Worker  *
89*0e209d39SAndroid Build Coastguard Worker  * @param map the map
90*0e209d39SAndroid Build Coastguard Worker  * @param c the code point
91*0e209d39SAndroid Build Coastguard Worker  * @return the map value,
92*0e209d39SAndroid Build Coastguard Worker  *         or an implementation-defined error value if the code point is not in the range 0..U+10FFFF
93*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 63
94*0e209d39SAndroid Build Coastguard Worker  */
95*0e209d39SAndroid Build Coastguard Worker U_CAPI uint32_t U_EXPORT2
96*0e209d39SAndroid Build Coastguard Worker ucpmap_get(const UCPMap *map, UChar32 c);
97*0e209d39SAndroid Build Coastguard Worker 
98*0e209d39SAndroid Build Coastguard Worker /**
99*0e209d39SAndroid Build Coastguard Worker  * Callback function type: Modifies a map value.
100*0e209d39SAndroid Build Coastguard Worker  * Optionally called by ucpmap_getRange()/ucptrie_getRange()/umutablecptrie_getRange().
101*0e209d39SAndroid Build Coastguard Worker  * The modified value will be returned by the getRange function.
102*0e209d39SAndroid Build Coastguard Worker  *
103*0e209d39SAndroid Build Coastguard Worker  * Can be used to ignore some of the value bits,
104*0e209d39SAndroid Build Coastguard Worker  * make a filter for one of several values,
105*0e209d39SAndroid Build Coastguard Worker  * return a value index computed from the map value, etc.
106*0e209d39SAndroid Build Coastguard Worker  *
107*0e209d39SAndroid Build Coastguard Worker  * @param context an opaque pointer, as passed into the getRange function
108*0e209d39SAndroid Build Coastguard Worker  * @param value a value from the map
109*0e209d39SAndroid Build Coastguard Worker  * @return the modified value
110*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 63
111*0e209d39SAndroid Build Coastguard Worker  */
112*0e209d39SAndroid Build Coastguard Worker typedef uint32_t U_CALLCONV
113*0e209d39SAndroid Build Coastguard Worker UCPMapValueFilter(const void *context, uint32_t value);
114*0e209d39SAndroid Build Coastguard Worker 
115*0e209d39SAndroid Build Coastguard Worker /**
116*0e209d39SAndroid Build Coastguard Worker  * Returns the last code point such that all those from start to there have the same value.
117*0e209d39SAndroid Build Coastguard Worker  * Can be used to efficiently iterate over all same-value ranges in a map.
118*0e209d39SAndroid Build Coastguard Worker  * (This is normally faster than iterating over code points and get()ting each value,
119*0e209d39SAndroid Build Coastguard Worker  * but much slower than a data structure that stores ranges directly.)
120*0e209d39SAndroid Build Coastguard Worker  *
121*0e209d39SAndroid Build Coastguard Worker  * If the UCPMapValueFilter function pointer is not NULL, then
122*0e209d39SAndroid Build Coastguard Worker  * the value to be delivered is passed through that function, and the return value is the end
123*0e209d39SAndroid Build Coastguard Worker  * of the range where all values are modified to the same actual value.
124*0e209d39SAndroid Build Coastguard Worker  * The value is unchanged if that function pointer is NULL.
125*0e209d39SAndroid Build Coastguard Worker  *
126*0e209d39SAndroid Build Coastguard Worker  * Example:
127*0e209d39SAndroid Build Coastguard Worker  * \code
128*0e209d39SAndroid Build Coastguard Worker  * UChar32 start = 0, end;
129*0e209d39SAndroid Build Coastguard Worker  * uint32_t value;
130*0e209d39SAndroid Build Coastguard Worker  * while ((end = ucpmap_getRange(map, start, UCPMAP_RANGE_NORMAL, 0,
131*0e209d39SAndroid Build Coastguard Worker  *                               NULL, NULL, &value)) >= 0) {
132*0e209d39SAndroid Build Coastguard Worker  *     // Work with the range start..end and its value.
133*0e209d39SAndroid Build Coastguard Worker  *     start = end + 1;
134*0e209d39SAndroid Build Coastguard Worker  * }
135*0e209d39SAndroid Build Coastguard Worker  * \endcode
136*0e209d39SAndroid Build Coastguard Worker  *
137*0e209d39SAndroid Build Coastguard Worker  * @param map the map
138*0e209d39SAndroid Build Coastguard Worker  * @param start range start
139*0e209d39SAndroid Build Coastguard Worker  * @param option defines whether surrogates are treated normally,
140*0e209d39SAndroid Build Coastguard Worker  *               or as having the surrogateValue; usually UCPMAP_RANGE_NORMAL
141*0e209d39SAndroid Build Coastguard Worker  * @param surrogateValue value for surrogates; ignored if option==UCPMAP_RANGE_NORMAL
142*0e209d39SAndroid Build Coastguard Worker  * @param filter a pointer to a function that may modify the map data value,
143*0e209d39SAndroid Build Coastguard Worker  *     or NULL if the values from the map are to be used unmodified
144*0e209d39SAndroid Build Coastguard Worker  * @param context an opaque pointer that is passed on to the filter function
145*0e209d39SAndroid Build Coastguard Worker  * @param pValue if not NULL, receives the value that every code point start..end has;
146*0e209d39SAndroid Build Coastguard Worker  *     may have been modified by filter(context, map value)
147*0e209d39SAndroid Build Coastguard Worker  *     if that function pointer is not NULL
148*0e209d39SAndroid Build Coastguard Worker  * @return the range end code point, or -1 if start is not a valid code point
149*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 63
150*0e209d39SAndroid Build Coastguard Worker  */
151*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2
152*0e209d39SAndroid Build Coastguard Worker ucpmap_getRange(const UCPMap *map, UChar32 start,
153*0e209d39SAndroid Build Coastguard Worker                 UCPMapRangeOption option, uint32_t surrogateValue,
154*0e209d39SAndroid Build Coastguard Worker                 UCPMapValueFilter *filter, const void *context, uint32_t *pValue);
155*0e209d39SAndroid Build Coastguard Worker 
156*0e209d39SAndroid Build Coastguard Worker U_CDECL_END
157*0e209d39SAndroid Build Coastguard Worker 
158*0e209d39SAndroid Build Coastguard Worker #endif
159