uset.h 46 KB

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