uset.h 40 KB

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