annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/unicode/uset.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 // © 2016 and later: Unicode, Inc. and others.
jpayne@69 2 // License & terms of use: http://www.unicode.org/copyright.html
jpayne@69 3 /*
jpayne@69 4 *******************************************************************************
jpayne@69 5 *
jpayne@69 6 * Copyright (C) 2002-2014, International Business Machines
jpayne@69 7 * Corporation and others. All Rights Reserved.
jpayne@69 8 *
jpayne@69 9 *******************************************************************************
jpayne@69 10 * file name: uset.h
jpayne@69 11 * encoding: UTF-8
jpayne@69 12 * tab size: 8 (not used)
jpayne@69 13 * indentation:4
jpayne@69 14 *
jpayne@69 15 * created on: 2002mar07
jpayne@69 16 * created by: Markus W. Scherer
jpayne@69 17 *
jpayne@69 18 * C version of UnicodeSet.
jpayne@69 19 */
jpayne@69 20
jpayne@69 21
jpayne@69 22 /**
jpayne@69 23 * \file
jpayne@69 24 * \brief C API: Unicode Set
jpayne@69 25 *
jpayne@69 26 * <p>This is a C wrapper around the C++ UnicodeSet class.</p>
jpayne@69 27 */
jpayne@69 28
jpayne@69 29 #ifndef __USET_H__
jpayne@69 30 #define __USET_H__
jpayne@69 31
jpayne@69 32 #include "unicode/utypes.h"
jpayne@69 33 #include "unicode/uchar.h"
jpayne@69 34 #include "unicode/localpointer.h"
jpayne@69 35
jpayne@69 36 #ifndef USET_DEFINED
jpayne@69 37
jpayne@69 38 #ifndef U_IN_DOXYGEN
jpayne@69 39 #define USET_DEFINED
jpayne@69 40 #endif
jpayne@69 41 /**
jpayne@69 42 * USet is the C API type corresponding to C++ class UnicodeSet.
jpayne@69 43 * Use the uset_* API to manipulate. Create with
jpayne@69 44 * uset_open*, and destroy with uset_close.
jpayne@69 45 * @stable ICU 2.4
jpayne@69 46 */
jpayne@69 47 typedef struct USet USet;
jpayne@69 48 #endif
jpayne@69 49
jpayne@69 50 /**
jpayne@69 51 * Bitmask values to be passed to uset_openPatternOptions() or
jpayne@69 52 * uset_applyPattern() taking an option parameter.
jpayne@69 53 * @stable ICU 2.4
jpayne@69 54 */
jpayne@69 55 enum {
jpayne@69 56 /**
jpayne@69 57 * Ignore white space within patterns unless quoted or escaped.
jpayne@69 58 * @stable ICU 2.4
jpayne@69 59 */
jpayne@69 60 USET_IGNORE_SPACE = 1,
jpayne@69 61
jpayne@69 62 /**
jpayne@69 63 * Enable case insensitive matching. E.g., "[ab]" with this flag
jpayne@69 64 * will match 'a', 'A', 'b', and 'B'. "[^ab]" with this flag will
jpayne@69 65 * match all except 'a', 'A', 'b', and 'B'. This performs a full
jpayne@69 66 * closure over case mappings, e.g. U+017F for s.
jpayne@69 67 *
jpayne@69 68 * The resulting set is a superset of the input for the code points but
jpayne@69 69 * not for the strings.
jpayne@69 70 * It performs a case mapping closure of the code points and adds
jpayne@69 71 * full case folding strings for the code points, and reduces strings of
jpayne@69 72 * the original set to their full case folding equivalents.
jpayne@69 73 *
jpayne@69 74 * This is designed for case-insensitive matches, for example
jpayne@69 75 * in regular expressions. The full code point case closure allows checking of
jpayne@69 76 * an input character directly against the closure set.
jpayne@69 77 * Strings are matched by comparing the case-folded form from the closure
jpayne@69 78 * set with an incremental case folding of the string in question.
jpayne@69 79 *
jpayne@69 80 * The closure set will also contain single code points if the original
jpayne@69 81 * set contained case-equivalent strings (like U+00DF for "ss" or "Ss" etc.).
jpayne@69 82 * This is not necessary (that is, redundant) for the above matching method
jpayne@69 83 * but results in the same closure sets regardless of whether the original
jpayne@69 84 * set contained the code point or a string.
jpayne@69 85 *
jpayne@69 86 * @stable ICU 2.4
jpayne@69 87 */
jpayne@69 88 USET_CASE_INSENSITIVE = 2,
jpayne@69 89
jpayne@69 90 /**
jpayne@69 91 * Enable case insensitive matching. E.g., "[ab]" with this flag
jpayne@69 92 * will match 'a', 'A', 'b', and 'B'. "[^ab]" with this flag will
jpayne@69 93 * match all except 'a', 'A', 'b', and 'B'. This adds the lower-,
jpayne@69 94 * title-, and uppercase mappings as well as the case folding
jpayne@69 95 * of each existing element in the set.
jpayne@69 96 * @stable ICU 3.2
jpayne@69 97 */
jpayne@69 98 USET_ADD_CASE_MAPPINGS = 4
jpayne@69 99 };
jpayne@69 100
jpayne@69 101 /**
jpayne@69 102 * Argument values for whether span() and similar functions continue while
jpayne@69 103 * the current character is contained vs. not contained in the set.
jpayne@69 104 *
jpayne@69 105 * The functionality is straightforward for sets with only single code points,
jpayne@69 106 * without strings (which is the common case):
jpayne@69 107 * - USET_SPAN_CONTAINED and USET_SPAN_SIMPLE work the same.
jpayne@69 108 * - USET_SPAN_CONTAINED and USET_SPAN_SIMPLE are inverses of USET_SPAN_NOT_CONTAINED.
jpayne@69 109 * - span() and spanBack() partition any string the same way when
jpayne@69 110 * alternating between span(USET_SPAN_NOT_CONTAINED) and
jpayne@69 111 * span(either "contained" condition).
jpayne@69 112 * - Using a complemented (inverted) set and the opposite span conditions
jpayne@69 113 * yields the same results.
jpayne@69 114 *
jpayne@69 115 * When a set contains multi-code point strings, then these statements may not
jpayne@69 116 * be true, depending on the strings in the set (for example, whether they
jpayne@69 117 * overlap with each other) and the string that is processed.
jpayne@69 118 * For a set with strings:
jpayne@69 119 * - The complement of the set contains the opposite set of code points,
jpayne@69 120 * but the same set of strings.
jpayne@69 121 * Therefore, complementing both the set and the span conditions
jpayne@69 122 * may yield different results.
jpayne@69 123 * - When starting spans at different positions in a string
jpayne@69 124 * (span(s, ...) vs. span(s+1, ...)) the ends of the spans may be different
jpayne@69 125 * because a set string may start before the later position.
jpayne@69 126 * - span(USET_SPAN_SIMPLE) may be shorter than
jpayne@69 127 * span(USET_SPAN_CONTAINED) because it will not recursively try
jpayne@69 128 * all possible paths.
jpayne@69 129 * For example, with a set which contains the three strings "xy", "xya" and "ax",
jpayne@69 130 * span("xyax", USET_SPAN_CONTAINED) will return 4 but
jpayne@69 131 * span("xyax", USET_SPAN_SIMPLE) will return 3.
jpayne@69 132 * span(USET_SPAN_SIMPLE) will never be longer than
jpayne@69 133 * span(USET_SPAN_CONTAINED).
jpayne@69 134 * - With either "contained" condition, span() and spanBack() may partition
jpayne@69 135 * a string in different ways.
jpayne@69 136 * For example, with a set which contains the two strings "ab" and "ba",
jpayne@69 137 * and when processing the string "aba",
jpayne@69 138 * span() will yield contained/not-contained boundaries of { 0, 2, 3 }
jpayne@69 139 * while spanBack() will yield boundaries of { 0, 1, 3 }.
jpayne@69 140 *
jpayne@69 141 * Note: If it is important to get the same boundaries whether iterating forward
jpayne@69 142 * or backward through a string, then either only span() should be used and
jpayne@69 143 * the boundaries cached for backward operation, or an ICU BreakIterator
jpayne@69 144 * could be used.
jpayne@69 145 *
jpayne@69 146 * Note: Unpaired surrogates are treated like surrogate code points.
jpayne@69 147 * Similarly, set strings match only on code point boundaries,
jpayne@69 148 * never in the middle of a surrogate pair.
jpayne@69 149 * Illegal UTF-8 sequences are treated like U+FFFD.
jpayne@69 150 * When processing UTF-8 strings, malformed set strings
jpayne@69 151 * (strings with unpaired surrogates which cannot be converted to UTF-8)
jpayne@69 152 * are ignored.
jpayne@69 153 *
jpayne@69 154 * @stable ICU 3.8
jpayne@69 155 */
jpayne@69 156 typedef enum USetSpanCondition {
jpayne@69 157 /**
jpayne@69 158 * Continues a span() while there is no set element at the current position.
jpayne@69 159 * Increments by one code point at a time.
jpayne@69 160 * Stops before the first set element (character or string).
jpayne@69 161 * (For code points only, this is like while contains(current)==FALSE).
jpayne@69 162 *
jpayne@69 163 * When span() returns, the substring between where it started and the position
jpayne@69 164 * it returned consists only of characters that are not in the set,
jpayne@69 165 * and none of its strings overlap with the span.
jpayne@69 166 *
jpayne@69 167 * @stable ICU 3.8
jpayne@69 168 */
jpayne@69 169 USET_SPAN_NOT_CONTAINED = 0,
jpayne@69 170 /**
jpayne@69 171 * Spans the longest substring that is a concatenation of set elements (characters or strings).
jpayne@69 172 * (For characters only, this is like while contains(current)==TRUE).
jpayne@69 173 *
jpayne@69 174 * When span() returns, the substring between where it started and the position
jpayne@69 175 * it returned consists only of set elements (characters or strings) that are in the set.
jpayne@69 176 *
jpayne@69 177 * If a set contains strings, then the span will be the longest substring for which there
jpayne@69 178 * exists at least one non-overlapping concatenation of set elements (characters or strings).
jpayne@69 179 * This is equivalent to a POSIX regular expression for <code>(OR of each set element)*</code>.
jpayne@69 180 * (Java/ICU/Perl regex stops at the first match of an OR.)
jpayne@69 181 *
jpayne@69 182 * @stable ICU 3.8
jpayne@69 183 */
jpayne@69 184 USET_SPAN_CONTAINED = 1,
jpayne@69 185 /**
jpayne@69 186 * Continues a span() while there is a set element at the current position.
jpayne@69 187 * Increments by the longest matching element at each position.
jpayne@69 188 * (For characters only, this is like while contains(current)==TRUE).
jpayne@69 189 *
jpayne@69 190 * When span() returns, the substring between where it started and the position
jpayne@69 191 * it returned consists only of set elements (characters or strings) that are in the set.
jpayne@69 192 *
jpayne@69 193 * If a set only contains single characters, then this is the same
jpayne@69 194 * as USET_SPAN_CONTAINED.
jpayne@69 195 *
jpayne@69 196 * If a set contains strings, then the span will be the longest substring
jpayne@69 197 * with a match at each position with the longest single set element (character or string).
jpayne@69 198 *
jpayne@69 199 * Use this span condition together with other longest-match algorithms,
jpayne@69 200 * such as ICU converters (ucnv_getUnicodeSet()).
jpayne@69 201 *
jpayne@69 202 * @stable ICU 3.8
jpayne@69 203 */
jpayne@69 204 USET_SPAN_SIMPLE = 2,
jpayne@69 205 #ifndef U_HIDE_DEPRECATED_API
jpayne@69 206 /**
jpayne@69 207 * One more than the last span condition.
jpayne@69 208 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
jpayne@69 209 */
jpayne@69 210 USET_SPAN_CONDITION_COUNT
jpayne@69 211 #endif // U_HIDE_DEPRECATED_API
jpayne@69 212 } USetSpanCondition;
jpayne@69 213
jpayne@69 214 enum {
jpayne@69 215 /**
jpayne@69 216 * Capacity of USerializedSet::staticArray.
jpayne@69 217 * Enough for any single-code point set.
jpayne@69 218 * Also provides padding for nice sizeof(USerializedSet).
jpayne@69 219 * @stable ICU 2.4
jpayne@69 220 */
jpayne@69 221 USET_SERIALIZED_STATIC_ARRAY_CAPACITY=8
jpayne@69 222 };
jpayne@69 223
jpayne@69 224 /**
jpayne@69 225 * A serialized form of a Unicode set. Limited manipulations are
jpayne@69 226 * possible directly on a serialized set. See below.
jpayne@69 227 * @stable ICU 2.4
jpayne@69 228 */
jpayne@69 229 typedef struct USerializedSet {
jpayne@69 230 /**
jpayne@69 231 * The serialized Unicode Set.
jpayne@69 232 * @stable ICU 2.4
jpayne@69 233 */
jpayne@69 234 const uint16_t *array;
jpayne@69 235 /**
jpayne@69 236 * The length of the array that contains BMP characters.
jpayne@69 237 * @stable ICU 2.4
jpayne@69 238 */
jpayne@69 239 int32_t bmpLength;
jpayne@69 240 /**
jpayne@69 241 * The total length of the array.
jpayne@69 242 * @stable ICU 2.4
jpayne@69 243 */
jpayne@69 244 int32_t length;
jpayne@69 245 /**
jpayne@69 246 * A small buffer for the array to reduce memory allocations.
jpayne@69 247 * @stable ICU 2.4
jpayne@69 248 */
jpayne@69 249 uint16_t staticArray[USET_SERIALIZED_STATIC_ARRAY_CAPACITY];
jpayne@69 250 } USerializedSet;
jpayne@69 251
jpayne@69 252 /*********************************************************************
jpayne@69 253 * USet API
jpayne@69 254 *********************************************************************/
jpayne@69 255
jpayne@69 256 /**
jpayne@69 257 * Create an empty USet object.
jpayne@69 258 * Equivalent to uset_open(1, 0).
jpayne@69 259 * @return a newly created USet. The caller must call uset_close() on
jpayne@69 260 * it when done.
jpayne@69 261 * @stable ICU 4.2
jpayne@69 262 */
jpayne@69 263 U_STABLE USet* U_EXPORT2
jpayne@69 264 uset_openEmpty(void);
jpayne@69 265
jpayne@69 266 /**
jpayne@69 267 * Creates a USet object that contains the range of characters
jpayne@69 268 * start..end, inclusive. If <code>start > end</code>
jpayne@69 269 * then an empty set is created (same as using uset_openEmpty()).
jpayne@69 270 * @param start first character of the range, inclusive
jpayne@69 271 * @param end last character of the range, inclusive
jpayne@69 272 * @return a newly created USet. The caller must call uset_close() on
jpayne@69 273 * it when done.
jpayne@69 274 * @stable ICU 2.4
jpayne@69 275 */
jpayne@69 276 U_STABLE USet* U_EXPORT2
jpayne@69 277 uset_open(UChar32 start, UChar32 end);
jpayne@69 278
jpayne@69 279 /**
jpayne@69 280 * Creates a set from the given pattern. See the UnicodeSet class
jpayne@69 281 * description for the syntax of the pattern language.
jpayne@69 282 * @param pattern a string specifying what characters are in the set
jpayne@69 283 * @param patternLength the length of the pattern, or -1 if null
jpayne@69 284 * terminated
jpayne@69 285 * @param ec the error code
jpayne@69 286 * @stable ICU 2.4
jpayne@69 287 */
jpayne@69 288 U_STABLE USet* U_EXPORT2
jpayne@69 289 uset_openPattern(const UChar* pattern, int32_t patternLength,
jpayne@69 290 UErrorCode* ec);
jpayne@69 291
jpayne@69 292 /**
jpayne@69 293 * Creates a set from the given pattern. See the UnicodeSet class
jpayne@69 294 * description for the syntax of the pattern language.
jpayne@69 295 * @param pattern a string specifying what characters are in the set
jpayne@69 296 * @param patternLength the length of the pattern, or -1 if null
jpayne@69 297 * terminated
jpayne@69 298 * @param options bitmask for options to apply to the pattern.
jpayne@69 299 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
jpayne@69 300 * @param ec the error code
jpayne@69 301 * @stable ICU 2.4
jpayne@69 302 */
jpayne@69 303 U_STABLE USet* U_EXPORT2
jpayne@69 304 uset_openPatternOptions(const UChar* pattern, int32_t patternLength,
jpayne@69 305 uint32_t options,
jpayne@69 306 UErrorCode* ec);
jpayne@69 307
jpayne@69 308 /**
jpayne@69 309 * Disposes of the storage used by a USet object. This function should
jpayne@69 310 * be called exactly once for objects returned by uset_open().
jpayne@69 311 * @param set the object to dispose of
jpayne@69 312 * @stable ICU 2.4
jpayne@69 313 */
jpayne@69 314 U_STABLE void U_EXPORT2
jpayne@69 315 uset_close(USet* set);
jpayne@69 316
jpayne@69 317 #if U_SHOW_CPLUSPLUS_API
jpayne@69 318
jpayne@69 319 U_NAMESPACE_BEGIN
jpayne@69 320
jpayne@69 321 /**
jpayne@69 322 * \class LocalUSetPointer
jpayne@69 323 * "Smart pointer" class, closes a USet via uset_close().
jpayne@69 324 * For most methods see the LocalPointerBase base class.
jpayne@69 325 *
jpayne@69 326 * @see LocalPointerBase
jpayne@69 327 * @see LocalPointer
jpayne@69 328 * @stable ICU 4.4
jpayne@69 329 */
jpayne@69 330 U_DEFINE_LOCAL_OPEN_POINTER(LocalUSetPointer, USet, uset_close);
jpayne@69 331
jpayne@69 332 U_NAMESPACE_END
jpayne@69 333
jpayne@69 334 #endif
jpayne@69 335
jpayne@69 336 /**
jpayne@69 337 * Returns a copy of this object.
jpayne@69 338 * If this set is frozen, then the clone will be frozen as well.
jpayne@69 339 * Use uset_cloneAsThawed() for a mutable clone of a frozen set.
jpayne@69 340 * @param set the original set
jpayne@69 341 * @return the newly allocated copy of the set
jpayne@69 342 * @see uset_cloneAsThawed
jpayne@69 343 * @stable ICU 3.8
jpayne@69 344 */
jpayne@69 345 U_STABLE USet * U_EXPORT2
jpayne@69 346 uset_clone(const USet *set);
jpayne@69 347
jpayne@69 348 /**
jpayne@69 349 * Determines whether the set has been frozen (made immutable) or not.
jpayne@69 350 * See the ICU4J Freezable interface for details.
jpayne@69 351 * @param set the set
jpayne@69 352 * @return TRUE/FALSE for whether the set has been frozen
jpayne@69 353 * @see uset_freeze
jpayne@69 354 * @see uset_cloneAsThawed
jpayne@69 355 * @stable ICU 3.8
jpayne@69 356 */
jpayne@69 357 U_STABLE UBool U_EXPORT2
jpayne@69 358 uset_isFrozen(const USet *set);
jpayne@69 359
jpayne@69 360 /**
jpayne@69 361 * Freeze the set (make it immutable).
jpayne@69 362 * Once frozen, it cannot be unfrozen and is therefore thread-safe
jpayne@69 363 * until it is deleted.
jpayne@69 364 * See the ICU4J Freezable interface for details.
jpayne@69 365 * Freezing the set may also make some operations faster, for example
jpayne@69 366 * uset_contains() and uset_span().
jpayne@69 367 * A frozen set will not be modified. (It remains frozen.)
jpayne@69 368 * @param set the set
jpayne@69 369 * @return the same set, now frozen
jpayne@69 370 * @see uset_isFrozen
jpayne@69 371 * @see uset_cloneAsThawed
jpayne@69 372 * @stable ICU 3.8
jpayne@69 373 */
jpayne@69 374 U_STABLE void U_EXPORT2
jpayne@69 375 uset_freeze(USet *set);
jpayne@69 376
jpayne@69 377 /**
jpayne@69 378 * Clone the set and make the clone mutable.
jpayne@69 379 * See the ICU4J Freezable interface for details.
jpayne@69 380 * @param set the set
jpayne@69 381 * @return the mutable clone
jpayne@69 382 * @see uset_freeze
jpayne@69 383 * @see uset_isFrozen
jpayne@69 384 * @see uset_clone
jpayne@69 385 * @stable ICU 3.8
jpayne@69 386 */
jpayne@69 387 U_STABLE USet * U_EXPORT2
jpayne@69 388 uset_cloneAsThawed(const USet *set);
jpayne@69 389
jpayne@69 390 /**
jpayne@69 391 * Causes the USet object to represent the range <code>start - end</code>.
jpayne@69 392 * If <code>start > end</code> then this USet is set to an empty range.
jpayne@69 393 * A frozen set will not be modified.
jpayne@69 394 * @param set the object to set to the given range
jpayne@69 395 * @param start first character in the set, inclusive
jpayne@69 396 * @param end last character in the set, inclusive
jpayne@69 397 * @stable ICU 3.2
jpayne@69 398 */
jpayne@69 399 U_STABLE void U_EXPORT2
jpayne@69 400 uset_set(USet* set,
jpayne@69 401 UChar32 start, UChar32 end);
jpayne@69 402
jpayne@69 403 /**
jpayne@69 404 * Modifies the set to represent the set specified by the given
jpayne@69 405 * pattern. See the UnicodeSet class description for the syntax of
jpayne@69 406 * the pattern language. See also the User Guide chapter about UnicodeSet.
jpayne@69 407 * <em>Empties the set passed before applying the pattern.</em>
jpayne@69 408 * A frozen set will not be modified.
jpayne@69 409 * @param set The set to which the pattern is to be applied.
jpayne@69 410 * @param pattern A pointer to UChar string specifying what characters are in the set.
jpayne@69 411 * The character at pattern[0] must be a '['.
jpayne@69 412 * @param patternLength The length of the UChar string. -1 if NUL terminated.
jpayne@69 413 * @param options A bitmask for options to apply to the pattern.
jpayne@69 414 * Valid options are USET_IGNORE_SPACE and USET_CASE_INSENSITIVE.
jpayne@69 415 * @param status Returns an error if the pattern cannot be parsed.
jpayne@69 416 * @return Upon successful parse, the value is either
jpayne@69 417 * the index of the character after the closing ']'
jpayne@69 418 * of the parsed pattern.
jpayne@69 419 * If the status code indicates failure, then the return value
jpayne@69 420 * is the index of the error in the source.
jpayne@69 421 *
jpayne@69 422 * @stable ICU 2.8
jpayne@69 423 */
jpayne@69 424 U_STABLE int32_t U_EXPORT2
jpayne@69 425 uset_applyPattern(USet *set,
jpayne@69 426 const UChar *pattern, int32_t patternLength,
jpayne@69 427 uint32_t options,
jpayne@69 428 UErrorCode *status);
jpayne@69 429
jpayne@69 430 /**
jpayne@69 431 * Modifies the set to contain those code points which have the given value
jpayne@69 432 * for the given binary or enumerated property, as returned by
jpayne@69 433 * u_getIntPropertyValue. Prior contents of this set are lost.
jpayne@69 434 * A frozen set will not be modified.
jpayne@69 435 *
jpayne@69 436 * @param set the object to contain the code points defined by the property
jpayne@69 437 *
jpayne@69 438 * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
jpayne@69 439 * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
jpayne@69 440 * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
jpayne@69 441 *
jpayne@69 442 * @param value a value in the range u_getIntPropertyMinValue(prop)..
jpayne@69 443 * u_getIntPropertyMaxValue(prop), with one exception. If prop is
jpayne@69 444 * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
jpayne@69 445 * rather a mask value produced by U_GET_GC_MASK(). This allows grouped
jpayne@69 446 * categories such as [:L:] to be represented.
jpayne@69 447 *
jpayne@69 448 * @param ec error code input/output parameter
jpayne@69 449 *
jpayne@69 450 * @stable ICU 3.2
jpayne@69 451 */
jpayne@69 452 U_STABLE void U_EXPORT2
jpayne@69 453 uset_applyIntPropertyValue(USet* set,
jpayne@69 454 UProperty prop, int32_t value, UErrorCode* ec);
jpayne@69 455
jpayne@69 456 /**
jpayne@69 457 * Modifies the set to contain those code points which have the
jpayne@69 458 * given value for the given property. Prior contents of this
jpayne@69 459 * set are lost.
jpayne@69 460 * A frozen set will not be modified.
jpayne@69 461 *
jpayne@69 462 * @param set the object to contain the code points defined by the given
jpayne@69 463 * property and value alias
jpayne@69 464 *
jpayne@69 465 * @param prop a string specifying a property alias, either short or long.
jpayne@69 466 * The name is matched loosely. See PropertyAliases.txt for names and a
jpayne@69 467 * description of loose matching. If the value string is empty, then this
jpayne@69 468 * string is interpreted as either a General_Category value alias, a Script
jpayne@69 469 * value alias, a binary property alias, or a special ID. Special IDs are
jpayne@69 470 * matched loosely and correspond to the following sets:
jpayne@69 471 *
jpayne@69 472 * "ANY" = [\\u0000-\\U0010FFFF],
jpayne@69 473 * "ASCII" = [\\u0000-\\u007F],
jpayne@69 474 * "Assigned" = [:^Cn:].
jpayne@69 475 *
jpayne@69 476 * @param propLength the length of the prop, or -1 if NULL
jpayne@69 477 *
jpayne@69 478 * @param value a string specifying a value alias, either short or long.
jpayne@69 479 * The name is matched loosely. See PropertyValueAliases.txt for names
jpayne@69 480 * and a description of loose matching. In addition to aliases listed,
jpayne@69 481 * numeric values and canonical combining classes may be expressed
jpayne@69 482 * numerically, e.g., ("nv", "0.5") or ("ccc", "220"). The value string
jpayne@69 483 * may also be empty.
jpayne@69 484 *
jpayne@69 485 * @param valueLength the length of the value, or -1 if NULL
jpayne@69 486 *
jpayne@69 487 * @param ec error code input/output parameter
jpayne@69 488 *
jpayne@69 489 * @stable ICU 3.2
jpayne@69 490 */
jpayne@69 491 U_STABLE void U_EXPORT2
jpayne@69 492 uset_applyPropertyAlias(USet* set,
jpayne@69 493 const UChar *prop, int32_t propLength,
jpayne@69 494 const UChar *value, int32_t valueLength,
jpayne@69 495 UErrorCode* ec);
jpayne@69 496
jpayne@69 497 /**
jpayne@69 498 * Return true if the given position, in the given pattern, appears
jpayne@69 499 * to be the start of a UnicodeSet pattern.
jpayne@69 500 *
jpayne@69 501 * @param pattern a string specifying the pattern
jpayne@69 502 * @param patternLength the length of the pattern, or -1 if NULL
jpayne@69 503 * @param pos the given position
jpayne@69 504 * @stable ICU 3.2
jpayne@69 505 */
jpayne@69 506 U_STABLE UBool U_EXPORT2
jpayne@69 507 uset_resemblesPattern(const UChar *pattern, int32_t patternLength,
jpayne@69 508 int32_t pos);
jpayne@69 509
jpayne@69 510 /**
jpayne@69 511 * Returns a string representation of this set. If the result of
jpayne@69 512 * calling this function is passed to a uset_openPattern(), it
jpayne@69 513 * will produce another set that is equal to this one.
jpayne@69 514 * @param set the set
jpayne@69 515 * @param result the string to receive the rules, may be NULL
jpayne@69 516 * @param resultCapacity the capacity of result, may be 0 if result is NULL
jpayne@69 517 * @param escapeUnprintable if TRUE then convert unprintable
jpayne@69 518 * character to their hex escape representations, \\uxxxx or
jpayne@69 519 * \\Uxxxxxxxx. Unprintable characters are those other than
jpayne@69 520 * U+000A, U+0020..U+007E.
jpayne@69 521 * @param ec error code.
jpayne@69 522 * @return length of string, possibly larger than resultCapacity
jpayne@69 523 * @stable ICU 2.4
jpayne@69 524 */
jpayne@69 525 U_STABLE int32_t U_EXPORT2
jpayne@69 526 uset_toPattern(const USet* set,
jpayne@69 527 UChar* result, int32_t resultCapacity,
jpayne@69 528 UBool escapeUnprintable,
jpayne@69 529 UErrorCode* ec);
jpayne@69 530
jpayne@69 531 /**
jpayne@69 532 * Adds the given character to the given USet. After this call,
jpayne@69 533 * uset_contains(set, c) will return TRUE.
jpayne@69 534 * A frozen set will not be modified.
jpayne@69 535 * @param set the object to which to add the character
jpayne@69 536 * @param c the character to add
jpayne@69 537 * @stable ICU 2.4
jpayne@69 538 */
jpayne@69 539 U_STABLE void U_EXPORT2
jpayne@69 540 uset_add(USet* set, UChar32 c);
jpayne@69 541
jpayne@69 542 /**
jpayne@69 543 * Adds all of the elements in the specified set to this set if
jpayne@69 544 * they're not already present. This operation effectively
jpayne@69 545 * modifies this set so that its value is the <i>union</i> of the two
jpayne@69 546 * sets. The behavior of this operation is unspecified if the specified
jpayne@69 547 * collection is modified while the operation is in progress.
jpayne@69 548 * A frozen set will not be modified.
jpayne@69 549 *
jpayne@69 550 * @param set the object to which to add the set
jpayne@69 551 * @param additionalSet the source set whose elements are to be added to this set.
jpayne@69 552 * @stable ICU 2.6
jpayne@69 553 */
jpayne@69 554 U_STABLE void U_EXPORT2
jpayne@69 555 uset_addAll(USet* set, const USet *additionalSet);
jpayne@69 556
jpayne@69 557 /**
jpayne@69 558 * Adds the given range of characters to the given USet. After this call,
jpayne@69 559 * uset_contains(set, start, end) will return TRUE.
jpayne@69 560 * A frozen set will not be modified.
jpayne@69 561 * @param set the object to which to add the character
jpayne@69 562 * @param start the first character of the range to add, inclusive
jpayne@69 563 * @param end the last character of the range to add, inclusive
jpayne@69 564 * @stable ICU 2.2
jpayne@69 565 */
jpayne@69 566 U_STABLE void U_EXPORT2
jpayne@69 567 uset_addRange(USet* set, UChar32 start, UChar32 end);
jpayne@69 568
jpayne@69 569 /**
jpayne@69 570 * Adds the given string to the given USet. After this call,
jpayne@69 571 * uset_containsString(set, str, strLen) will return TRUE.
jpayne@69 572 * A frozen set will not be modified.
jpayne@69 573 * @param set the object to which to add the character
jpayne@69 574 * @param str the string to add
jpayne@69 575 * @param strLen the length of the string or -1 if null terminated.
jpayne@69 576 * @stable ICU 2.4
jpayne@69 577 */
jpayne@69 578 U_STABLE void U_EXPORT2
jpayne@69 579 uset_addString(USet* set, const UChar* str, int32_t strLen);
jpayne@69 580
jpayne@69 581 /**
jpayne@69 582 * Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"}
jpayne@69 583 * If this set already any particular character, it has no effect on that character.
jpayne@69 584 * A frozen set will not be modified.
jpayne@69 585 * @param set the object to which to add the character
jpayne@69 586 * @param str the source string
jpayne@69 587 * @param strLen the length of the string or -1 if null terminated.
jpayne@69 588 * @stable ICU 3.4
jpayne@69 589 */
jpayne@69 590 U_STABLE void U_EXPORT2
jpayne@69 591 uset_addAllCodePoints(USet* set, const UChar *str, int32_t strLen);
jpayne@69 592
jpayne@69 593 /**
jpayne@69 594 * Removes the given character from the given USet. After this call,
jpayne@69 595 * uset_contains(set, c) will return FALSE.
jpayne@69 596 * A frozen set will not be modified.
jpayne@69 597 * @param set the object from which to remove the character
jpayne@69 598 * @param c the character to remove
jpayne@69 599 * @stable ICU 2.4
jpayne@69 600 */
jpayne@69 601 U_STABLE void U_EXPORT2
jpayne@69 602 uset_remove(USet* set, UChar32 c);
jpayne@69 603
jpayne@69 604 /**
jpayne@69 605 * Removes the given range of characters from the given USet. After this call,
jpayne@69 606 * uset_contains(set, start, end) will return FALSE.
jpayne@69 607 * A frozen set will not be modified.
jpayne@69 608 * @param set the object to which to add the character
jpayne@69 609 * @param start the first character of the range to remove, inclusive
jpayne@69 610 * @param end the last character of the range to remove, inclusive
jpayne@69 611 * @stable ICU 2.2
jpayne@69 612 */
jpayne@69 613 U_STABLE void U_EXPORT2
jpayne@69 614 uset_removeRange(USet* set, UChar32 start, UChar32 end);
jpayne@69 615
jpayne@69 616 /**
jpayne@69 617 * Removes the given string to the given USet. After this call,
jpayne@69 618 * uset_containsString(set, str, strLen) will return FALSE.
jpayne@69 619 * A frozen set will not be modified.
jpayne@69 620 * @param set the object to which to add the character
jpayne@69 621 * @param str the string to remove
jpayne@69 622 * @param strLen the length of the string or -1 if null terminated.
jpayne@69 623 * @stable ICU 2.4
jpayne@69 624 */
jpayne@69 625 U_STABLE void U_EXPORT2
jpayne@69 626 uset_removeString(USet* set, const UChar* str, int32_t strLen);
jpayne@69 627
jpayne@69 628 /**
jpayne@69 629 * Removes from this set all of its elements that are contained in the
jpayne@69 630 * specified set. This operation effectively modifies this
jpayne@69 631 * set so that its value is the <i>asymmetric set difference</i> of
jpayne@69 632 * the two sets.
jpayne@69 633 * A frozen set will not be modified.
jpayne@69 634 * @param set the object from which the elements are to be removed
jpayne@69 635 * @param removeSet the object that defines which elements will be
jpayne@69 636 * removed from this set
jpayne@69 637 * @stable ICU 3.2
jpayne@69 638 */
jpayne@69 639 U_STABLE void U_EXPORT2
jpayne@69 640 uset_removeAll(USet* set, const USet* removeSet);
jpayne@69 641
jpayne@69 642 /**
jpayne@69 643 * Retain only the elements in this set that are contained in the
jpayne@69 644 * specified range. If <code>start > end</code> then an empty range is
jpayne@69 645 * retained, leaving the set empty. This is equivalent to
jpayne@69 646 * a boolean logic AND, or a set INTERSECTION.
jpayne@69 647 * A frozen set will not be modified.
jpayne@69 648 *
jpayne@69 649 * @param set the object for which to retain only the specified range
jpayne@69 650 * @param start first character, inclusive, of range to be retained
jpayne@69 651 * to this set.
jpayne@69 652 * @param end last character, inclusive, of range to be retained
jpayne@69 653 * to this set.
jpayne@69 654 * @stable ICU 3.2
jpayne@69 655 */
jpayne@69 656 U_STABLE void U_EXPORT2
jpayne@69 657 uset_retain(USet* set, UChar32 start, UChar32 end);
jpayne@69 658
jpayne@69 659 /**
jpayne@69 660 * Retains only the elements in this set that are contained in the
jpayne@69 661 * specified set. In other words, removes from this set all of
jpayne@69 662 * its elements that are not contained in the specified set. This
jpayne@69 663 * operation effectively modifies this set so that its value is
jpayne@69 664 * the <i>intersection</i> of the two sets.
jpayne@69 665 * A frozen set will not be modified.
jpayne@69 666 *
jpayne@69 667 * @param set the object on which to perform the retain
jpayne@69 668 * @param retain set that defines which elements this set will retain
jpayne@69 669 * @stable ICU 3.2
jpayne@69 670 */
jpayne@69 671 U_STABLE void U_EXPORT2
jpayne@69 672 uset_retainAll(USet* set, const USet* retain);
jpayne@69 673
jpayne@69 674 /**
jpayne@69 675 * Reallocate this objects internal structures to take up the least
jpayne@69 676 * possible space, without changing this object's value.
jpayne@69 677 * A frozen set will not be modified.
jpayne@69 678 *
jpayne@69 679 * @param set the object on which to perfrom the compact
jpayne@69 680 * @stable ICU 3.2
jpayne@69 681 */
jpayne@69 682 U_STABLE void U_EXPORT2
jpayne@69 683 uset_compact(USet* set);
jpayne@69 684
jpayne@69 685 /**
jpayne@69 686 * Inverts this set. This operation modifies this set so that
jpayne@69 687 * its value is its complement. This operation does not affect
jpayne@69 688 * the multicharacter strings, if any.
jpayne@69 689 * A frozen set will not be modified.
jpayne@69 690 * @param set the set
jpayne@69 691 * @stable ICU 2.4
jpayne@69 692 */
jpayne@69 693 U_STABLE void U_EXPORT2
jpayne@69 694 uset_complement(USet* set);
jpayne@69 695
jpayne@69 696 /**
jpayne@69 697 * Complements in this set all elements contained in the specified
jpayne@69 698 * set. Any character in the other set will be removed if it is
jpayne@69 699 * in this set, or will be added if it is not in this set.
jpayne@69 700 * A frozen set will not be modified.
jpayne@69 701 *
jpayne@69 702 * @param set the set with which to complement
jpayne@69 703 * @param complement set that defines which elements will be xor'ed
jpayne@69 704 * from this set.
jpayne@69 705 * @stable ICU 3.2
jpayne@69 706 */
jpayne@69 707 U_STABLE void U_EXPORT2
jpayne@69 708 uset_complementAll(USet* set, const USet* complement);
jpayne@69 709
jpayne@69 710 /**
jpayne@69 711 * Removes all of the elements from this set. This set will be
jpayne@69 712 * empty after this call returns.
jpayne@69 713 * A frozen set will not be modified.
jpayne@69 714 * @param set the set
jpayne@69 715 * @stable ICU 2.4
jpayne@69 716 */
jpayne@69 717 U_STABLE void U_EXPORT2
jpayne@69 718 uset_clear(USet* set);
jpayne@69 719
jpayne@69 720 /**
jpayne@69 721 * Close this set over the given attribute. For the attribute
jpayne@69 722 * USET_CASE, the result is to modify this set so that:
jpayne@69 723 *
jpayne@69 724 * 1. For each character or string 'a' in this set, all strings or
jpayne@69 725 * characters 'b' such that foldCase(a) == foldCase(b) are added
jpayne@69 726 * to this set.
jpayne@69 727 *
jpayne@69 728 * 2. For each string 'e' in the resulting set, if e !=
jpayne@69 729 * foldCase(e), 'e' will be removed.
jpayne@69 730 *
jpayne@69 731 * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}]
jpayne@69 732 *
jpayne@69 733 * (Here foldCase(x) refers to the operation u_strFoldCase, and a
jpayne@69 734 * == b denotes that the contents are the same, not pointer
jpayne@69 735 * comparison.)
jpayne@69 736 *
jpayne@69 737 * A frozen set will not be modified.
jpayne@69 738 *
jpayne@69 739 * @param set the set
jpayne@69 740 *
jpayne@69 741 * @param attributes bitmask for attributes to close over.
jpayne@69 742 * Currently only the USET_CASE bit is supported. Any undefined bits
jpayne@69 743 * are ignored.
jpayne@69 744 * @stable ICU 4.2
jpayne@69 745 */
jpayne@69 746 U_STABLE void U_EXPORT2
jpayne@69 747 uset_closeOver(USet* set, int32_t attributes);
jpayne@69 748
jpayne@69 749 /**
jpayne@69 750 * Remove all strings from this set.
jpayne@69 751 *
jpayne@69 752 * @param set the set
jpayne@69 753 * @stable ICU 4.2
jpayne@69 754 */
jpayne@69 755 U_STABLE void U_EXPORT2
jpayne@69 756 uset_removeAllStrings(USet* set);
jpayne@69 757
jpayne@69 758 /**
jpayne@69 759 * Returns TRUE if the given USet contains no characters and no
jpayne@69 760 * strings.
jpayne@69 761 * @param set the set
jpayne@69 762 * @return true if set is empty
jpayne@69 763 * @stable ICU 2.4
jpayne@69 764 */
jpayne@69 765 U_STABLE UBool U_EXPORT2
jpayne@69 766 uset_isEmpty(const USet* set);
jpayne@69 767
jpayne@69 768 /**
jpayne@69 769 * Returns TRUE if the given USet contains the given character.
jpayne@69 770 * This function works faster with a frozen set.
jpayne@69 771 * @param set the set
jpayne@69 772 * @param c The codepoint to check for within the set
jpayne@69 773 * @return true if set contains c
jpayne@69 774 * @stable ICU 2.4
jpayne@69 775 */
jpayne@69 776 U_STABLE UBool U_EXPORT2
jpayne@69 777 uset_contains(const USet* set, UChar32 c);
jpayne@69 778
jpayne@69 779 /**
jpayne@69 780 * Returns TRUE if the given USet contains all characters c
jpayne@69 781 * where start <= c && c <= end.
jpayne@69 782 * @param set the set
jpayne@69 783 * @param start the first character of the range to test, inclusive
jpayne@69 784 * @param end the last character of the range to test, inclusive
jpayne@69 785 * @return TRUE if set contains the range
jpayne@69 786 * @stable ICU 2.2
jpayne@69 787 */
jpayne@69 788 U_STABLE UBool U_EXPORT2
jpayne@69 789 uset_containsRange(const USet* set, UChar32 start, UChar32 end);
jpayne@69 790
jpayne@69 791 /**
jpayne@69 792 * Returns TRUE if the given USet contains the given string.
jpayne@69 793 * @param set the set
jpayne@69 794 * @param str the string
jpayne@69 795 * @param strLen the length of the string or -1 if null terminated.
jpayne@69 796 * @return true if set contains str
jpayne@69 797 * @stable ICU 2.4
jpayne@69 798 */
jpayne@69 799 U_STABLE UBool U_EXPORT2
jpayne@69 800 uset_containsString(const USet* set, const UChar* str, int32_t strLen);
jpayne@69 801
jpayne@69 802 /**
jpayne@69 803 * Returns the index of the given character within this set, where
jpayne@69 804 * the set is ordered by ascending code point. If the character
jpayne@69 805 * is not in this set, return -1. The inverse of this method is
jpayne@69 806 * <code>charAt()</code>.
jpayne@69 807 * @param set the set
jpayne@69 808 * @param c the character to obtain the index for
jpayne@69 809 * @return an index from 0..size()-1, or -1
jpayne@69 810 * @stable ICU 3.2
jpayne@69 811 */
jpayne@69 812 U_STABLE int32_t U_EXPORT2
jpayne@69 813 uset_indexOf(const USet* set, UChar32 c);
jpayne@69 814
jpayne@69 815 /**
jpayne@69 816 * Returns the character at the given index within this set, where
jpayne@69 817 * the set is ordered by ascending code point. If the index is
jpayne@69 818 * out of range, return (UChar32)-1. The inverse of this method is
jpayne@69 819 * <code>indexOf()</code>.
jpayne@69 820 * @param set the set
jpayne@69 821 * @param charIndex an index from 0..size()-1 to obtain the char for
jpayne@69 822 * @return the character at the given index, or (UChar32)-1.
jpayne@69 823 * @stable ICU 3.2
jpayne@69 824 */
jpayne@69 825 U_STABLE UChar32 U_EXPORT2
jpayne@69 826 uset_charAt(const USet* set, int32_t charIndex);
jpayne@69 827
jpayne@69 828 /**
jpayne@69 829 * Returns the number of characters and strings contained in the given
jpayne@69 830 * USet.
jpayne@69 831 * @param set the set
jpayne@69 832 * @return a non-negative integer counting the characters and strings
jpayne@69 833 * contained in set
jpayne@69 834 * @stable ICU 2.4
jpayne@69 835 */
jpayne@69 836 U_STABLE int32_t U_EXPORT2
jpayne@69 837 uset_size(const USet* set);
jpayne@69 838
jpayne@69 839 /**
jpayne@69 840 * Returns the number of items in this set. An item is either a range
jpayne@69 841 * of characters or a single multicharacter string.
jpayne@69 842 * @param set the set
jpayne@69 843 * @return a non-negative integer counting the character ranges
jpayne@69 844 * and/or strings contained in set
jpayne@69 845 * @stable ICU 2.4
jpayne@69 846 */
jpayne@69 847 U_STABLE int32_t U_EXPORT2
jpayne@69 848 uset_getItemCount(const USet* set);
jpayne@69 849
jpayne@69 850 /**
jpayne@69 851 * Returns an item of this set. An item is either a range of
jpayne@69 852 * characters or a single multicharacter string.
jpayne@69 853 * @param set the set
jpayne@69 854 * @param itemIndex a non-negative integer in the range 0..
jpayne@69 855 * uset_getItemCount(set)-1
jpayne@69 856 * @param start pointer to variable to receive first character
jpayne@69 857 * in range, inclusive
jpayne@69 858 * @param end pointer to variable to receive last character in range,
jpayne@69 859 * inclusive
jpayne@69 860 * @param str buffer to receive the string, may be NULL
jpayne@69 861 * @param strCapacity capacity of str, or 0 if str is NULL
jpayne@69 862 * @param ec error code
jpayne@69 863 * @return the length of the string (>= 2), or 0 if the item is a
jpayne@69 864 * range, in which case it is the range *start..*end, or -1 if
jpayne@69 865 * itemIndex is out of range
jpayne@69 866 * @stable ICU 2.4
jpayne@69 867 */
jpayne@69 868 U_STABLE int32_t U_EXPORT2
jpayne@69 869 uset_getItem(const USet* set, int32_t itemIndex,
jpayne@69 870 UChar32* start, UChar32* end,
jpayne@69 871 UChar* str, int32_t strCapacity,
jpayne@69 872 UErrorCode* ec);
jpayne@69 873
jpayne@69 874 /**
jpayne@69 875 * Returns true if set1 contains all the characters and strings
jpayne@69 876 * of set2. It answers the question, 'Is set1 a superset of set2?'
jpayne@69 877 * @param set1 set to be checked for containment
jpayne@69 878 * @param set2 set to be checked for containment
jpayne@69 879 * @return true if the test condition is met
jpayne@69 880 * @stable ICU 3.2
jpayne@69 881 */
jpayne@69 882 U_STABLE UBool U_EXPORT2
jpayne@69 883 uset_containsAll(const USet* set1, const USet* set2);
jpayne@69 884
jpayne@69 885 /**
jpayne@69 886 * Returns true if this set contains all the characters
jpayne@69 887 * of the given string. This is does not check containment of grapheme
jpayne@69 888 * clusters, like uset_containsString.
jpayne@69 889 * @param set set of characters to be checked for containment
jpayne@69 890 * @param str string containing codepoints to be checked for containment
jpayne@69 891 * @param strLen the length of the string or -1 if null terminated.
jpayne@69 892 * @return true if the test condition is met
jpayne@69 893 * @stable ICU 3.4
jpayne@69 894 */
jpayne@69 895 U_STABLE UBool U_EXPORT2
jpayne@69 896 uset_containsAllCodePoints(const USet* set, const UChar *str, int32_t strLen);
jpayne@69 897
jpayne@69 898 /**
jpayne@69 899 * Returns true if set1 contains none of the characters and strings
jpayne@69 900 * of set2. It answers the question, 'Is set1 a disjoint set of set2?'
jpayne@69 901 * @param set1 set to be checked for containment
jpayne@69 902 * @param set2 set to be checked for containment
jpayne@69 903 * @return true if the test condition is met
jpayne@69 904 * @stable ICU 3.2
jpayne@69 905 */
jpayne@69 906 U_STABLE UBool U_EXPORT2
jpayne@69 907 uset_containsNone(const USet* set1, const USet* set2);
jpayne@69 908
jpayne@69 909 /**
jpayne@69 910 * Returns true if set1 contains some of the characters and strings
jpayne@69 911 * of set2. It answers the question, 'Does set1 and set2 have an intersection?'
jpayne@69 912 * @param set1 set to be checked for containment
jpayne@69 913 * @param set2 set to be checked for containment
jpayne@69 914 * @return true if the test condition is met
jpayne@69 915 * @stable ICU 3.2
jpayne@69 916 */
jpayne@69 917 U_STABLE UBool U_EXPORT2
jpayne@69 918 uset_containsSome(const USet* set1, const USet* set2);
jpayne@69 919
jpayne@69 920 /**
jpayne@69 921 * Returns the length of the initial substring of the input string which
jpayne@69 922 * consists only of characters and strings that are contained in this set
jpayne@69 923 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
jpayne@69 924 * or only of characters and strings that are not contained
jpayne@69 925 * in this set (USET_SPAN_NOT_CONTAINED).
jpayne@69 926 * See USetSpanCondition for details.
jpayne@69 927 * Similar to the strspn() C library function.
jpayne@69 928 * Unpaired surrogates are treated according to contains() of their surrogate code points.
jpayne@69 929 * This function works faster with a frozen set and with a non-negative string length argument.
jpayne@69 930 * @param set the set
jpayne@69 931 * @param s start of the string
jpayne@69 932 * @param length of the string; can be -1 for NUL-terminated
jpayne@69 933 * @param spanCondition specifies the containment condition
jpayne@69 934 * @return the length of the initial substring according to the spanCondition;
jpayne@69 935 * 0 if the start of the string does not fit the spanCondition
jpayne@69 936 * @stable ICU 3.8
jpayne@69 937 * @see USetSpanCondition
jpayne@69 938 */
jpayne@69 939 U_STABLE int32_t U_EXPORT2
jpayne@69 940 uset_span(const USet *set, const UChar *s, int32_t length, USetSpanCondition spanCondition);
jpayne@69 941
jpayne@69 942 /**
jpayne@69 943 * Returns the start of the trailing substring of the input string which
jpayne@69 944 * consists only of characters and strings that are contained in this set
jpayne@69 945 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
jpayne@69 946 * or only of characters and strings that are not contained
jpayne@69 947 * in this set (USET_SPAN_NOT_CONTAINED).
jpayne@69 948 * See USetSpanCondition for details.
jpayne@69 949 * Unpaired surrogates are treated according to contains() of their surrogate code points.
jpayne@69 950 * This function works faster with a frozen set and with a non-negative string length argument.
jpayne@69 951 * @param set the set
jpayne@69 952 * @param s start of the string
jpayne@69 953 * @param length of the string; can be -1 for NUL-terminated
jpayne@69 954 * @param spanCondition specifies the containment condition
jpayne@69 955 * @return the start of the trailing substring according to the spanCondition;
jpayne@69 956 * the string length if the end of the string does not fit the spanCondition
jpayne@69 957 * @stable ICU 3.8
jpayne@69 958 * @see USetSpanCondition
jpayne@69 959 */
jpayne@69 960 U_STABLE int32_t U_EXPORT2
jpayne@69 961 uset_spanBack(const USet *set, const UChar *s, int32_t length, USetSpanCondition spanCondition);
jpayne@69 962
jpayne@69 963 /**
jpayne@69 964 * Returns the length of the initial substring of the input string which
jpayne@69 965 * consists only of characters and strings that are contained in this set
jpayne@69 966 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
jpayne@69 967 * or only of characters and strings that are not contained
jpayne@69 968 * in this set (USET_SPAN_NOT_CONTAINED).
jpayne@69 969 * See USetSpanCondition for details.
jpayne@69 970 * Similar to the strspn() C library function.
jpayne@69 971 * Malformed byte sequences are treated according to contains(0xfffd).
jpayne@69 972 * This function works faster with a frozen set and with a non-negative string length argument.
jpayne@69 973 * @param set the set
jpayne@69 974 * @param s start of the string (UTF-8)
jpayne@69 975 * @param length of the string; can be -1 for NUL-terminated
jpayne@69 976 * @param spanCondition specifies the containment condition
jpayne@69 977 * @return the length of the initial substring according to the spanCondition;
jpayne@69 978 * 0 if the start of the string does not fit the spanCondition
jpayne@69 979 * @stable ICU 3.8
jpayne@69 980 * @see USetSpanCondition
jpayne@69 981 */
jpayne@69 982 U_STABLE int32_t U_EXPORT2
jpayne@69 983 uset_spanUTF8(const USet *set, const char *s, int32_t length, USetSpanCondition spanCondition);
jpayne@69 984
jpayne@69 985 /**
jpayne@69 986 * Returns the start of the trailing substring of the input string which
jpayne@69 987 * consists only of characters and strings that are contained in this set
jpayne@69 988 * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
jpayne@69 989 * or only of characters and strings that are not contained
jpayne@69 990 * in this set (USET_SPAN_NOT_CONTAINED).
jpayne@69 991 * See USetSpanCondition for details.
jpayne@69 992 * Malformed byte sequences are treated according to contains(0xfffd).
jpayne@69 993 * This function works faster with a frozen set and with a non-negative string length argument.
jpayne@69 994 * @param set the set
jpayne@69 995 * @param s start of the string (UTF-8)
jpayne@69 996 * @param length of the string; can be -1 for NUL-terminated
jpayne@69 997 * @param spanCondition specifies the containment condition
jpayne@69 998 * @return the start of the trailing substring according to the spanCondition;
jpayne@69 999 * the string length if the end of the string does not fit the spanCondition
jpayne@69 1000 * @stable ICU 3.8
jpayne@69 1001 * @see USetSpanCondition
jpayne@69 1002 */
jpayne@69 1003 U_STABLE int32_t U_EXPORT2
jpayne@69 1004 uset_spanBackUTF8(const USet *set, const char *s, int32_t length, USetSpanCondition spanCondition);
jpayne@69 1005
jpayne@69 1006 /**
jpayne@69 1007 * Returns true if set1 contains all of the characters and strings
jpayne@69 1008 * of set2, and vis versa. It answers the question, 'Is set1 equal to set2?'
jpayne@69 1009 * @param set1 set to be checked for containment
jpayne@69 1010 * @param set2 set to be checked for containment
jpayne@69 1011 * @return true if the test condition is met
jpayne@69 1012 * @stable ICU 3.2
jpayne@69 1013 */
jpayne@69 1014 U_STABLE UBool U_EXPORT2
jpayne@69 1015 uset_equals(const USet* set1, const USet* set2);
jpayne@69 1016
jpayne@69 1017 /*********************************************************************
jpayne@69 1018 * Serialized set API
jpayne@69 1019 *********************************************************************/
jpayne@69 1020
jpayne@69 1021 /**
jpayne@69 1022 * Serializes this set into an array of 16-bit integers. Serialization
jpayne@69 1023 * (currently) only records the characters in the set; multicharacter
jpayne@69 1024 * strings are ignored.
jpayne@69 1025 *
jpayne@69 1026 * The array
jpayne@69 1027 * has following format (each line is one 16-bit integer):
jpayne@69 1028 *
jpayne@69 1029 * length = (n+2*m) | (m!=0?0x8000:0)
jpayne@69 1030 * bmpLength = n; present if m!=0
jpayne@69 1031 * bmp[0]
jpayne@69 1032 * bmp[1]
jpayne@69 1033 * ...
jpayne@69 1034 * bmp[n-1]
jpayne@69 1035 * supp-high[0]
jpayne@69 1036 * supp-low[0]
jpayne@69 1037 * supp-high[1]
jpayne@69 1038 * supp-low[1]
jpayne@69 1039 * ...
jpayne@69 1040 * supp-high[m-1]
jpayne@69 1041 * supp-low[m-1]
jpayne@69 1042 *
jpayne@69 1043 * The array starts with a header. After the header are n bmp
jpayne@69 1044 * code points, then m supplementary code points. Either n or m
jpayne@69 1045 * or both may be zero. n+2*m is always <= 0x7FFF.
jpayne@69 1046 *
jpayne@69 1047 * If there are no supplementary characters (if m==0) then the
jpayne@69 1048 * header is one 16-bit integer, 'length', with value n.
jpayne@69 1049 *
jpayne@69 1050 * If there are supplementary characters (if m!=0) then the header
jpayne@69 1051 * is two 16-bit integers. The first, 'length', has value
jpayne@69 1052 * (n+2*m)|0x8000. The second, 'bmpLength', has value n.
jpayne@69 1053 *
jpayne@69 1054 * After the header the code points are stored in ascending order.
jpayne@69 1055 * Supplementary code points are stored as most significant 16
jpayne@69 1056 * bits followed by least significant 16 bits.
jpayne@69 1057 *
jpayne@69 1058 * @param set the set
jpayne@69 1059 * @param dest pointer to buffer of destCapacity 16-bit integers.
jpayne@69 1060 * May be NULL only if destCapacity is zero.
jpayne@69 1061 * @param destCapacity size of dest, or zero. Must not be negative.
jpayne@69 1062 * @param pErrorCode pointer to the error code. Will be set to
jpayne@69 1063 * U_INDEX_OUTOFBOUNDS_ERROR if n+2*m > 0x7FFF. Will be set to
jpayne@69 1064 * U_BUFFER_OVERFLOW_ERROR if n+2*m+(m!=0?2:1) > destCapacity.
jpayne@69 1065 * @return the total length of the serialized format, including
jpayne@69 1066 * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
jpayne@69 1067 * than U_BUFFER_OVERFLOW_ERROR.
jpayne@69 1068 * @stable ICU 2.4
jpayne@69 1069 */
jpayne@69 1070 U_STABLE int32_t U_EXPORT2
jpayne@69 1071 uset_serialize(const USet* set, uint16_t* dest, int32_t destCapacity, UErrorCode* pErrorCode);
jpayne@69 1072
jpayne@69 1073 /**
jpayne@69 1074 * Given a serialized array, fill in the given serialized set object.
jpayne@69 1075 * @param fillSet pointer to result
jpayne@69 1076 * @param src pointer to start of array
jpayne@69 1077 * @param srcLength length of array
jpayne@69 1078 * @return true if the given array is valid, otherwise false
jpayne@69 1079 * @stable ICU 2.4
jpayne@69 1080 */
jpayne@69 1081 U_STABLE UBool U_EXPORT2
jpayne@69 1082 uset_getSerializedSet(USerializedSet* fillSet, const uint16_t* src, int32_t srcLength);
jpayne@69 1083
jpayne@69 1084 /**
jpayne@69 1085 * Set the USerializedSet to contain the given character (and nothing
jpayne@69 1086 * else).
jpayne@69 1087 * @param fillSet pointer to result
jpayne@69 1088 * @param c The codepoint to set
jpayne@69 1089 * @stable ICU 2.4
jpayne@69 1090 */
jpayne@69 1091 U_STABLE void U_EXPORT2
jpayne@69 1092 uset_setSerializedToOne(USerializedSet* fillSet, UChar32 c);
jpayne@69 1093
jpayne@69 1094 /**
jpayne@69 1095 * Returns TRUE if the given USerializedSet contains the given
jpayne@69 1096 * character.
jpayne@69 1097 * @param set the serialized set
jpayne@69 1098 * @param c The codepoint to check for within the set
jpayne@69 1099 * @return true if set contains c
jpayne@69 1100 * @stable ICU 2.4
jpayne@69 1101 */
jpayne@69 1102 U_STABLE UBool U_EXPORT2
jpayne@69 1103 uset_serializedContains(const USerializedSet* set, UChar32 c);
jpayne@69 1104
jpayne@69 1105 /**
jpayne@69 1106 * Returns the number of disjoint ranges of characters contained in
jpayne@69 1107 * the given serialized set. Ignores any strings contained in the
jpayne@69 1108 * set.
jpayne@69 1109 * @param set the serialized set
jpayne@69 1110 * @return a non-negative integer counting the character ranges
jpayne@69 1111 * contained in set
jpayne@69 1112 * @stable ICU 2.4
jpayne@69 1113 */
jpayne@69 1114 U_STABLE int32_t U_EXPORT2
jpayne@69 1115 uset_getSerializedRangeCount(const USerializedSet* set);
jpayne@69 1116
jpayne@69 1117 /**
jpayne@69 1118 * Returns a range of characters contained in the given serialized
jpayne@69 1119 * set.
jpayne@69 1120 * @param set the serialized set
jpayne@69 1121 * @param rangeIndex a non-negative integer in the range 0..
jpayne@69 1122 * uset_getSerializedRangeCount(set)-1
jpayne@69 1123 * @param pStart pointer to variable to receive first character
jpayne@69 1124 * in range, inclusive
jpayne@69 1125 * @param pEnd pointer to variable to receive last character in range,
jpayne@69 1126 * inclusive
jpayne@69 1127 * @return true if rangeIndex is valid, otherwise false
jpayne@69 1128 * @stable ICU 2.4
jpayne@69 1129 */
jpayne@69 1130 U_STABLE UBool U_EXPORT2
jpayne@69 1131 uset_getSerializedRange(const USerializedSet* set, int32_t rangeIndex,
jpayne@69 1132 UChar32* pStart, UChar32* pEnd);
jpayne@69 1133
jpayne@69 1134 #endif