uniset.h 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ***************************************************************************
  5. * Copyright (C) 1999-2016, International Business Machines Corporation
  6. * and others. All Rights Reserved.
  7. ***************************************************************************
  8. * Date Name Description
  9. * 10/20/99 alan Creation.
  10. ***************************************************************************
  11. */
  12. #ifndef UNICODESET_H
  13. #define UNICODESET_H
  14. #include "unicode/utypes.h"
  15. #if U_SHOW_CPLUSPLUS_API
  16. #include "unicode/ucpmap.h"
  17. #include "unicode/unifilt.h"
  18. #include "unicode/unistr.h"
  19. #include "unicode/uset.h"
  20. /**
  21. * \file
  22. * \brief C++ API: Unicode Set
  23. */
  24. U_NAMESPACE_BEGIN
  25. // Forward Declarations.
  26. class BMPSet;
  27. class ParsePosition;
  28. class RBBIRuleScanner;
  29. class SymbolTable;
  30. class UnicodeSetStringSpan;
  31. class UVector;
  32. class RuleCharacterIterator;
  33. /**
  34. * A mutable set of Unicode characters and multicharacter strings. Objects of this class
  35. * represent <em>character classes</em> used in regular expressions.
  36. * A character specifies a subset of Unicode code points. Legal
  37. * code points are U+0000 to U+10FFFF, inclusive.
  38. *
  39. * <p>The UnicodeSet class is not designed to be subclassed.
  40. *
  41. * <p><code>UnicodeSet</code> supports two APIs. The first is the
  42. * <em>operand</em> API that allows the caller to modify the value of
  43. * a <code>UnicodeSet</code> object. It conforms to Java 2's
  44. * <code>java.util.Set</code> interface, although
  45. * <code>UnicodeSet</code> does not actually implement that
  46. * interface. All methods of <code>Set</code> are supported, with the
  47. * modification that they take a character range or single character
  48. * instead of an <code>Object</code>, and they take a
  49. * <code>UnicodeSet</code> instead of a <code>Collection</code>. The
  50. * operand API may be thought of in terms of boolean logic: a boolean
  51. * OR is implemented by <code>add</code>, a boolean AND is implemented
  52. * by <code>retain</code>, a boolean XOR is implemented by
  53. * <code>complement</code> taking an argument, and a boolean NOT is
  54. * implemented by <code>complement</code> with no argument. In terms
  55. * of traditional set theory function names, <code>add</code> is a
  56. * union, <code>retain</code> is an intersection, <code>remove</code>
  57. * is an asymmetric difference, and <code>complement</code> with no
  58. * argument is a set complement with respect to the superset range
  59. * <code>MIN_VALUE-MAX_VALUE</code>
  60. *
  61. * <p>The second API is the
  62. * <code>applyPattern()</code>/<code>toPattern()</code> API from the
  63. * <code>java.text.Format</code>-derived classes. Unlike the
  64. * methods that add characters, add categories, and control the logic
  65. * of the set, the method <code>applyPattern()</code> sets all
  66. * attributes of a <code>UnicodeSet</code> at once, based on a
  67. * string pattern.
  68. *
  69. * <p><b>Pattern syntax</b></p>
  70. *
  71. * Patterns are accepted by the constructors and the
  72. * <code>applyPattern()</code> methods and returned by the
  73. * <code>toPattern()</code> method. These patterns follow a syntax
  74. * similar to that employed by version 8 regular expression character
  75. * classes. Here are some simple examples:
  76. *
  77. * \htmlonly<blockquote>\endhtmlonly
  78. * <table>
  79. * <tr align="top">
  80. * <td nowrap valign="top" align="left"><code>[]</code></td>
  81. * <td valign="top">No characters</td>
  82. * </tr><tr align="top">
  83. * <td nowrap valign="top" align="left"><code>[a]</code></td>
  84. * <td valign="top">The character 'a'</td>
  85. * </tr><tr align="top">
  86. * <td nowrap valign="top" align="left"><code>[ae]</code></td>
  87. * <td valign="top">The characters 'a' and 'e'</td>
  88. * </tr>
  89. * <tr>
  90. * <td nowrap valign="top" align="left"><code>[a-e]</code></td>
  91. * <td valign="top">The characters 'a' through 'e' inclusive, in Unicode code
  92. * point order</td>
  93. * </tr>
  94. * <tr>
  95. * <td nowrap valign="top" align="left"><code>[\\u4E01]</code></td>
  96. * <td valign="top">The character U+4E01</td>
  97. * </tr>
  98. * <tr>
  99. * <td nowrap valign="top" align="left"><code>[a{ab}{ac}]</code></td>
  100. * <td valign="top">The character 'a' and the multicharacter strings &quot;ab&quot; and
  101. * &quot;ac&quot;</td>
  102. * </tr>
  103. * <tr>
  104. * <td nowrap valign="top" align="left"><code>[\\p{Lu}]</code></td>
  105. * <td valign="top">All characters in the general category Uppercase Letter</td>
  106. * </tr>
  107. * </table>
  108. * \htmlonly</blockquote>\endhtmlonly
  109. *
  110. * Any character may be preceded by a backslash in order to remove any special
  111. * meaning. White space characters, as defined by UCharacter.isWhitespace(), are
  112. * ignored, unless they are escaped.
  113. *
  114. * <p>Property patterns specify a set of characters having a certain
  115. * property as defined by the Unicode standard. Both the POSIX-like
  116. * "[:Lu:]" and the Perl-like syntax "\\p{Lu}" are recognized. For a
  117. * complete list of supported property patterns, see the User's Guide
  118. * for UnicodeSet at
  119. * <a href="https://unicode-org.github.io/icu/userguide/strings/unicodeset">
  120. * https://unicode-org.github.io/icu/userguide/strings/unicodeset</a>.
  121. * Actual determination of property data is defined by the underlying
  122. * Unicode database as implemented by UCharacter.
  123. *
  124. * <p>Patterns specify individual characters, ranges of characters, and
  125. * Unicode property sets. When elements are concatenated, they
  126. * specify their union. To complement a set, place a '^' immediately
  127. * after the opening '['. Property patterns are inverted by modifying
  128. * their delimiters; "[:^foo]" and "\\P{foo}". In any other location,
  129. * '^' has no special meaning.
  130. *
  131. * <p>Since ICU 70, "[^...]", "[:^foo]", "\\P{foo}", and "[:binaryProperty=No:]"
  132. * perform a “code point complement” (all code points minus the original set),
  133. * removing all multicharacter strings,
  134. * equivalent to <code>.complement().removeAllStrings()</code>.
  135. * The complement() API function continues to perform a
  136. * symmetric difference with all code points and thus retains all multicharacter strings.
  137. *
  138. * <p>Ranges are indicated by placing two a '-' between two
  139. * characters, as in "a-z". This specifies the range of all
  140. * characters from the left to the right, in Unicode order. If the
  141. * left character is greater than or equal to the
  142. * right character it is a syntax error. If a '-' occurs as the first
  143. * character after the opening '[' or '[^', or if it occurs as the
  144. * last character before the closing ']', then it is taken as a
  145. * literal. Thus "[a\-b]", "[-ab]", and "[ab-]" all indicate the same
  146. * set of three characters, 'a', 'b', and '-'.
  147. *
  148. * <p>Sets may be intersected using the '&' operator or the asymmetric
  149. * set difference may be taken using the '-' operator, for example,
  150. * "[[:L:]&[\\u0000-\\u0FFF]]" indicates the set of all Unicode letters
  151. * with values less than 4096. Operators ('&' and '|') have equal
  152. * precedence and bind left-to-right. Thus
  153. * "[[:L:]-[a-z]-[\\u0100-\\u01FF]]" is equivalent to
  154. * "[[[:L:]-[a-z]]-[\\u0100-\\u01FF]]". This only really matters for
  155. * difference; intersection is commutative.
  156. *
  157. * <table>
  158. * <tr valign=top><td nowrap><code>[a]</code><td>The set containing 'a'
  159. * <tr valign=top><td nowrap><code>[a-z]</code><td>The set containing 'a'
  160. * through 'z' and all letters in between, in Unicode order
  161. * <tr valign=top><td nowrap><code>[^a-z]</code><td>The set containing
  162. * all characters but 'a' through 'z',
  163. * that is, U+0000 through 'a'-1 and 'z'+1 through U+10FFFF
  164. * <tr valign=top><td nowrap><code>[[<em>pat1</em>][<em>pat2</em>]]</code>
  165. * <td>The union of sets specified by <em>pat1</em> and <em>pat2</em>
  166. * <tr valign=top><td nowrap><code>[[<em>pat1</em>]&[<em>pat2</em>]]</code>
  167. * <td>The intersection of sets specified by <em>pat1</em> and <em>pat2</em>
  168. * <tr valign=top><td nowrap><code>[[<em>pat1</em>]-[<em>pat2</em>]]</code>
  169. * <td>The asymmetric difference of sets specified by <em>pat1</em> and
  170. * <em>pat2</em>
  171. * <tr valign=top><td nowrap><code>[:Lu:] or \\p{Lu}</code>
  172. * <td>The set of characters having the specified
  173. * Unicode property; in
  174. * this case, Unicode uppercase letters
  175. * <tr valign=top><td nowrap><code>[:^Lu:] or \\P{Lu}</code>
  176. * <td>The set of characters <em>not</em> having the given
  177. * Unicode property
  178. * </table>
  179. *
  180. * <p><b>Formal syntax</b></p>
  181. *
  182. * \htmlonly<blockquote>\endhtmlonly
  183. * <table>
  184. * <tr align="top">
  185. * <td nowrap valign="top" align="right"><code>pattern :=&nbsp; </code></td>
  186. * <td valign="top"><code>('[' '^'? item* ']') |
  187. * property</code></td>
  188. * </tr>
  189. * <tr align="top">
  190. * <td nowrap valign="top" align="right"><code>item :=&nbsp; </code></td>
  191. * <td valign="top"><code>char | (char '-' char) | pattern-expr<br>
  192. * </code></td>
  193. * </tr>
  194. * <tr align="top">
  195. * <td nowrap valign="top" align="right"><code>pattern-expr :=&nbsp; </code></td>
  196. * <td valign="top"><code>pattern | pattern-expr pattern |
  197. * pattern-expr op pattern<br>
  198. * </code></td>
  199. * </tr>
  200. * <tr align="top">
  201. * <td nowrap valign="top" align="right"><code>op :=&nbsp; </code></td>
  202. * <td valign="top"><code>'&amp;' | '-'<br>
  203. * </code></td>
  204. * </tr>
  205. * <tr align="top">
  206. * <td nowrap valign="top" align="right"><code>special :=&nbsp; </code></td>
  207. * <td valign="top"><code>'[' | ']' | '-'<br>
  208. * </code></td>
  209. * </tr>
  210. * <tr align="top">
  211. * <td nowrap valign="top" align="right"><code>char :=&nbsp; </code></td>
  212. * <td valign="top"><em>any character that is not</em><code> special<br>
  213. * | ('\' </code><em>any character</em><code>)<br>
  214. * | ('\\u' hex hex hex hex)<br>
  215. * </code></td>
  216. * </tr>
  217. * <tr align="top">
  218. * <td nowrap valign="top" align="right"><code>hex :=&nbsp; </code></td>
  219. * <td valign="top"><code>'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |<br>
  220. * &nbsp;&nbsp;&nbsp;&nbsp;'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'</code></td>
  221. * </tr>
  222. * <tr>
  223. * <td nowrap valign="top" align="right"><code>property :=&nbsp; </code></td>
  224. * <td valign="top"><em>a Unicode property set pattern</em></td>
  225. * </tr>
  226. * </table>
  227. * <br>
  228. * <table border="1">
  229. * <tr>
  230. * <td>Legend: <table>
  231. * <tr>
  232. * <td nowrap valign="top"><code>a := b</code></td>
  233. * <td width="20" valign="top">&nbsp; </td>
  234. * <td valign="top"><code>a</code> may be replaced by <code>b</code> </td>
  235. * </tr>
  236. * <tr>
  237. * <td nowrap valign="top"><code>a?</code></td>
  238. * <td valign="top"></td>
  239. * <td valign="top">zero or one instance of <code>a</code><br>
  240. * </td>
  241. * </tr>
  242. * <tr>
  243. * <td nowrap valign="top"><code>a*</code></td>
  244. * <td valign="top"></td>
  245. * <td valign="top">one or more instances of <code>a</code><br>
  246. * </td>
  247. * </tr>
  248. * <tr>
  249. * <td nowrap valign="top"><code>a | b</code></td>
  250. * <td valign="top"></td>
  251. * <td valign="top">either <code>a</code> or <code>b</code><br>
  252. * </td>
  253. * </tr>
  254. * <tr>
  255. * <td nowrap valign="top"><code>'a'</code></td>
  256. * <td valign="top"></td>
  257. * <td valign="top">the literal string between the quotes </td>
  258. * </tr>
  259. * </table>
  260. * </td>
  261. * </tr>
  262. * </table>
  263. * \htmlonly</blockquote>\endhtmlonly
  264. *
  265. * <p>Note:
  266. * - Most UnicodeSet methods do not take a UErrorCode parameter because
  267. * there are usually very few opportunities for failure other than a shortage
  268. * of memory, error codes in low-level C++ string methods would be inconvenient,
  269. * and the error code as the last parameter (ICU convention) would prevent
  270. * the use of default parameter values.
  271. * Instead, such methods set the UnicodeSet into a "bogus" state
  272. * (see isBogus()) if an error occurs.
  273. *
  274. * @author Alan Liu
  275. * @stable ICU 2.0
  276. */
  277. class U_COMMON_API UnicodeSet final : public UnicodeFilter {
  278. private:
  279. /**
  280. * Enough for sets with few ranges.
  281. * For example, White_Space has 10 ranges, list length 21.
  282. */
  283. static constexpr int32_t INITIAL_CAPACITY = 25;
  284. // fFlags constant
  285. static constexpr uint8_t kIsBogus = 1; // This set is bogus (i.e. not valid)
  286. UChar32* list = stackList; // MUST be terminated with HIGH
  287. int32_t capacity = INITIAL_CAPACITY; // capacity of list
  288. int32_t len = 1; // length of list used; 1 <= len <= capacity
  289. uint8_t fFlags = 0; // Bit flag (see constants above)
  290. BMPSet *bmpSet = nullptr; // The set is frozen iff either bmpSet or stringSpan is not nullptr.
  291. UChar32* buffer = nullptr; // internal buffer, may be nullptr
  292. int32_t bufferCapacity = 0; // capacity of buffer
  293. /**
  294. * The pattern representation of this set. This may not be the
  295. * most economical pattern. It is the pattern supplied to
  296. * applyPattern(), with variables substituted and whitespace
  297. * removed. For sets constructed without applyPattern(), or
  298. * modified using the non-pattern API, this string will be empty,
  299. * indicating that toPattern() must generate a pattern
  300. * representation from the inversion list.
  301. */
  302. char16_t *pat = nullptr;
  303. int32_t patLen = 0;
  304. UVector* strings = nullptr; // maintained in sorted order
  305. UnicodeSetStringSpan *stringSpan = nullptr;
  306. /**
  307. * Initial list array.
  308. * Avoids some heap allocations, and list is never nullptr.
  309. * Increases the object size a bit.
  310. */
  311. UChar32 stackList[INITIAL_CAPACITY];
  312. public:
  313. /**
  314. * Determine if this object contains a valid set.
  315. * A bogus set has no value. It is different from an empty set.
  316. * It can be used to indicate that no set value is available.
  317. *
  318. * @return true if the set is bogus/invalid, false otherwise
  319. * @see setToBogus()
  320. * @stable ICU 4.0
  321. */
  322. inline UBool isBogus() const;
  323. /**
  324. * Make this UnicodeSet object invalid.
  325. * The string will test true with isBogus().
  326. *
  327. * A bogus set has no value. It is different from an empty set.
  328. * It can be used to indicate that no set value is available.
  329. *
  330. * This utility function is used throughout the UnicodeSet
  331. * implementation to indicate that a UnicodeSet operation failed,
  332. * and may be used in other functions,
  333. * especially but not exclusively when such functions do not
  334. * take a UErrorCode for simplicity.
  335. *
  336. * @see isBogus()
  337. * @stable ICU 4.0
  338. */
  339. void setToBogus();
  340. public:
  341. enum {
  342. /**
  343. * Minimum value that can be stored in a UnicodeSet.
  344. * @stable ICU 2.4
  345. */
  346. MIN_VALUE = 0,
  347. /**
  348. * Maximum value that can be stored in a UnicodeSet.
  349. * @stable ICU 2.4
  350. */
  351. MAX_VALUE = 0x10ffff
  352. };
  353. //----------------------------------------------------------------
  354. // Constructors &c
  355. //----------------------------------------------------------------
  356. public:
  357. /**
  358. * Constructs an empty set.
  359. * @stable ICU 2.0
  360. */
  361. UnicodeSet();
  362. /**
  363. * Constructs a set containing the given range. If <code>end <
  364. * start</code> then an empty set is created.
  365. *
  366. * @param start first character, inclusive, of range
  367. * @param end last character, inclusive, of range
  368. * @stable ICU 2.4
  369. */
  370. UnicodeSet(UChar32 start, UChar32 end);
  371. #ifndef U_HIDE_INTERNAL_API
  372. /**
  373. * @internal
  374. */
  375. enum ESerialization {
  376. kSerialized /* result of serialize() */
  377. };
  378. /**
  379. * Constructs a set from the output of serialize().
  380. *
  381. * @param buffer the 16 bit array
  382. * @param bufferLen the original length returned from serialize()
  383. * @param serialization the value 'kSerialized'
  384. * @param status error code
  385. *
  386. * @internal
  387. */
  388. UnicodeSet(const uint16_t buffer[], int32_t bufferLen,
  389. ESerialization serialization, UErrorCode &status);
  390. #endif /* U_HIDE_INTERNAL_API */
  391. /**
  392. * Constructs a set from the given pattern. See the class
  393. * description for the syntax of the pattern language.
  394. * @param pattern a string specifying what characters are in the set
  395. * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
  396. * contains a syntax error.
  397. * @stable ICU 2.0
  398. */
  399. UnicodeSet(const UnicodeString& pattern,
  400. UErrorCode& status);
  401. #ifndef U_HIDE_INTERNAL_API
  402. /**
  403. * Constructs a set from the given pattern. See the class
  404. * description for the syntax of the pattern language.
  405. * @param pattern a string specifying what characters are in the set
  406. * @param options bitmask for options to apply to the pattern.
  407. * Valid options are USET_IGNORE_SPACE and
  408. * at most one of USET_CASE_INSENSITIVE, USET_ADD_CASE_MAPPINGS, USET_SIMPLE_CASE_INSENSITIVE.
  409. * These case options are mutually exclusive.
  410. * @param symbols a symbol table mapping variable names to values
  411. * and stand-in characters to UnicodeSets; may be nullptr
  412. * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
  413. * contains a syntax error.
  414. * @internal
  415. */
  416. UnicodeSet(const UnicodeString& pattern,
  417. uint32_t options,
  418. const SymbolTable* symbols,
  419. UErrorCode& status);
  420. #endif /* U_HIDE_INTERNAL_API */
  421. /**
  422. * Constructs a set from the given pattern. See the class description
  423. * for the syntax of the pattern language.
  424. * @param pattern a string specifying what characters are in the set
  425. * @param pos on input, the position in pattern at which to start parsing.
  426. * On output, the position after the last character parsed.
  427. * @param options bitmask for options to apply to the pattern.
  428. * Valid options are USET_IGNORE_SPACE and
  429. * at most one of USET_CASE_INSENSITIVE, USET_ADD_CASE_MAPPINGS, USET_SIMPLE_CASE_INSENSITIVE.
  430. * These case options are mutually exclusive.
  431. * @param symbols a symbol table mapping variable names to values
  432. * and stand-in characters to UnicodeSets; may be nullptr
  433. * @param status input-output error code
  434. * @stable ICU 2.8
  435. */
  436. UnicodeSet(const UnicodeString& pattern, ParsePosition& pos,
  437. uint32_t options,
  438. const SymbolTable* symbols,
  439. UErrorCode& status);
  440. /**
  441. * Constructs a set that is identical to the given UnicodeSet.
  442. * @stable ICU 2.0
  443. */
  444. UnicodeSet(const UnicodeSet& o);
  445. /**
  446. * Destructs the set.
  447. * @stable ICU 2.0
  448. */
  449. virtual ~UnicodeSet();
  450. /**
  451. * Assigns this object to be a copy of another.
  452. * A frozen set will not be modified.
  453. * @stable ICU 2.0
  454. */
  455. UnicodeSet& operator=(const UnicodeSet& o);
  456. /**
  457. * Compares the specified object with this set for equality. Returns
  458. * <tt>true</tt> if the two sets
  459. * have the same size, and every member of the specified set is
  460. * contained in this set (or equivalently, every member of this set is
  461. * contained in the specified set).
  462. *
  463. * @param o set to be compared for equality with this set.
  464. * @return <tt>true</tt> if the specified set is equal to this set.
  465. * @stable ICU 2.0
  466. */
  467. virtual bool operator==(const UnicodeSet& o) const;
  468. /**
  469. * Compares the specified object with this set for equality. Returns
  470. * <tt>true</tt> if the specified set is not equal to this set.
  471. * @stable ICU 2.0
  472. */
  473. inline bool operator!=(const UnicodeSet& o) const;
  474. /**
  475. * Returns a copy of this object. All UnicodeFunctor objects have
  476. * to support cloning in order to allow classes using
  477. * UnicodeFunctors, such as Transliterator, to implement cloning.
  478. * If this set is frozen, then the clone will be frozen as well.
  479. * Use cloneAsThawed() for a mutable clone of a frozen set.
  480. * @see cloneAsThawed
  481. * @stable ICU 2.0
  482. */
  483. virtual UnicodeSet* clone() const override;
  484. /**
  485. * Returns the hash code value for this set.
  486. *
  487. * @return the hash code value for this set.
  488. * @see Object#hashCode()
  489. * @stable ICU 2.0
  490. */
  491. virtual int32_t hashCode() const;
  492. /**
  493. * Get a UnicodeSet pointer from a USet
  494. *
  495. * @param uset a USet (the ICU plain C type for UnicodeSet)
  496. * @return the corresponding UnicodeSet pointer.
  497. *
  498. * @stable ICU 4.2
  499. */
  500. inline static UnicodeSet *fromUSet(USet *uset);
  501. /**
  502. * Get a UnicodeSet pointer from a const USet
  503. *
  504. * @param uset a const USet (the ICU plain C type for UnicodeSet)
  505. * @return the corresponding UnicodeSet pointer.
  506. *
  507. * @stable ICU 4.2
  508. */
  509. inline static const UnicodeSet *fromUSet(const USet *uset);
  510. /**
  511. * Produce a USet * pointer for this UnicodeSet.
  512. * USet is the plain C type for UnicodeSet
  513. *
  514. * @return a USet pointer for this UnicodeSet
  515. * @stable ICU 4.2
  516. */
  517. inline USet *toUSet();
  518. /**
  519. * Produce a const USet * pointer for this UnicodeSet.
  520. * USet is the plain C type for UnicodeSet
  521. *
  522. * @return a const USet pointer for this UnicodeSet
  523. * @stable ICU 4.2
  524. */
  525. inline const USet * toUSet() const;
  526. //----------------------------------------------------------------
  527. // Freezable API
  528. //----------------------------------------------------------------
  529. /**
  530. * Determines whether the set has been frozen (made immutable) or not.
  531. * See the ICU4J Freezable interface for details.
  532. * @return true/false for whether the set has been frozen
  533. * @see freeze
  534. * @see cloneAsThawed
  535. * @stable ICU 3.8
  536. */
  537. inline UBool isFrozen() const;
  538. /**
  539. * Freeze the set (make it immutable).
  540. * Once frozen, it cannot be unfrozen and is therefore thread-safe
  541. * until it is deleted.
  542. * See the ICU4J Freezable interface for details.
  543. * Freezing the set may also make some operations faster, for example
  544. * contains() and span().
  545. * A frozen set will not be modified. (It remains frozen.)
  546. * @return this set.
  547. * @see isFrozen
  548. * @see cloneAsThawed
  549. * @stable ICU 3.8
  550. */
  551. UnicodeSet *freeze();
  552. /**
  553. * Clone the set and make the clone mutable.
  554. * See the ICU4J Freezable interface for details.
  555. * @return the mutable clone
  556. * @see freeze
  557. * @see isFrozen
  558. * @stable ICU 3.8
  559. */
  560. UnicodeSet *cloneAsThawed() const;
  561. //----------------------------------------------------------------
  562. // Public API
  563. //----------------------------------------------------------------
  564. /**
  565. * Make this object represent the range `start - end`.
  566. * If `start > end` then this object is set to an empty range.
  567. * A frozen set will not be modified.
  568. *
  569. * @param start first character in the set, inclusive
  570. * @param end last character in the set, inclusive
  571. * @stable ICU 2.4
  572. */
  573. UnicodeSet& set(UChar32 start, UChar32 end);
  574. /**
  575. * Return true if the given position, in the given pattern, appears
  576. * to be the start of a UnicodeSet pattern.
  577. * @stable ICU 2.4
  578. */
  579. static UBool resemblesPattern(const UnicodeString& pattern,
  580. int32_t pos);
  581. /**
  582. * Modifies this set to represent the set specified by the given
  583. * pattern, ignoring Unicode Pattern_White_Space characters.
  584. * See the class description for the syntax of the pattern language.
  585. * A frozen set will not be modified.
  586. * @param pattern a string specifying what characters are in the set
  587. * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
  588. * contains a syntax error.
  589. * <em> Empties the set passed before applying the pattern.</em>
  590. * @return a reference to this
  591. * @stable ICU 2.0
  592. */
  593. UnicodeSet& applyPattern(const UnicodeString& pattern,
  594. UErrorCode& status);
  595. #ifndef U_HIDE_INTERNAL_API
  596. /**
  597. * Modifies this set to represent the set specified by the given
  598. * pattern, optionally ignoring Unicode Pattern_White_Space characters.
  599. * See the class description for the syntax of the pattern language.
  600. * A frozen set will not be modified.
  601. * @param pattern a string specifying what characters are in the set
  602. * @param options bitmask for options to apply to the pattern.
  603. * Valid options are USET_IGNORE_SPACE and
  604. * at most one of USET_CASE_INSENSITIVE, USET_ADD_CASE_MAPPINGS, USET_SIMPLE_CASE_INSENSITIVE.
  605. * These case options are mutually exclusive.
  606. * @param symbols a symbol table mapping variable names to
  607. * values and stand-ins to UnicodeSets; may be nullptr
  608. * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
  609. * contains a syntax error.
  610. *<em> Empties the set passed before applying the pattern.</em>
  611. * @return a reference to this
  612. * @internal
  613. */
  614. UnicodeSet& applyPattern(const UnicodeString& pattern,
  615. uint32_t options,
  616. const SymbolTable* symbols,
  617. UErrorCode& status);
  618. #endif /* U_HIDE_INTERNAL_API */
  619. /**
  620. * Parses the given pattern, starting at the given position. The
  621. * character at pattern.charAt(pos.getIndex()) must be '[', or the
  622. * parse fails. Parsing continues until the corresponding closing
  623. * ']'. If a syntax error is encountered between the opening and
  624. * closing brace, the parse fails. Upon return from a successful
  625. * parse, the ParsePosition is updated to point to the character
  626. * following the closing ']', and a StringBuffer containing a
  627. * pairs list for the parsed pattern is returned. This method calls
  628. * itself recursively to parse embedded subpatterns.
  629. *<em> Empties the set passed before applying the pattern.</em>
  630. * A frozen set will not be modified.
  631. *
  632. * @param pattern the string containing the pattern to be parsed.
  633. * The portion of the string from pos.getIndex(), which must be a
  634. * '[', to the corresponding closing ']', is parsed.
  635. * @param pos upon entry, the position at which to being parsing.
  636. * The character at pattern.charAt(pos.getIndex()) must be a '['.
  637. * Upon return from a successful parse, pos.getIndex() is either
  638. * the character after the closing ']' of the parsed pattern, or
  639. * pattern.length() if the closing ']' is the last character of
  640. * the pattern string.
  641. * @param options bitmask for options to apply to the pattern.
  642. * Valid options are USET_IGNORE_SPACE and
  643. * at most one of USET_CASE_INSENSITIVE, USET_ADD_CASE_MAPPINGS, USET_SIMPLE_CASE_INSENSITIVE.
  644. * These case options are mutually exclusive.
  645. * @param symbols a symbol table mapping variable names to
  646. * values and stand-ins to UnicodeSets; may be nullptr
  647. * @param status returns <code>U_ILLEGAL_ARGUMENT_ERROR</code> if the pattern
  648. * contains a syntax error.
  649. * @return a reference to this
  650. * @stable ICU 2.8
  651. */
  652. UnicodeSet& applyPattern(const UnicodeString& pattern,
  653. ParsePosition& pos,
  654. uint32_t options,
  655. const SymbolTable* symbols,
  656. UErrorCode& status);
  657. /**
  658. * Returns a string representation of this set. If the result of
  659. * calling this function is passed to a UnicodeSet constructor, it
  660. * will produce another set that is equal to this one.
  661. * A frozen set will not be modified.
  662. * @param result the string to receive the rules. Previous
  663. * contents will be deleted.
  664. * @param escapeUnprintable if true then convert unprintable
  665. * character to their hex escape representations, \\uxxxx or
  666. * \\Uxxxxxxxx. Unprintable characters are those other than
  667. * U+000A, U+0020..U+007E.
  668. * @stable ICU 2.0
  669. */
  670. virtual UnicodeString& toPattern(UnicodeString& result,
  671. UBool escapeUnprintable = false) const override;
  672. /**
  673. * Modifies this set to contain those code points which have the given value
  674. * for the given binary or enumerated property, as returned by
  675. * u_getIntPropertyValue. Prior contents of this set are lost.
  676. * A frozen set will not be modified.
  677. *
  678. * @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
  679. * or UCHAR_INT_START..UCHAR_INT_LIMIT-1
  680. * or UCHAR_MASK_START..UCHAR_MASK_LIMIT-1.
  681. *
  682. * @param value a value in the range u_getIntPropertyMinValue(prop)..
  683. * u_getIntPropertyMaxValue(prop), with one exception. If prop is
  684. * UCHAR_GENERAL_CATEGORY_MASK, then value should not be a UCharCategory, but
  685. * rather a mask value produced by U_GET_GC_MASK(). This allows grouped
  686. * categories such as [:L:] to be represented.
  687. *
  688. * @param ec error code input/output parameter
  689. *
  690. * @return a reference to this set
  691. *
  692. * @stable ICU 2.4
  693. */
  694. UnicodeSet& applyIntPropertyValue(UProperty prop,
  695. int32_t value,
  696. UErrorCode& ec);
  697. /**
  698. * Modifies this set to contain those code points which have the
  699. * given value for the given property. Prior contents of this
  700. * set are lost.
  701. * A frozen set will not be modified.
  702. *
  703. * @param prop a property alias, either short or long. The name is matched
  704. * loosely. See PropertyAliases.txt for names and a description of loose
  705. * matching. If the value string is empty, then this string is interpreted
  706. * as either a General_Category value alias, a Script value alias, a binary
  707. * property alias, or a special ID. Special IDs are matched loosely and
  708. * correspond to the following sets:
  709. *
  710. * "ANY" = [\\u0000-\\U0010FFFF],
  711. * "ASCII" = [\\u0000-\\u007F],
  712. * "Assigned" = [:^Cn:].
  713. *
  714. * @param value a value alias, either short or long. The name is matched
  715. * loosely. See PropertyValueAliases.txt for names and a description of
  716. * loose matching. In addition to aliases listed, numeric values and
  717. * canonical combining classes may be expressed numerically, e.g., ("nv",
  718. * "0.5") or ("ccc", "220"). The value string may also be empty.
  719. *
  720. * @param ec error code input/output parameter
  721. *
  722. * @return a reference to this set
  723. *
  724. * @stable ICU 2.4
  725. */
  726. UnicodeSet& applyPropertyAlias(const UnicodeString& prop,
  727. const UnicodeString& value,
  728. UErrorCode& ec);
  729. /**
  730. * Returns the number of elements in this set (its cardinality).
  731. * Note than the elements of a set may include both individual
  732. * codepoints and strings.
  733. *
  734. * This is slower than getRangeCount() because
  735. * it counts the code points of all ranges.
  736. *
  737. * @return the number of elements in this set (its cardinality).
  738. * @stable ICU 2.0
  739. * @see getRangeCount
  740. */
  741. virtual int32_t size() const;
  742. /**
  743. * Returns <tt>true</tt> if this set contains no elements.
  744. *
  745. * @return <tt>true</tt> if this set contains no elements.
  746. * @stable ICU 2.0
  747. */
  748. virtual UBool isEmpty() const;
  749. /**
  750. * @return true if this set contains multi-character strings or the empty string.
  751. * @stable ICU 70
  752. */
  753. UBool hasStrings() const;
  754. /**
  755. * Returns true if this set contains the given character.
  756. * This function works faster with a frozen set.
  757. * @param c character to be checked for containment
  758. * @return true if the test condition is met
  759. * @stable ICU 2.0
  760. */
  761. virtual UBool contains(UChar32 c) const override;
  762. /**
  763. * Returns true if this set contains every character
  764. * of the given range.
  765. * @param start first character, inclusive, of the range
  766. * @param end last character, inclusive, of the range
  767. * @return true if the test condition is met
  768. * @stable ICU 2.0
  769. */
  770. virtual UBool contains(UChar32 start, UChar32 end) const;
  771. /**
  772. * Returns <tt>true</tt> if this set contains the given
  773. * multicharacter string.
  774. * @param s string to be checked for containment
  775. * @return <tt>true</tt> if this set contains the specified string
  776. * @stable ICU 2.4
  777. */
  778. UBool contains(const UnicodeString& s) const;
  779. /**
  780. * Returns true if this set contains all the characters and strings
  781. * of the given set.
  782. * @param c set to be checked for containment
  783. * @return true if the test condition is met
  784. * @stable ICU 2.4
  785. */
  786. virtual UBool containsAll(const UnicodeSet& c) const;
  787. /**
  788. * Returns true if this set contains all the characters
  789. * of the given string.
  790. * @param s string containing characters to be checked for containment
  791. * @return true if the test condition is met
  792. * @stable ICU 2.4
  793. */
  794. UBool containsAll(const UnicodeString& s) const;
  795. /**
  796. * Returns true if this set contains none of the characters
  797. * of the given range.
  798. * @param start first character, inclusive, of the range
  799. * @param end last character, inclusive, of the range
  800. * @return true if the test condition is met
  801. * @stable ICU 2.4
  802. */
  803. UBool containsNone(UChar32 start, UChar32 end) const;
  804. /**
  805. * Returns true if this set contains none of the characters and strings
  806. * of the given set.
  807. * @param c set to be checked for containment
  808. * @return true if the test condition is met
  809. * @stable ICU 2.4
  810. */
  811. UBool containsNone(const UnicodeSet& c) const;
  812. /**
  813. * Returns true if this set contains none of the characters
  814. * of the given string.
  815. * @param s string containing characters to be checked for containment
  816. * @return true if the test condition is met
  817. * @stable ICU 2.4
  818. */
  819. UBool containsNone(const UnicodeString& s) const;
  820. /**
  821. * Returns true if this set contains one or more of the characters
  822. * in the given range.
  823. * @param start first character, inclusive, of the range
  824. * @param end last character, inclusive, of the range
  825. * @return true if the condition is met
  826. * @stable ICU 2.4
  827. */
  828. inline UBool containsSome(UChar32 start, UChar32 end) const;
  829. /**
  830. * Returns true if this set contains one or more of the characters
  831. * and strings of the given set.
  832. * @param s The set to be checked for containment
  833. * @return true if the condition is met
  834. * @stable ICU 2.4
  835. */
  836. inline UBool containsSome(const UnicodeSet& s) const;
  837. /**
  838. * Returns true if this set contains one or more of the characters
  839. * of the given string.
  840. * @param s string containing characters to be checked for containment
  841. * @return true if the condition is met
  842. * @stable ICU 2.4
  843. */
  844. inline UBool containsSome(const UnicodeString& s) const;
  845. /**
  846. * Returns the length of the initial substring of the input string which
  847. * consists only of characters and strings that are contained in this set
  848. * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
  849. * or only of characters and strings that are not contained
  850. * in this set (USET_SPAN_NOT_CONTAINED).
  851. * See USetSpanCondition for details.
  852. * Similar to the strspn() C library function.
  853. * Unpaired surrogates are treated according to contains() of their surrogate code points.
  854. * This function works faster with a frozen set and with a non-negative string length argument.
  855. * @param s start of the string
  856. * @param length of the string; can be -1 for NUL-terminated
  857. * @param spanCondition specifies the containment condition
  858. * @return the length of the initial substring according to the spanCondition;
  859. * 0 if the start of the string does not fit the spanCondition
  860. * @stable ICU 3.8
  861. * @see USetSpanCondition
  862. */
  863. int32_t span(const char16_t *s, int32_t length, USetSpanCondition spanCondition) const;
  864. /**
  865. * Returns the end of the substring of the input string according to the USetSpanCondition.
  866. * Same as <code>start+span(s.getBuffer()+start, s.length()-start, spanCondition)</code>
  867. * after pinning start to 0<=start<=s.length().
  868. * @param s the string
  869. * @param start the start index in the string for the span operation
  870. * @param spanCondition specifies the containment condition
  871. * @return the exclusive end of the substring according to the spanCondition;
  872. * the substring s.tempSubStringBetween(start, end) fulfills the spanCondition
  873. * @stable ICU 4.4
  874. * @see USetSpanCondition
  875. */
  876. inline int32_t span(const UnicodeString &s, int32_t start, USetSpanCondition spanCondition) const;
  877. /**
  878. * Returns the start of the trailing substring of the input string which
  879. * consists only of characters and strings that are contained in this set
  880. * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
  881. * or only of characters and strings that are not contained
  882. * in this set (USET_SPAN_NOT_CONTAINED).
  883. * See USetSpanCondition for details.
  884. * Unpaired surrogates are treated according to contains() of their surrogate code points.
  885. * This function works faster with a frozen set and with a non-negative string length argument.
  886. * @param s start of the string
  887. * @param length of the string; can be -1 for NUL-terminated
  888. * @param spanCondition specifies the containment condition
  889. * @return the start of the trailing substring according to the spanCondition;
  890. * the string length if the end of the string does not fit the spanCondition
  891. * @stable ICU 3.8
  892. * @see USetSpanCondition
  893. */
  894. int32_t spanBack(const char16_t *s, int32_t length, USetSpanCondition spanCondition) const;
  895. /**
  896. * Returns the start of the substring of the input string according to the USetSpanCondition.
  897. * Same as <code>spanBack(s.getBuffer(), limit, spanCondition)</code>
  898. * after pinning limit to 0<=end<=s.length().
  899. * @param s the string
  900. * @param limit the exclusive-end index in the string for the span operation
  901. * (use s.length() or INT32_MAX for spanning back from the end of the string)
  902. * @param spanCondition specifies the containment condition
  903. * @return the start of the substring according to the spanCondition;
  904. * the substring s.tempSubStringBetween(start, limit) fulfills the spanCondition
  905. * @stable ICU 4.4
  906. * @see USetSpanCondition
  907. */
  908. inline int32_t spanBack(const UnicodeString &s, int32_t limit, USetSpanCondition spanCondition) const;
  909. /**
  910. * Returns the length of the initial substring of the input string which
  911. * consists only of characters and strings that are contained in this set
  912. * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
  913. * or only of characters and strings that are not contained
  914. * in this set (USET_SPAN_NOT_CONTAINED).
  915. * See USetSpanCondition for details.
  916. * Similar to the strspn() C library function.
  917. * Malformed byte sequences are treated according to contains(0xfffd).
  918. * This function works faster with a frozen set and with a non-negative string length argument.
  919. * @param s start of the string (UTF-8)
  920. * @param length of the string; can be -1 for NUL-terminated
  921. * @param spanCondition specifies the containment condition
  922. * @return the length of the initial substring according to the spanCondition;
  923. * 0 if the start of the string does not fit the spanCondition
  924. * @stable ICU 3.8
  925. * @see USetSpanCondition
  926. */
  927. int32_t spanUTF8(const char *s, int32_t length, USetSpanCondition spanCondition) const;
  928. /**
  929. * Returns the start of the trailing substring of the input string which
  930. * consists only of characters and strings that are contained in this set
  931. * (USET_SPAN_CONTAINED, USET_SPAN_SIMPLE),
  932. * or only of characters and strings that are not contained
  933. * in this set (USET_SPAN_NOT_CONTAINED).
  934. * See USetSpanCondition for details.
  935. * Malformed byte sequences are treated according to contains(0xfffd).
  936. * This function works faster with a frozen set and with a non-negative string length argument.
  937. * @param s start of the string (UTF-8)
  938. * @param length of the string; can be -1 for NUL-terminated
  939. * @param spanCondition specifies the containment condition
  940. * @return the start of the trailing substring according to the spanCondition;
  941. * the string length if the end of the string does not fit the spanCondition
  942. * @stable ICU 3.8
  943. * @see USetSpanCondition
  944. */
  945. int32_t spanBackUTF8(const char *s, int32_t length, USetSpanCondition spanCondition) const;
  946. /**
  947. * Implement UnicodeMatcher::matches()
  948. * @stable ICU 2.4
  949. */
  950. virtual UMatchDegree matches(const Replaceable& text,
  951. int32_t& offset,
  952. int32_t limit,
  953. UBool incremental) override;
  954. private:
  955. /**
  956. * Returns the longest match for s in text at the given position.
  957. * If limit > start then match forward from start+1 to limit
  958. * matching all characters except s.charAt(0). If limit < start,
  959. * go backward starting from start-1 matching all characters
  960. * except s.charAt(s.length()-1). This method assumes that the
  961. * first character, text.charAt(start), matches s, so it does not
  962. * check it.
  963. * @param text the text to match
  964. * @param start the first character to match. In the forward
  965. * direction, text.charAt(start) is matched against s.charAt(0).
  966. * In the reverse direction, it is matched against
  967. * s.charAt(s.length()-1).
  968. * @param limit the limit offset for matching, either last+1 in
  969. * the forward direction, or last-1 in the reverse direction,
  970. * where last is the index of the last character to match.
  971. * @param s
  972. * @return If part of s matches up to the limit, return |limit -
  973. * start|. If all of s matches before reaching the limit, return
  974. * s.length(). If there is a mismatch between s and text, return
  975. * 0
  976. */
  977. static int32_t matchRest(const Replaceable& text,
  978. int32_t start, int32_t limit,
  979. const UnicodeString& s);
  980. /**
  981. * Returns the smallest value i such that c < list[i]. Caller
  982. * must ensure that c is a legal value or this method will enter
  983. * an infinite loop. This method performs a binary search.
  984. * @param c a character in the range MIN_VALUE..MAX_VALUE
  985. * inclusive
  986. * @return the smallest integer i in the range 0..len-1,
  987. * inclusive, such that c < list[i]
  988. */
  989. int32_t findCodePoint(UChar32 c) const;
  990. public:
  991. /**
  992. * Implementation of UnicodeMatcher API. Union the set of all
  993. * characters that may be matched by this object into the given
  994. * set.
  995. * @param toUnionTo the set into which to union the source characters
  996. * @stable ICU 2.4
  997. */
  998. virtual void addMatchSetTo(UnicodeSet& toUnionTo) const override;
  999. /**
  1000. * Returns the index of the given character within this set, where
  1001. * the set is ordered by ascending code point. If the character
  1002. * is not in this set, return -1. The inverse of this method is
  1003. * <code>charAt()</code>.
  1004. * @return an index from 0..size()-1, or -1
  1005. * @stable ICU 2.4
  1006. */
  1007. int32_t indexOf(UChar32 c) const;
  1008. /**
  1009. * Returns the character at the given index within this set, where
  1010. * the set is ordered by ascending code point. If the index is
  1011. * out of range for characters, returns (UChar32)-1.
  1012. * The inverse of this method is <code>indexOf()</code>.
  1013. *
  1014. * For iteration, this is slower than UnicodeSetIterator or
  1015. * getRangeCount()/getRangeStart()/getRangeEnd(),
  1016. * because for each call it skips linearly over <code>index</code>
  1017. * characters in the ranges.
  1018. *
  1019. * @param index an index from 0..size()-1
  1020. * @return the character at the given index, or (UChar32)-1.
  1021. * @stable ICU 2.4
  1022. */
  1023. UChar32 charAt(int32_t index) const;
  1024. /**
  1025. * Adds the specified range to this set if it is not already
  1026. * present. If this set already contains the specified range,
  1027. * the call leaves this set unchanged. If <code>start > end</code>
  1028. * then an empty range is added, leaving the set unchanged.
  1029. * This is equivalent to a boolean logic OR, or a set UNION.
  1030. * A frozen set will not be modified.
  1031. *
  1032. * @param start first character, inclusive, of range to be added
  1033. * to this set.
  1034. * @param end last character, inclusive, of range to be added
  1035. * to this set.
  1036. * @stable ICU 2.0
  1037. */
  1038. virtual UnicodeSet& add(UChar32 start, UChar32 end);
  1039. /**
  1040. * Adds the specified character to this set if it is not already
  1041. * present. If this set already contains the specified character,
  1042. * the call leaves this set unchanged.
  1043. * A frozen set will not be modified.
  1044. *
  1045. * @param c the character (code point)
  1046. * @return this object, for chaining
  1047. * @stable ICU 2.0
  1048. */
  1049. UnicodeSet& add(UChar32 c);
  1050. /**
  1051. * Adds the specified multicharacter to this set if it is not already
  1052. * present. If this set already contains the multicharacter,
  1053. * the call leaves this set unchanged.
  1054. * Thus "ch" => {"ch"}
  1055. * A frozen set will not be modified.
  1056. *
  1057. * @param s the source string
  1058. * @return this object, for chaining
  1059. * @stable ICU 2.4
  1060. */
  1061. UnicodeSet& add(const UnicodeString& s);
  1062. private:
  1063. /**
  1064. * @return a code point IF the string consists of a single one.
  1065. * otherwise returns -1.
  1066. * @param s string to test
  1067. */
  1068. static int32_t getSingleCP(const UnicodeString& s);
  1069. void _add(const UnicodeString& s);
  1070. public:
  1071. /**
  1072. * Adds each of the characters in this string to the set. Note: "ch" => {"c", "h"}
  1073. * If this set already contains any particular character, it has no effect on that character.
  1074. * A frozen set will not be modified.
  1075. * @param s the source string
  1076. * @return this object, for chaining
  1077. * @stable ICU 2.4
  1078. */
  1079. UnicodeSet& addAll(const UnicodeString& s);
  1080. /**
  1081. * Retains EACH of the characters in this string. Note: "ch" == {"c", "h"}
  1082. * A frozen set will not be modified.
  1083. * @param s the source string
  1084. * @return this object, for chaining
  1085. * @stable ICU 2.4
  1086. */
  1087. UnicodeSet& retainAll(const UnicodeString& s);
  1088. /**
  1089. * Complement EACH of the characters in this string. Note: "ch" == {"c", "h"}
  1090. * A frozen set will not be modified.
  1091. * @param s the source string
  1092. * @return this object, for chaining
  1093. * @stable ICU 2.4
  1094. */
  1095. UnicodeSet& complementAll(const UnicodeString& s);
  1096. /**
  1097. * Remove EACH of the characters in this string. Note: "ch" == {"c", "h"}
  1098. * A frozen set will not be modified.
  1099. * @param s the source string
  1100. * @return this object, for chaining
  1101. * @stable ICU 2.4
  1102. */
  1103. UnicodeSet& removeAll(const UnicodeString& s);
  1104. /**
  1105. * Makes a set from a multicharacter string. Thus "ch" => {"ch"}
  1106. *
  1107. * @param s the source string
  1108. * @return a newly created set containing the given string.
  1109. * The caller owns the return object and is responsible for deleting it.
  1110. * @stable ICU 2.4
  1111. */
  1112. static UnicodeSet* U_EXPORT2 createFrom(const UnicodeString& s);
  1113. /**
  1114. * Makes a set from each of the characters in the string. Thus "ch" => {"c", "h"}
  1115. * @param s the source string
  1116. * @return a newly created set containing the given characters
  1117. * The caller owns the return object and is responsible for deleting it.
  1118. * @stable ICU 2.4
  1119. */
  1120. static UnicodeSet* U_EXPORT2 createFromAll(const UnicodeString& s);
  1121. /**
  1122. * Retain only the elements in this set that are contained in the
  1123. * specified range. If <code>start > end</code> then an empty range is
  1124. * retained, leaving the set empty. This is equivalent to
  1125. * a boolean logic AND, or a set INTERSECTION.
  1126. * A frozen set will not be modified.
  1127. *
  1128. * @param start first character, inclusive, of range
  1129. * @param end last character, inclusive, of range
  1130. * @stable ICU 2.0
  1131. */
  1132. virtual UnicodeSet& retain(UChar32 start, UChar32 end);
  1133. /**
  1134. * Retain the specified character from this set if it is present.
  1135. * A frozen set will not be modified.
  1136. *
  1137. * @param c the character (code point)
  1138. * @return this object, for chaining
  1139. * @stable ICU 2.0
  1140. */
  1141. UnicodeSet& retain(UChar32 c);
  1142. /**
  1143. * Retains only the specified string from this set if it is present.
  1144. * Upon return this set will be empty if it did not contain s, or
  1145. * will only contain s if it did contain s.
  1146. * A frozen set will not be modified.
  1147. *
  1148. * @param s the source string
  1149. * @return this object, for chaining
  1150. * @stable ICU 69
  1151. */
  1152. UnicodeSet& retain(const UnicodeString &s);
  1153. /**
  1154. * Removes the specified range from this set if it is present.
  1155. * The set will not contain the specified range once the call
  1156. * returns. If <code>start > end</code> then an empty range is
  1157. * removed, leaving the set unchanged.
  1158. * A frozen set will not be modified.
  1159. *
  1160. * @param start first character, inclusive, of range to be removed
  1161. * from this set.
  1162. * @param end last character, inclusive, of range to be removed
  1163. * from this set.
  1164. * @stable ICU 2.0
  1165. */
  1166. virtual UnicodeSet& remove(UChar32 start, UChar32 end);
  1167. /**
  1168. * Removes the specified character from this set if it is present.
  1169. * The set will not contain the specified range once the call
  1170. * returns.
  1171. * A frozen set will not be modified.
  1172. *
  1173. * @param c the character (code point)
  1174. * @return this object, for chaining
  1175. * @stable ICU 2.0
  1176. */
  1177. UnicodeSet& remove(UChar32 c);
  1178. /**
  1179. * Removes the specified string from this set if it is present.
  1180. * The set will not contain the specified character once the call
  1181. * returns.
  1182. * A frozen set will not be modified.
  1183. * @param s the source string
  1184. * @return this object, for chaining
  1185. * @stable ICU 2.4
  1186. */
  1187. UnicodeSet& remove(const UnicodeString& s);
  1188. /**
  1189. * This is equivalent to
  1190. * <code>complement(MIN_VALUE, MAX_VALUE)</code>.
  1191. *
  1192. * <strong>Note:</strong> This performs a symmetric difference with all code points
  1193. * <em>and thus retains all multicharacter strings</em>.
  1194. * In order to achieve a “code point complement” (all code points minus this set),
  1195. * the easiest is to <code>.complement().removeAllStrings()</code>.
  1196. *
  1197. * A frozen set will not be modified.
  1198. * @stable ICU 2.0
  1199. */
  1200. virtual UnicodeSet& complement();
  1201. /**
  1202. * Complements the specified range in this set. Any character in
  1203. * the range will be removed if it is in this set, or will be
  1204. * added if it is not in this set. If <code>start > end</code>
  1205. * then an empty range is complemented, leaving the set unchanged.
  1206. * This is equivalent to a boolean logic XOR.
  1207. * A frozen set will not be modified.
  1208. *
  1209. * @param start first character, inclusive, of range
  1210. * @param end last character, inclusive, of range
  1211. * @stable ICU 2.0
  1212. */
  1213. virtual UnicodeSet& complement(UChar32 start, UChar32 end);
  1214. /**
  1215. * Complements the specified character in this set. The character
  1216. * will be removed if it is in this set, or will be added if it is
  1217. * not in this set.
  1218. * A frozen set will not be modified.
  1219. *
  1220. * @param c the character (code point)
  1221. * @return this object, for chaining
  1222. * @stable ICU 2.0
  1223. */
  1224. UnicodeSet& complement(UChar32 c);
  1225. /**
  1226. * Complement the specified string in this set.
  1227. * The string will be removed if it is in this set, or will be added if it is not in this set.
  1228. * A frozen set will not be modified.
  1229. *
  1230. * @param s the string to complement
  1231. * @return this object, for chaining
  1232. * @stable ICU 2.4
  1233. */
  1234. UnicodeSet& complement(const UnicodeString& s);
  1235. /**
  1236. * Adds all of the elements in the specified set to this set if
  1237. * they're not already present. This operation effectively
  1238. * modifies this set so that its value is the <i>union</i> of the two
  1239. * sets. The behavior of this operation is unspecified if the specified
  1240. * collection is modified while the operation is in progress.
  1241. * A frozen set will not be modified.
  1242. *
  1243. * @param c set whose elements are to be added to this set.
  1244. * @see #add(UChar32, UChar32)
  1245. * @stable ICU 2.0
  1246. */
  1247. virtual UnicodeSet& addAll(const UnicodeSet& c);
  1248. /**
  1249. * Retains only the elements in this set that are contained in the
  1250. * specified set. In other words, removes from this set all of
  1251. * its elements that are not contained in the specified set. This
  1252. * operation effectively modifies this set so that its value is
  1253. * the <i>intersection</i> of the two sets.
  1254. * A frozen set will not be modified.
  1255. *
  1256. * @param c set that defines which elements this set will retain.
  1257. * @stable ICU 2.0
  1258. */
  1259. virtual UnicodeSet& retainAll(const UnicodeSet& c);
  1260. /**
  1261. * Removes from this set all of its elements that are contained in the
  1262. * specified set. This operation effectively modifies this
  1263. * set so that its value is the <i>asymmetric set difference</i> of
  1264. * the two sets.
  1265. * A frozen set will not be modified.
  1266. *
  1267. * @param c set that defines which elements will be removed from
  1268. * this set.
  1269. * @stable ICU 2.0
  1270. */
  1271. virtual UnicodeSet& removeAll(const UnicodeSet& c);
  1272. /**
  1273. * Complements in this set all elements contained in the specified
  1274. * set. Any character in the other set will be removed if it is
  1275. * in this set, or will be added if it is not in this set.
  1276. * A frozen set will not be modified.
  1277. *
  1278. * @param c set that defines which elements will be xor'ed from
  1279. * this set.
  1280. * @stable ICU 2.4
  1281. */
  1282. virtual UnicodeSet& complementAll(const UnicodeSet& c);
  1283. /**
  1284. * Removes all of the elements from this set. This set will be
  1285. * empty after this call returns.
  1286. * A frozen set will not be modified.
  1287. * @stable ICU 2.0
  1288. */
  1289. virtual UnicodeSet& clear();
  1290. /**
  1291. * Close this set over the given attribute. For the attribute
  1292. * USET_CASE_INSENSITIVE, the result is to modify this set so that:
  1293. *
  1294. * 1. For each character or string 'a' in this set, all strings or
  1295. * characters 'b' such that foldCase(a) == foldCase(b) are added
  1296. * to this set.
  1297. *
  1298. * 2. For each string 'e' in the resulting set, if e !=
  1299. * foldCase(e), 'e' will be removed.
  1300. *
  1301. * Example: [aq\\u00DF{Bc}{bC}{Fi}] => [aAqQ\\u00DF\\uFB01{ss}{bc}{fi}]
  1302. *
  1303. * (Here foldCase(x) refers to the operation u_strFoldCase, and a
  1304. * == b denotes that the contents are the same, not pointer
  1305. * comparison.)
  1306. *
  1307. * A frozen set will not be modified.
  1308. *
  1309. * @param attribute bitmask for attributes to close over.
  1310. * Valid options:
  1311. * At most one of USET_CASE_INSENSITIVE, USET_ADD_CASE_MAPPINGS, USET_SIMPLE_CASE_INSENSITIVE.
  1312. * These case options are mutually exclusive.
  1313. * Unrelated options bits are ignored.
  1314. * @return a reference to this set.
  1315. * @stable ICU 4.2
  1316. */
  1317. UnicodeSet& closeOver(int32_t attribute);
  1318. /**
  1319. * Remove all strings from this set.
  1320. *
  1321. * @return a reference to this set.
  1322. * @stable ICU 4.2
  1323. */
  1324. virtual UnicodeSet &removeAllStrings();
  1325. /**
  1326. * Iteration method that returns the number of ranges contained in
  1327. * this set.
  1328. * @see #getRangeStart
  1329. * @see #getRangeEnd
  1330. * @stable ICU 2.4
  1331. */
  1332. virtual int32_t getRangeCount() const;
  1333. /**
  1334. * Iteration method that returns the first character in the
  1335. * specified range of this set.
  1336. * @see #getRangeCount
  1337. * @see #getRangeEnd
  1338. * @stable ICU 2.4
  1339. */
  1340. virtual UChar32 getRangeStart(int32_t index) const;
  1341. /**
  1342. * Iteration method that returns the last character in the
  1343. * specified range of this set.
  1344. * @see #getRangeStart
  1345. * @see #getRangeEnd
  1346. * @stable ICU 2.4
  1347. */
  1348. virtual UChar32 getRangeEnd(int32_t index) const;
  1349. /**
  1350. * Serializes this set into an array of 16-bit integers. Serialization
  1351. * (currently) only records the characters in the set; multicharacter
  1352. * strings are ignored.
  1353. *
  1354. * The array has following format (each line is one 16-bit
  1355. * integer):
  1356. *
  1357. * length = (n+2*m) | (m!=0?0x8000:0)
  1358. * bmpLength = n; present if m!=0
  1359. * bmp[0]
  1360. * bmp[1]
  1361. * ...
  1362. * bmp[n-1]
  1363. * supp-high[0]
  1364. * supp-low[0]
  1365. * supp-high[1]
  1366. * supp-low[1]
  1367. * ...
  1368. * supp-high[m-1]
  1369. * supp-low[m-1]
  1370. *
  1371. * The array starts with a header. After the header are n bmp
  1372. * code points, then m supplementary code points. Either n or m
  1373. * or both may be zero. n+2*m is always <= 0x7FFF.
  1374. *
  1375. * If there are no supplementary characters (if m==0) then the
  1376. * header is one 16-bit integer, 'length', with value n.
  1377. *
  1378. * If there are supplementary characters (if m!=0) then the header
  1379. * is two 16-bit integers. The first, 'length', has value
  1380. * (n+2*m)|0x8000. The second, 'bmpLength', has value n.
  1381. *
  1382. * After the header the code points are stored in ascending order.
  1383. * Supplementary code points are stored as most significant 16
  1384. * bits followed by least significant 16 bits.
  1385. *
  1386. * @param dest pointer to buffer of destCapacity 16-bit integers.
  1387. * May be nullptr only if destCapacity is zero.
  1388. * @param destCapacity size of dest, or zero. Must not be negative.
  1389. * @param ec error code. Will be set to U_INDEX_OUTOFBOUNDS_ERROR
  1390. * if n+2*m > 0x7FFF. Will be set to U_BUFFER_OVERFLOW_ERROR if
  1391. * n+2*m+(m!=0?2:1) > destCapacity.
  1392. * @return the total length of the serialized format, including
  1393. * the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
  1394. * than U_BUFFER_OVERFLOW_ERROR.
  1395. * @stable ICU 2.4
  1396. */
  1397. int32_t serialize(uint16_t *dest, int32_t destCapacity, UErrorCode& ec) const;
  1398. /**
  1399. * Reallocate this objects internal structures to take up the least
  1400. * possible space, without changing this object's value.
  1401. * A frozen set will not be modified.
  1402. * @stable ICU 2.4
  1403. */
  1404. virtual UnicodeSet& compact();
  1405. /**
  1406. * Return the class ID for this class. This is useful only for
  1407. * comparing to a return value from getDynamicClassID(). For example:
  1408. * <pre>
  1409. * . Base* polymorphic_pointer = createPolymorphicObject();
  1410. * . if (polymorphic_pointer->getDynamicClassID() ==
  1411. * . Derived::getStaticClassID()) ...
  1412. * </pre>
  1413. * @return The class ID for all objects of this class.
  1414. * @stable ICU 2.0
  1415. */
  1416. static UClassID U_EXPORT2 getStaticClassID();
  1417. /**
  1418. * Implement UnicodeFunctor API.
  1419. *
  1420. * @return The class ID for this object. All objects of a given
  1421. * class have the same class ID. Objects of other classes have
  1422. * different class IDs.
  1423. * @stable ICU 2.4
  1424. */
  1425. virtual UClassID getDynamicClassID() const override;
  1426. private:
  1427. // Private API for the USet API
  1428. friend class USetAccess;
  1429. const UnicodeString* getString(int32_t index) const;
  1430. //----------------------------------------------------------------
  1431. // RuleBasedTransliterator support
  1432. //----------------------------------------------------------------
  1433. private:
  1434. /**
  1435. * Returns <tt>true</tt> if this set contains any character whose low byte
  1436. * is the given value. This is used by <tt>RuleBasedTransliterator</tt> for
  1437. * indexing.
  1438. */
  1439. virtual UBool matchesIndexValue(uint8_t v) const override;
  1440. private:
  1441. friend class RBBIRuleScanner;
  1442. //----------------------------------------------------------------
  1443. // Implementation: Clone as thawed (see ICU4J Freezable)
  1444. //----------------------------------------------------------------
  1445. UnicodeSet(const UnicodeSet& o, UBool /* asThawed */);
  1446. UnicodeSet& copyFrom(const UnicodeSet& o, UBool asThawed);
  1447. //----------------------------------------------------------------
  1448. // Implementation: Pattern parsing
  1449. //----------------------------------------------------------------
  1450. void applyPatternIgnoreSpace(const UnicodeString& pattern,
  1451. ParsePosition& pos,
  1452. const SymbolTable* symbols,
  1453. UErrorCode& status);
  1454. void applyPattern(RuleCharacterIterator& chars,
  1455. const SymbolTable* symbols,
  1456. UnicodeString& rebuiltPat,
  1457. uint32_t options,
  1458. UnicodeSet& (UnicodeSet::*caseClosure)(int32_t attribute),
  1459. int32_t depth,
  1460. UErrorCode& ec);
  1461. void closeOverCaseInsensitive(bool simple);
  1462. void closeOverAddCaseMappings();
  1463. //----------------------------------------------------------------
  1464. // Implementation: Utility methods
  1465. //----------------------------------------------------------------
  1466. static int32_t nextCapacity(int32_t minCapacity);
  1467. bool ensureCapacity(int32_t newLen);
  1468. bool ensureBufferCapacity(int32_t newLen);
  1469. void swapBuffers();
  1470. UBool allocateStrings(UErrorCode &status);
  1471. int32_t stringsSize() const;
  1472. UBool stringsContains(const UnicodeString &s) const;
  1473. UnicodeString& _toPattern(UnicodeString& result,
  1474. UBool escapeUnprintable) const;
  1475. UnicodeString& _generatePattern(UnicodeString& result,
  1476. UBool escapeUnprintable) const;
  1477. static void _appendToPat(UnicodeString& buf, const UnicodeString& s, UBool escapeUnprintable);
  1478. static void _appendToPat(UnicodeString& buf, UChar32 c, UBool escapeUnprintable);
  1479. static void _appendToPat(UnicodeString &result, UChar32 start, UChar32 end,
  1480. UBool escapeUnprintable);
  1481. //----------------------------------------------------------------
  1482. // Implementation: Fundamental operators
  1483. //----------------------------------------------------------------
  1484. void exclusiveOr(const UChar32* other, int32_t otherLen, int8_t polarity);
  1485. void add(const UChar32* other, int32_t otherLen, int8_t polarity);
  1486. void retain(const UChar32* other, int32_t otherLen, int8_t polarity);
  1487. /**
  1488. * Return true if the given position, in the given pattern, appears
  1489. * to be the start of a property set pattern [:foo:], \\p{foo}, or
  1490. * \\P{foo}, or \\N{name}.
  1491. */
  1492. static UBool resemblesPropertyPattern(const UnicodeString& pattern,
  1493. int32_t pos);
  1494. static UBool resemblesPropertyPattern(RuleCharacterIterator& chars,
  1495. int32_t iterOpts);
  1496. /**
  1497. * Parse the given property pattern at the given parse position
  1498. * and set this UnicodeSet to the result.
  1499. *
  1500. * The original design document is out of date, but still useful.
  1501. * Ignore the property and value names:
  1502. * https://htmlpreview.github.io/?https://github.com/unicode-org/icu-docs/blob/main/design/unicodeset_properties.html
  1503. *
  1504. * Recognized syntax:
  1505. *
  1506. * [:foo:] [:^foo:] - white space not allowed within "[:" or ":]"
  1507. * \\p{foo} \\P{foo} - white space not allowed within "\\p" or "\\P"
  1508. * \\N{name} - white space not allowed within "\\N"
  1509. *
  1510. * Other than the above restrictions, Unicode Pattern_White_Space characters are ignored.
  1511. * Case is ignored except in "\\p" and "\\P" and "\\N". In 'name' leading
  1512. * and trailing space is deleted, and internal runs of whitespace
  1513. * are collapsed to a single space.
  1514. *
  1515. * We support binary properties, enumerated properties, and the
  1516. * following non-enumerated properties:
  1517. *
  1518. * Numeric_Value
  1519. * Name
  1520. * Unicode_1_Name
  1521. *
  1522. * @param pattern the pattern string
  1523. * @param ppos on entry, the position at which to begin parsing.
  1524. * This should be one of the locations marked '^':
  1525. *
  1526. * [:blah:] \\p{blah} \\P{blah} \\N{name}
  1527. * ^ % ^ % ^ % ^ %
  1528. *
  1529. * On return, the position after the last character parsed, that is,
  1530. * the locations marked '%'. If the parse fails, ppos is returned
  1531. * unchanged.
  1532. * @param ec status
  1533. * @return a reference to this.
  1534. */
  1535. UnicodeSet& applyPropertyPattern(const UnicodeString& pattern,
  1536. ParsePosition& ppos,
  1537. UErrorCode &ec);
  1538. void applyPropertyPattern(RuleCharacterIterator& chars,
  1539. UnicodeString& rebuiltPat,
  1540. UErrorCode& ec);
  1541. /**
  1542. * A filter that returns true if the given code point should be
  1543. * included in the UnicodeSet being constructed.
  1544. */
  1545. typedef UBool (*Filter)(UChar32 codePoint, void* context);
  1546. /**
  1547. * Given a filter, set this UnicodeSet to the code points
  1548. * contained by that filter. The filter MUST be
  1549. * property-conformant. That is, if it returns value v for one
  1550. * code point, then it must return v for all affiliated code
  1551. * points, as defined by the inclusions list. See
  1552. * getInclusions().
  1553. * src is a UPropertySource value.
  1554. */
  1555. void applyFilter(Filter filter,
  1556. void* context,
  1557. const UnicodeSet* inclusions,
  1558. UErrorCode &status);
  1559. /**
  1560. * Set the new pattern to cache.
  1561. */
  1562. void setPattern(const UnicodeString& newPat) {
  1563. setPattern(newPat.getBuffer(), newPat.length());
  1564. }
  1565. void setPattern(const char16_t *newPat, int32_t newPatLen);
  1566. /**
  1567. * Release existing cached pattern.
  1568. */
  1569. void releasePattern();
  1570. friend class UnicodeSetIterator;
  1571. };
  1572. inline bool UnicodeSet::operator!=(const UnicodeSet& o) const {
  1573. return !operator==(o);
  1574. }
  1575. inline UBool UnicodeSet::isFrozen() const {
  1576. return (UBool)(bmpSet!=nullptr || stringSpan!=nullptr);
  1577. }
  1578. inline UBool UnicodeSet::containsSome(UChar32 start, UChar32 end) const {
  1579. return !containsNone(start, end);
  1580. }
  1581. inline UBool UnicodeSet::containsSome(const UnicodeSet& s) const {
  1582. return !containsNone(s);
  1583. }
  1584. inline UBool UnicodeSet::containsSome(const UnicodeString& s) const {
  1585. return !containsNone(s);
  1586. }
  1587. inline UBool UnicodeSet::isBogus() const {
  1588. return (UBool)(fFlags & kIsBogus);
  1589. }
  1590. inline UnicodeSet *UnicodeSet::fromUSet(USet *uset) {
  1591. return reinterpret_cast<UnicodeSet *>(uset);
  1592. }
  1593. inline const UnicodeSet *UnicodeSet::fromUSet(const USet *uset) {
  1594. return reinterpret_cast<const UnicodeSet *>(uset);
  1595. }
  1596. inline USet *UnicodeSet::toUSet() {
  1597. return reinterpret_cast<USet *>(this);
  1598. }
  1599. inline const USet *UnicodeSet::toUSet() const {
  1600. return reinterpret_cast<const USet *>(this);
  1601. }
  1602. inline int32_t UnicodeSet::span(const UnicodeString &s, int32_t start, USetSpanCondition spanCondition) const {
  1603. int32_t sLength=s.length();
  1604. if(start<0) {
  1605. start=0;
  1606. } else if(start>sLength) {
  1607. start=sLength;
  1608. }
  1609. return start+span(s.getBuffer()+start, sLength-start, spanCondition);
  1610. }
  1611. inline int32_t UnicodeSet::spanBack(const UnicodeString &s, int32_t limit, USetSpanCondition spanCondition) const {
  1612. int32_t sLength=s.length();
  1613. if(limit<0) {
  1614. limit=0;
  1615. } else if(limit>sLength) {
  1616. limit=sLength;
  1617. }
  1618. return spanBack(s.getBuffer(), limit, spanCondition);
  1619. }
  1620. U_NAMESPACE_END
  1621. #endif /* U_SHOW_CPLUSPLUS_API */
  1622. #endif