1 // © 2018 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
5 // created: 2018sep03 Markus W. Scherer
10 #include "unicode/utypes.h"
12 #ifndef U_HIDE_DRAFT_API
19 * This file defines an abstract map from Unicode code points to integer values.
27 * Abstract map from Unicode code points (U+0000..U+10FFFF) to integer values.
33 typedef struct UCPMap UCPMap
;
36 * Selectors for how ucpmap_getRange() etc. should report value ranges overlapping with surrogates.
37 * Most users should use UCPMAP_RANGE_NORMAL.
39 * @see ucpmap_getRange
40 * @see ucptrie_getRange
41 * @see umutablecptrie_getRange
44 enum UCPMapRangeOption
{
46 * ucpmap_getRange() enumerates all same-value ranges as stored in the map.
47 * Most users should use this option.
52 * ucpmap_getRange() enumerates all same-value ranges as stored in the map,
53 * except that lead surrogates (U+D800..U+DBFF) are treated as having the
54 * surrogateValue, which is passed to getRange() as a separate parameter.
55 * The surrogateValue is not transformed via filter().
58 * Most users should use UCPMAP_RANGE_NORMAL instead.
60 * This option is useful for maps that map surrogate code *units* to
61 * special values optimized for UTF-16 string processing
62 * or for special error behavior for unpaired surrogates,
63 * but those values are not to be associated with the lead surrogate code *points*.
66 UCPMAP_RANGE_FIXED_LEAD_SURROGATES
,
68 * ucpmap_getRange() enumerates all same-value ranges as stored in the map,
69 * except that all surrogates (U+D800..U+DFFF) are treated as having the
70 * surrogateValue, which is passed to getRange() as a separate parameter.
71 * The surrogateValue is not transformed via filter().
72 * See U_IS_SURROGATE(c).
74 * Most users should use UCPMAP_RANGE_NORMAL instead.
76 * This option is useful for maps that map surrogate code *units* to
77 * special values optimized for UTF-16 string processing
78 * or for special error behavior for unpaired surrogates,
79 * but those values are not to be associated with the lead surrogate code *points*.
82 UCPMAP_RANGE_FIXED_ALL_SURROGATES
85 typedef enum UCPMapRangeOption UCPMapRangeOption
;
89 * Returns the value for a code point as stored in the map, with range checking.
90 * Returns an implementation-defined error value if c is not in the range 0..U+10FFFF.
93 * @param c the code point
94 * @return the map value,
95 * or an implementation-defined error value if the code point is not in the range 0..U+10FFFF
98 U_CAPI
uint32_t U_EXPORT2
99 ucpmap_get(const UCPMap
*map
, UChar32 c
);
102 * Callback function type: Modifies a map value.
103 * Optionally called by ucpmap_getRange()/ucptrie_getRange()/umutablecptrie_getRange().
104 * The modified value will be returned by the getRange function.
106 * Can be used to ignore some of the value bits,
107 * make a filter for one of several values,
108 * return a value index computed from the map value, etc.
110 * @param context an opaque pointer, as passed into the getRange function
111 * @param value a value from the map
112 * @return the modified value
115 typedef uint32_t U_CALLCONV
116 UCPMapValueFilter(const void *context
, uint32_t value
);
119 * Returns the last code point such that all those from start to there have the same value.
120 * Can be used to efficiently iterate over all same-value ranges in a map.
121 * (This is normally faster than iterating over code points and get()ting each value,
122 * but much slower than a data structure that stores ranges directly.)
124 * If the UCPMapValueFilter function pointer is not NULL, then
125 * the value to be delivered is passed through that function, and the return value is the end
126 * of the range where all values are modified to the same actual value.
127 * The value is unchanged if that function pointer is NULL.
131 * UChar32 start = 0, end;
133 * while ((end = ucpmap_getRange(map, start, UCPMAP_RANGE_NORMAL, 0,
134 * NULL, NULL, &value)) >= 0) {
135 * // Work with the range start..end and its value.
141 * @param start range start
142 * @param option defines whether surrogates are treated normally,
143 * or as having the surrogateValue; usually UCPMAP_RANGE_NORMAL
144 * @param surrogateValue value for surrogates; ignored if option==UCPMAP_RANGE_NORMAL
145 * @param filter a pointer to a function that may modify the map data value,
146 * or NULL if the values from the map are to be used unmodified
147 * @param context an opaque pointer that is passed on to the filter function
148 * @param pValue if not NULL, receives the value that every code point start..end has;
149 * may have been modified by filter(context, map value)
150 * if that function pointer is not NULL
151 * @return the range end code point, or -1 if start is not a valid code point
154 U_CAPI UChar32 U_EXPORT2
155 ucpmap_getRange(const UCPMap
*map
, UChar32 start
,
156 UCPMapRangeOption option
, uint32_t surrogateValue
,
157 UCPMapValueFilter
*filter
, const void *context
, uint32_t *pValue
);
161 #endif // U_HIDE_DRAFT_API