jpayne@69: // © 2018 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: jpayne@69: // ucpmap.h jpayne@69: // created: 2018sep03 Markus W. Scherer jpayne@69: jpayne@69: #ifndef __UCPMAP_H__ jpayne@69: #define __UCPMAP_H__ jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: U_CDECL_BEGIN jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * jpayne@69: * This file defines an abstract map from Unicode code points to integer values. jpayne@69: * jpayne@69: * @see UCPMap jpayne@69: * @see UCPTrie jpayne@69: * @see UMutableCPTrie jpayne@69: */ jpayne@69: jpayne@69: /** jpayne@69: * Abstract map from Unicode code points (U+0000..U+10FFFF) to integer values. jpayne@69: * jpayne@69: * @see UCPTrie jpayne@69: * @see UMutableCPTrie jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: typedef struct UCPMap UCPMap; jpayne@69: jpayne@69: /** jpayne@69: * Selectors for how ucpmap_getRange() etc. should report value ranges overlapping with surrogates. jpayne@69: * Most users should use UCPMAP_RANGE_NORMAL. jpayne@69: * jpayne@69: * @see ucpmap_getRange jpayne@69: * @see ucptrie_getRange jpayne@69: * @see umutablecptrie_getRange jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: enum UCPMapRangeOption { jpayne@69: /** jpayne@69: * ucpmap_getRange() enumerates all same-value ranges as stored in the map. jpayne@69: * Most users should use this option. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: UCPMAP_RANGE_NORMAL, jpayne@69: /** jpayne@69: * ucpmap_getRange() enumerates all same-value ranges as stored in the map, jpayne@69: * except that lead surrogates (U+D800..U+DBFF) are treated as having the jpayne@69: * surrogateValue, which is passed to getRange() as a separate parameter. jpayne@69: * The surrogateValue is not transformed via filter(). jpayne@69: * See U_IS_LEAD(c). jpayne@69: * jpayne@69: * Most users should use UCPMAP_RANGE_NORMAL instead. jpayne@69: * jpayne@69: * This option is useful for maps that map surrogate code *units* to jpayne@69: * special values optimized for UTF-16 string processing jpayne@69: * or for special error behavior for unpaired surrogates, jpayne@69: * but those values are not to be associated with the lead surrogate code *points*. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: UCPMAP_RANGE_FIXED_LEAD_SURROGATES, jpayne@69: /** jpayne@69: * ucpmap_getRange() enumerates all same-value ranges as stored in the map, jpayne@69: * except that all surrogates (U+D800..U+DFFF) are treated as having the jpayne@69: * surrogateValue, which is passed to getRange() as a separate parameter. jpayne@69: * The surrogateValue is not transformed via filter(). jpayne@69: * See U_IS_SURROGATE(c). jpayne@69: * jpayne@69: * Most users should use UCPMAP_RANGE_NORMAL instead. jpayne@69: * jpayne@69: * This option is useful for maps that map surrogate code *units* to jpayne@69: * special values optimized for UTF-16 string processing jpayne@69: * or for special error behavior for unpaired surrogates, jpayne@69: * but those values are not to be associated with the lead surrogate code *points*. jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: UCPMAP_RANGE_FIXED_ALL_SURROGATES jpayne@69: }; jpayne@69: #ifndef U_IN_DOXYGEN jpayne@69: typedef enum UCPMapRangeOption UCPMapRangeOption; jpayne@69: #endif jpayne@69: jpayne@69: /** jpayne@69: * Returns the value for a code point as stored in the map, with range checking. jpayne@69: * Returns an implementation-defined error value if c is not in the range 0..U+10FFFF. jpayne@69: * jpayne@69: * @param map the map jpayne@69: * @param c the code point jpayne@69: * @return the map value, jpayne@69: * or an implementation-defined error value if the code point is not in the range 0..U+10FFFF jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: U_CAPI uint32_t U_EXPORT2 jpayne@69: ucpmap_get(const UCPMap *map, UChar32 c); jpayne@69: jpayne@69: /** jpayne@69: * Callback function type: Modifies a map value. jpayne@69: * Optionally called by ucpmap_getRange()/ucptrie_getRange()/umutablecptrie_getRange(). jpayne@69: * The modified value will be returned by the getRange function. jpayne@69: * jpayne@69: * Can be used to ignore some of the value bits, jpayne@69: * make a filter for one of several values, jpayne@69: * return a value index computed from the map value, etc. jpayne@69: * jpayne@69: * @param context an opaque pointer, as passed into the getRange function jpayne@69: * @param value a value from the map jpayne@69: * @return the modified value jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: typedef uint32_t U_CALLCONV jpayne@69: UCPMapValueFilter(const void *context, uint32_t value); jpayne@69: jpayne@69: /** jpayne@69: * Returns the last code point such that all those from start to there have the same value. jpayne@69: * Can be used to efficiently iterate over all same-value ranges in a map. jpayne@69: * (This is normally faster than iterating over code points and get()ting each value, jpayne@69: * but much slower than a data structure that stores ranges directly.) jpayne@69: * jpayne@69: * If the UCPMapValueFilter function pointer is not NULL, then jpayne@69: * the value to be delivered is passed through that function, and the return value is the end jpayne@69: * of the range where all values are modified to the same actual value. jpayne@69: * The value is unchanged if that function pointer is NULL. jpayne@69: * jpayne@69: * Example: jpayne@69: * \code jpayne@69: * UChar32 start = 0, end; jpayne@69: * uint32_t value; jpayne@69: * while ((end = ucpmap_getRange(map, start, UCPMAP_RANGE_NORMAL, 0, jpayne@69: * NULL, NULL, &value)) >= 0) { jpayne@69: * // Work with the range start..end and its value. jpayne@69: * start = end + 1; jpayne@69: * } jpayne@69: * \endcode jpayne@69: * jpayne@69: * @param map the map jpayne@69: * @param start range start jpayne@69: * @param option defines whether surrogates are treated normally, jpayne@69: * or as having the surrogateValue; usually UCPMAP_RANGE_NORMAL jpayne@69: * @param surrogateValue value for surrogates; ignored if option==UCPMAP_RANGE_NORMAL jpayne@69: * @param filter a pointer to a function that may modify the map data value, jpayne@69: * or NULL if the values from the map are to be used unmodified jpayne@69: * @param context an opaque pointer that is passed on to the filter function jpayne@69: * @param pValue if not NULL, receives the value that every code point start..end has; jpayne@69: * may have been modified by filter(context, map value) jpayne@69: * if that function pointer is not NULL jpayne@69: * @return the range end code point, or -1 if start is not a valid code point jpayne@69: * @stable ICU 63 jpayne@69: */ jpayne@69: U_CAPI UChar32 U_EXPORT2 jpayne@69: ucpmap_getRange(const UCPMap *map, UChar32 start, jpayne@69: UCPMapRangeOption option, uint32_t surrogateValue, jpayne@69: UCPMapValueFilter *filter, const void *context, uint32_t *pValue); jpayne@69: jpayne@69: U_CDECL_END jpayne@69: jpayne@69: #endif