normlzr.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ********************************************************************
  5. * COPYRIGHT:
  6. * Copyright (c) 1996-2015, International Business Machines Corporation and
  7. * others. All Rights Reserved.
  8. ********************************************************************
  9. */
  10. #ifndef NORMLZR_H
  11. #define NORMLZR_H
  12. #include "unicode/utypes.h"
  13. #if U_SHOW_CPLUSPLUS_API
  14. /**
  15. * \file
  16. * \brief C++ API: Unicode Normalization
  17. */
  18. #if !UCONFIG_NO_NORMALIZATION
  19. #include "unicode/chariter.h"
  20. #include "unicode/normalizer2.h"
  21. #include "unicode/unistr.h"
  22. #include "unicode/unorm.h"
  23. #include "unicode/uobject.h"
  24. U_NAMESPACE_BEGIN
  25. /**
  26. * Old Unicode normalization API.
  27. *
  28. * This API has been replaced by the Normalizer2 class and is only available
  29. * for backward compatibility. This class simply delegates to the Normalizer2 class.
  30. * There is one exception: The new API does not provide a replacement for Normalizer::compare().
  31. *
  32. * The Normalizer class supports the standard normalization forms described in
  33. * <a href="http://www.unicode.org/unicode/reports/tr15/" target="unicode">
  34. * Unicode Standard Annex #15: Unicode Normalization Forms</a>.
  35. *
  36. * The Normalizer class consists of two parts:
  37. * - static functions that normalize strings or test if strings are normalized
  38. * - a Normalizer object is an iterator that takes any kind of text and
  39. * provides iteration over its normalized form
  40. *
  41. * The Normalizer class is not suitable for subclassing.
  42. *
  43. * For basic information about normalization forms and details about the C API
  44. * please see the documentation in unorm.h.
  45. *
  46. * The iterator API with the Normalizer constructors and the non-static functions
  47. * use a CharacterIterator as input. It is possible to pass a string which
  48. * is then internally wrapped in a CharacterIterator.
  49. * The input text is not normalized all at once, but incrementally where needed
  50. * (providing efficient random access).
  51. * This allows to pass in a large text but spend only a small amount of time
  52. * normalizing a small part of that text.
  53. * However, if the entire text is normalized, then the iterator will be
  54. * slower than normalizing the entire text at once and iterating over the result.
  55. * A possible use of the Normalizer iterator is also to report an index into the
  56. * original text that is close to where the normalized characters come from.
  57. *
  58. * <em>Important:</em> The iterator API was cleaned up significantly for ICU 2.0.
  59. * The earlier implementation reported the getIndex() inconsistently,
  60. * and previous() could not be used after setIndex(), next(), first(), and current().
  61. *
  62. * Normalizer allows to start normalizing from anywhere in the input text by
  63. * calling setIndexOnly(), first(), or last().
  64. * Without calling any of these, the iterator will start at the beginning of the text.
  65. *
  66. * At any time, next() returns the next normalized code point (UChar32),
  67. * with post-increment semantics (like CharacterIterator::next32PostInc()).
  68. * previous() returns the previous normalized code point (UChar32),
  69. * with pre-decrement semantics (like CharacterIterator::previous32()).
  70. *
  71. * current() returns the current code point
  72. * (respectively the one at the newly set index) without moving
  73. * the getIndex(). Note that if the text at the current position
  74. * needs to be normalized, then these functions will do that.
  75. * (This is why current() is not const.)
  76. * It is more efficient to call setIndexOnly() instead, which does not
  77. * normalize.
  78. *
  79. * getIndex() always refers to the position in the input text where the normalized
  80. * code points are returned from. It does not always change with each returned
  81. * code point.
  82. * The code point that is returned from any of the functions
  83. * corresponds to text at or after getIndex(), according to the
  84. * function's iteration semantics (post-increment or pre-decrement).
  85. *
  86. * next() returns a code point from at or after the getIndex()
  87. * from before the next() call. After the next() call, the getIndex()
  88. * might have moved to where the next code point will be returned from
  89. * (from a next() or current() call).
  90. * This is semantically equivalent to array access with array[index++]
  91. * (post-increment semantics).
  92. *
  93. * previous() returns a code point from at or after the getIndex()
  94. * from after the previous() call.
  95. * This is semantically equivalent to array access with array[--index]
  96. * (pre-decrement semantics).
  97. *
  98. * Internally, the Normalizer iterator normalizes a small piece of text
  99. * starting at the getIndex() and ending at a following "safe" index.
  100. * The normalized results is stored in an internal string buffer, and
  101. * the code points are iterated from there.
  102. * With multiple iteration calls, this is repeated until the next piece
  103. * of text needs to be normalized, and the getIndex() needs to be moved.
  104. *
  105. * The following "safe" index, the internal buffer, and the secondary
  106. * iteration index into that buffer are not exposed on the API.
  107. * This also means that it is currently not practical to return to
  108. * a particular, arbitrary position in the text because one would need to
  109. * know, and be able to set, in addition to the getIndex(), at least also the
  110. * current index into the internal buffer.
  111. * It is currently only possible to observe when getIndex() changes
  112. * (with careful consideration of the iteration semantics),
  113. * at which time the internal index will be 0.
  114. * For example, if getIndex() is different after next() than before it,
  115. * then the internal index is 0 and one can return to this getIndex()
  116. * later with setIndexOnly().
  117. *
  118. * Note: While the setIndex() and getIndex() refer to indices in the
  119. * underlying Unicode input text, the next() and previous() methods
  120. * iterate through characters in the normalized output.
  121. * This means that there is not necessarily a one-to-one correspondence
  122. * between characters returned by next() and previous() and the indices
  123. * passed to and returned from setIndex() and getIndex().
  124. * It is for this reason that Normalizer does not implement the CharacterIterator interface.
  125. *
  126. * @author Laura Werner, Mark Davis, Markus Scherer
  127. * @stable ICU 2.0
  128. */
  129. class U_COMMON_API Normalizer : public UObject {
  130. public:
  131. #ifndef U_HIDE_DEPRECATED_API
  132. /**
  133. * If DONE is returned from an iteration function that returns a code point,
  134. * then there are no more normalization results available.
  135. * @deprecated ICU 56 Use Normalizer2 instead.
  136. */
  137. enum {
  138. DONE=0xffff
  139. };
  140. // Constructors
  141. /**
  142. * Creates a new <code>Normalizer</code> object for iterating over the
  143. * normalized form of a given string.
  144. * <p>
  145. * @param str The string to be normalized. The normalization
  146. * will start at the beginning of the string.
  147. *
  148. * @param mode The normalization mode.
  149. * @deprecated ICU 56 Use Normalizer2 instead.
  150. */
  151. Normalizer(const UnicodeString& str, UNormalizationMode mode);
  152. /**
  153. * Creates a new <code>Normalizer</code> object for iterating over the
  154. * normalized form of a given string.
  155. * <p>
  156. * @param str The string to be normalized. The normalization
  157. * will start at the beginning of the string.
  158. *
  159. * @param length Length of the string, or -1 if NUL-terminated.
  160. * @param mode The normalization mode.
  161. * @deprecated ICU 56 Use Normalizer2 instead.
  162. */
  163. Normalizer(ConstChar16Ptr str, int32_t length, UNormalizationMode mode);
  164. /**
  165. * Creates a new <code>Normalizer</code> object for iterating over the
  166. * normalized form of the given text.
  167. * <p>
  168. * @param iter The input text to be normalized. The normalization
  169. * will start at the beginning of the string.
  170. *
  171. * @param mode The normalization mode.
  172. * @deprecated ICU 56 Use Normalizer2 instead.
  173. */
  174. Normalizer(const CharacterIterator& iter, UNormalizationMode mode);
  175. #endif /* U_HIDE_DEPRECATED_API */
  176. #ifndef U_FORCE_HIDE_DEPRECATED_API
  177. /**
  178. * Copy constructor.
  179. * @param copy The object to be copied.
  180. * @deprecated ICU 56 Use Normalizer2 instead.
  181. */
  182. Normalizer(const Normalizer& copy);
  183. /**
  184. * Destructor
  185. * @deprecated ICU 56 Use Normalizer2 instead.
  186. */
  187. virtual ~Normalizer();
  188. #endif // U_FORCE_HIDE_DEPRECATED_API
  189. //-------------------------------------------------------------------------
  190. // Static utility methods
  191. //-------------------------------------------------------------------------
  192. #ifndef U_HIDE_DEPRECATED_API
  193. /**
  194. * Normalizes a <code>UnicodeString</code> according to the specified normalization mode.
  195. * This is a wrapper for unorm_normalize(), using UnicodeString's.
  196. *
  197. * The <code>options</code> parameter specifies which optional
  198. * <code>Normalizer</code> features are to be enabled for this operation.
  199. *
  200. * @param source the input string to be normalized.
  201. * @param mode the normalization mode
  202. * @param options the optional features to be enabled (0 for no options)
  203. * @param result The normalized string (on output).
  204. * @param status The error code.
  205. * @deprecated ICU 56 Use Normalizer2 instead.
  206. */
  207. static void U_EXPORT2 normalize(const UnicodeString& source,
  208. UNormalizationMode mode, int32_t options,
  209. UnicodeString& result,
  210. UErrorCode &status);
  211. /**
  212. * Compose a <code>UnicodeString</code>.
  213. * This is equivalent to normalize() with mode UNORM_NFC or UNORM_NFKC.
  214. * This is a wrapper for unorm_normalize(), using UnicodeString's.
  215. *
  216. * The <code>options</code> parameter specifies which optional
  217. * <code>Normalizer</code> features are to be enabled for this operation.
  218. *
  219. * @param source the string to be composed.
  220. * @param compat Perform compatibility decomposition before composition.
  221. * If this argument is <code>false</code>, only canonical
  222. * decomposition will be performed.
  223. * @param options the optional features to be enabled (0 for no options)
  224. * @param result The composed string (on output).
  225. * @param status The error code.
  226. * @deprecated ICU 56 Use Normalizer2 instead.
  227. */
  228. static void U_EXPORT2 compose(const UnicodeString& source,
  229. UBool compat, int32_t options,
  230. UnicodeString& result,
  231. UErrorCode &status);
  232. /**
  233. * Static method to decompose a <code>UnicodeString</code>.
  234. * This is equivalent to normalize() with mode UNORM_NFD or UNORM_NFKD.
  235. * This is a wrapper for unorm_normalize(), using UnicodeString's.
  236. *
  237. * The <code>options</code> parameter specifies which optional
  238. * <code>Normalizer</code> features are to be enabled for this operation.
  239. *
  240. * @param source the string to be decomposed.
  241. * @param compat Perform compatibility decomposition.
  242. * If this argument is <code>false</code>, only canonical
  243. * decomposition will be performed.
  244. * @param options the optional features to be enabled (0 for no options)
  245. * @param result The decomposed string (on output).
  246. * @param status The error code.
  247. * @deprecated ICU 56 Use Normalizer2 instead.
  248. */
  249. static void U_EXPORT2 decompose(const UnicodeString& source,
  250. UBool compat, int32_t options,
  251. UnicodeString& result,
  252. UErrorCode &status);
  253. /**
  254. * Performing quick check on a string, to quickly determine if the string is
  255. * in a particular normalization format.
  256. * This is a wrapper for unorm_quickCheck(), using a UnicodeString.
  257. *
  258. * Three types of result can be returned UNORM_YES, UNORM_NO or
  259. * UNORM_MAYBE. Result UNORM_YES indicates that the argument
  260. * string is in the desired normalized format, UNORM_NO determines that
  261. * argument string is not in the desired normalized format. A
  262. * UNORM_MAYBE result indicates that a more thorough check is required,
  263. * the user may have to put the string in its normalized form and compare the
  264. * results.
  265. * @param source string for determining if it is in a normalized format
  266. * @param mode normalization format
  267. * @param status A reference to a UErrorCode to receive any errors
  268. * @return UNORM_YES, UNORM_NO or UNORM_MAYBE
  269. *
  270. * @see isNormalized
  271. * @deprecated ICU 56 Use Normalizer2 instead.
  272. */
  273. static inline UNormalizationCheckResult
  274. quickCheck(const UnicodeString &source, UNormalizationMode mode, UErrorCode &status);
  275. /**
  276. * Performing quick check on a string; same as the other version of quickCheck
  277. * but takes an extra options parameter like most normalization functions.
  278. *
  279. * @param source string for determining if it is in a normalized format
  280. * @param mode normalization format
  281. * @param options the optional features to be enabled (0 for no options)
  282. * @param status A reference to a UErrorCode to receive any errors
  283. * @return UNORM_YES, UNORM_NO or UNORM_MAYBE
  284. *
  285. * @see isNormalized
  286. * @deprecated ICU 56 Use Normalizer2 instead.
  287. */
  288. static UNormalizationCheckResult
  289. quickCheck(const UnicodeString &source, UNormalizationMode mode, int32_t options, UErrorCode &status);
  290. /**
  291. * Test if a string is in a given normalization form.
  292. * This is semantically equivalent to source.equals(normalize(source, mode)) .
  293. *
  294. * Unlike unorm_quickCheck(), this function returns a definitive result,
  295. * never a "maybe".
  296. * For NFD, NFKD, and FCD, both functions work exactly the same.
  297. * For NFC and NFKC where quickCheck may return "maybe", this function will
  298. * perform further tests to arrive at a true/false result.
  299. *
  300. * @param src String that is to be tested if it is in a normalization format.
  301. * @param mode Which normalization form to test for.
  302. * @param errorCode ICU error code in/out parameter.
  303. * Must fulfill U_SUCCESS before the function call.
  304. * @return Boolean value indicating whether the source string is in the
  305. * "mode" normalization form.
  306. *
  307. * @see quickCheck
  308. * @deprecated ICU 56 Use Normalizer2 instead.
  309. */
  310. static inline UBool
  311. isNormalized(const UnicodeString &src, UNormalizationMode mode, UErrorCode &errorCode);
  312. /**
  313. * Test if a string is in a given normalization form; same as the other version of isNormalized
  314. * but takes an extra options parameter like most normalization functions.
  315. *
  316. * @param src String that is to be tested if it is in a normalization format.
  317. * @param mode Which normalization form to test for.
  318. * @param options the optional features to be enabled (0 for no options)
  319. * @param errorCode ICU error code in/out parameter.
  320. * Must fulfill U_SUCCESS before the function call.
  321. * @return Boolean value indicating whether the source string is in the
  322. * "mode" normalization form.
  323. *
  324. * @see quickCheck
  325. * @deprecated ICU 56 Use Normalizer2 instead.
  326. */
  327. static UBool
  328. isNormalized(const UnicodeString &src, UNormalizationMode mode, int32_t options, UErrorCode &errorCode);
  329. /**
  330. * Concatenate normalized strings, making sure that the result is normalized as well.
  331. *
  332. * If both the left and the right strings are in
  333. * the normalization form according to "mode/options",
  334. * then the result will be
  335. *
  336. * \code
  337. * dest=normalize(left+right, mode, options)
  338. * \endcode
  339. *
  340. * For details see unorm_concatenate in unorm.h.
  341. *
  342. * @param left Left source string.
  343. * @param right Right source string.
  344. * @param result The output string.
  345. * @param mode The normalization mode.
  346. * @param options A bit set of normalization options.
  347. * @param errorCode ICU error code in/out parameter.
  348. * Must fulfill U_SUCCESS before the function call.
  349. * @return result
  350. *
  351. * @see unorm_concatenate
  352. * @see normalize
  353. * @see unorm_next
  354. * @see unorm_previous
  355. *
  356. * @deprecated ICU 56 Use Normalizer2 instead.
  357. */
  358. static UnicodeString &
  359. U_EXPORT2 concatenate(const UnicodeString &left, const UnicodeString &right,
  360. UnicodeString &result,
  361. UNormalizationMode mode, int32_t options,
  362. UErrorCode &errorCode);
  363. #endif /* U_HIDE_DEPRECATED_API */
  364. /**
  365. * Compare two strings for canonical equivalence.
  366. * Further options include case-insensitive comparison and
  367. * code point order (as opposed to code unit order).
  368. *
  369. * Canonical equivalence between two strings is defined as their normalized
  370. * forms (NFD or NFC) being identical.
  371. * This function compares strings incrementally instead of normalizing
  372. * (and optionally case-folding) both strings entirely,
  373. * improving performance significantly.
  374. *
  375. * Bulk normalization is only necessary if the strings do not fulfill the FCD
  376. * conditions. Only in this case, and only if the strings are relatively long,
  377. * is memory allocated temporarily.
  378. * For FCD strings and short non-FCD strings there is no memory allocation.
  379. *
  380. * Semantically, this is equivalent to
  381. * strcmp[CodePointOrder](NFD(foldCase(s1)), NFD(foldCase(s2)))
  382. * where code point order and foldCase are all optional.
  383. *
  384. * UAX 21 2.5 Caseless Matching specifies that for a canonical caseless match
  385. * the case folding must be performed first, then the normalization.
  386. *
  387. * @param s1 First source string.
  388. * @param s2 Second source string.
  389. *
  390. * @param options A bit set of options:
  391. * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
  392. * Case-sensitive comparison in code unit order, and the input strings
  393. * are quick-checked for FCD.
  394. *
  395. * - UNORM_INPUT_IS_FCD
  396. * Set if the caller knows that both s1 and s2 fulfill the FCD conditions.
  397. * If not set, the function will quickCheck for FCD
  398. * and normalize if necessary.
  399. *
  400. * - U_COMPARE_CODE_POINT_ORDER
  401. * Set to choose code point order instead of code unit order
  402. * (see u_strCompare for details).
  403. *
  404. * - U_COMPARE_IGNORE_CASE
  405. * Set to compare strings case-insensitively using case folding,
  406. * instead of case-sensitively.
  407. * If set, then the following case folding options are used.
  408. *
  409. * - Options as used with case-insensitive comparisons, currently:
  410. *
  411. * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
  412. * (see u_strCaseCompare for details)
  413. *
  414. * - regular normalization options shifted left by UNORM_COMPARE_NORM_OPTIONS_SHIFT
  415. *
  416. * @param errorCode ICU error code in/out parameter.
  417. * Must fulfill U_SUCCESS before the function call.
  418. * @return <0 or 0 or >0 as usual for string comparisons
  419. *
  420. * @see unorm_compare
  421. * @see normalize
  422. * @see UNORM_FCD
  423. * @see u_strCompare
  424. * @see u_strCaseCompare
  425. *
  426. * @stable ICU 2.2
  427. */
  428. static inline int32_t
  429. compare(const UnicodeString &s1, const UnicodeString &s2,
  430. uint32_t options,
  431. UErrorCode &errorCode);
  432. #ifndef U_HIDE_DEPRECATED_API
  433. //-------------------------------------------------------------------------
  434. // Iteration API
  435. //-------------------------------------------------------------------------
  436. /**
  437. * Return the current character in the normalized text.
  438. * current() may need to normalize some text at getIndex().
  439. * The getIndex() is not changed.
  440. *
  441. * @return the current normalized code point
  442. * @deprecated ICU 56 Use Normalizer2 instead.
  443. */
  444. UChar32 current(void);
  445. /**
  446. * Return the first character in the normalized text.
  447. * This is equivalent to setIndexOnly(startIndex()) followed by next().
  448. * (Post-increment semantics.)
  449. *
  450. * @return the first normalized code point
  451. * @deprecated ICU 56 Use Normalizer2 instead.
  452. */
  453. UChar32 first(void);
  454. /**
  455. * Return the last character in the normalized text.
  456. * This is equivalent to setIndexOnly(endIndex()) followed by previous().
  457. * (Pre-decrement semantics.)
  458. *
  459. * @return the last normalized code point
  460. * @deprecated ICU 56 Use Normalizer2 instead.
  461. */
  462. UChar32 last(void);
  463. /**
  464. * Return the next character in the normalized text.
  465. * (Post-increment semantics.)
  466. * If the end of the text has already been reached, DONE is returned.
  467. * The DONE value could be confused with a U+FFFF non-character code point
  468. * in the text. If this is possible, you can test getIndex()<endIndex()
  469. * before calling next(), or (getIndex()<endIndex() || last()!=DONE)
  470. * after calling next(). (Calling last() will change the iterator state!)
  471. *
  472. * The C API unorm_next() is more efficient and does not have this ambiguity.
  473. *
  474. * @return the next normalized code point
  475. * @deprecated ICU 56 Use Normalizer2 instead.
  476. */
  477. UChar32 next(void);
  478. /**
  479. * Return the previous character in the normalized text and decrement.
  480. * (Pre-decrement semantics.)
  481. * If the beginning of the text has already been reached, DONE is returned.
  482. * The DONE value could be confused with a U+FFFF non-character code point
  483. * in the text. If this is possible, you can test
  484. * (getIndex()>startIndex() || first()!=DONE). (Calling first() will change
  485. * the iterator state!)
  486. *
  487. * The C API unorm_previous() is more efficient and does not have this ambiguity.
  488. *
  489. * @return the previous normalized code point
  490. * @deprecated ICU 56 Use Normalizer2 instead.
  491. */
  492. UChar32 previous(void);
  493. /**
  494. * Set the iteration position in the input text that is being normalized,
  495. * without any immediate normalization.
  496. * After setIndexOnly(), getIndex() will return the same index that is
  497. * specified here.
  498. *
  499. * @param index the desired index in the input text.
  500. * @deprecated ICU 56 Use Normalizer2 instead.
  501. */
  502. void setIndexOnly(int32_t index);
  503. /**
  504. * Reset the index to the beginning of the text.
  505. * This is equivalent to setIndexOnly(startIndex)).
  506. * @deprecated ICU 56 Use Normalizer2 instead.
  507. */
  508. void reset(void);
  509. /**
  510. * Retrieve the current iteration position in the input text that is
  511. * being normalized.
  512. *
  513. * A following call to next() will return a normalized code point from
  514. * the input text at or after this index.
  515. *
  516. * After a call to previous(), getIndex() will point at or before the
  517. * position in the input text where the normalized code point
  518. * was returned from with previous().
  519. *
  520. * @return the current index in the input text
  521. * @deprecated ICU 56 Use Normalizer2 instead.
  522. */
  523. int32_t getIndex(void) const;
  524. /**
  525. * Retrieve the index of the start of the input text. This is the begin index
  526. * of the <code>CharacterIterator</code> or the start (i.e. index 0) of the string
  527. * over which this <code>Normalizer</code> is iterating.
  528. *
  529. * @return the smallest index in the input text where the Normalizer operates
  530. * @deprecated ICU 56 Use Normalizer2 instead.
  531. */
  532. int32_t startIndex(void) const;
  533. /**
  534. * Retrieve the index of the end of the input text. This is the end index
  535. * of the <code>CharacterIterator</code> or the length of the string
  536. * over which this <code>Normalizer</code> is iterating.
  537. * This end index is exclusive, i.e., the Normalizer operates only on characters
  538. * before this index.
  539. *
  540. * @return the first index in the input text where the Normalizer does not operate
  541. * @deprecated ICU 56 Use Normalizer2 instead.
  542. */
  543. int32_t endIndex(void) const;
  544. /**
  545. * Returns true when both iterators refer to the same character in the same
  546. * input text.
  547. *
  548. * @param that a Normalizer object to compare this one to
  549. * @return comparison result
  550. * @deprecated ICU 56 Use Normalizer2 instead.
  551. */
  552. bool operator==(const Normalizer& that) const;
  553. /**
  554. * Returns false when both iterators refer to the same character in the same
  555. * input text.
  556. *
  557. * @param that a Normalizer object to compare this one to
  558. * @return comparison result
  559. * @deprecated ICU 56 Use Normalizer2 instead.
  560. */
  561. inline bool operator!=(const Normalizer& that) const;
  562. /**
  563. * Returns a pointer to a new Normalizer that is a clone of this one.
  564. * The caller is responsible for deleting the new clone.
  565. * @return a pointer to a new Normalizer
  566. * @deprecated ICU 56 Use Normalizer2 instead.
  567. */
  568. Normalizer* clone() const;
  569. /**
  570. * Generates a hash code for this iterator.
  571. *
  572. * @return the hash code
  573. * @deprecated ICU 56 Use Normalizer2 instead.
  574. */
  575. int32_t hashCode(void) const;
  576. //-------------------------------------------------------------------------
  577. // Property access methods
  578. //-------------------------------------------------------------------------
  579. /**
  580. * Set the normalization mode for this object.
  581. * <p>
  582. * <b>Note:</b>If the normalization mode is changed while iterating
  583. * over a string, calls to {@link #next() } and {@link #previous() } may
  584. * return previously buffers characters in the old normalization mode
  585. * until the iteration is able to re-sync at the next base character.
  586. * It is safest to call {@link #setIndexOnly }, {@link #reset() },
  587. * {@link #setText }, {@link #first() },
  588. * {@link #last() }, etc. after calling <code>setMode</code>.
  589. * <p>
  590. * @param newMode the new mode for this <code>Normalizer</code>.
  591. * @see #getUMode
  592. * @deprecated ICU 56 Use Normalizer2 instead.
  593. */
  594. void setMode(UNormalizationMode newMode);
  595. /**
  596. * Return the normalization mode for this object.
  597. *
  598. * This is an unusual name because there used to be a getMode() that
  599. * returned a different type.
  600. *
  601. * @return the mode for this <code>Normalizer</code>
  602. * @see #setMode
  603. * @deprecated ICU 56 Use Normalizer2 instead.
  604. */
  605. UNormalizationMode getUMode(void) const;
  606. /**
  607. * Set options that affect this <code>Normalizer</code>'s operation.
  608. * Options do not change the basic composition or decomposition operation
  609. * that is being performed, but they control whether
  610. * certain optional portions of the operation are done.
  611. * Currently the only available option is obsolete.
  612. *
  613. * It is possible to specify multiple options that are all turned on or off.
  614. *
  615. * @param option the option(s) whose value is/are to be set.
  616. * @param value the new setting for the option. Use <code>true</code> to
  617. * turn the option(s) on and <code>false</code> to turn it/them off.
  618. *
  619. * @see #getOption
  620. * @deprecated ICU 56 Use Normalizer2 instead.
  621. */
  622. void setOption(int32_t option,
  623. UBool value);
  624. /**
  625. * Determine whether an option is turned on or off.
  626. * If multiple options are specified, then the result is true if any
  627. * of them are set.
  628. * <p>
  629. * @param option the option(s) that are to be checked
  630. * @return true if any of the option(s) are set
  631. * @see #setOption
  632. * @deprecated ICU 56 Use Normalizer2 instead.
  633. */
  634. UBool getOption(int32_t option) const;
  635. /**
  636. * Set the input text over which this <code>Normalizer</code> will iterate.
  637. * The iteration position is set to the beginning.
  638. *
  639. * @param newText a string that replaces the current input text
  640. * @param status a UErrorCode
  641. * @deprecated ICU 56 Use Normalizer2 instead.
  642. */
  643. void setText(const UnicodeString& newText,
  644. UErrorCode &status);
  645. /**
  646. * Set the input text over which this <code>Normalizer</code> will iterate.
  647. * The iteration position is set to the beginning.
  648. *
  649. * @param newText a CharacterIterator object that replaces the current input text
  650. * @param status a UErrorCode
  651. * @deprecated ICU 56 Use Normalizer2 instead.
  652. */
  653. void setText(const CharacterIterator& newText,
  654. UErrorCode &status);
  655. /**
  656. * Set the input text over which this <code>Normalizer</code> will iterate.
  657. * The iteration position is set to the beginning.
  658. *
  659. * @param newText a string that replaces the current input text
  660. * @param length the length of the string, or -1 if NUL-terminated
  661. * @param status a UErrorCode
  662. * @deprecated ICU 56 Use Normalizer2 instead.
  663. */
  664. void setText(ConstChar16Ptr newText,
  665. int32_t length,
  666. UErrorCode &status);
  667. /**
  668. * Copies the input text into the UnicodeString argument.
  669. *
  670. * @param result Receives a copy of the text under iteration.
  671. * @deprecated ICU 56 Use Normalizer2 instead.
  672. */
  673. void getText(UnicodeString& result);
  674. /**
  675. * ICU "poor man's RTTI", returns a UClassID for this class.
  676. * @returns a UClassID for this class.
  677. * @deprecated ICU 56 Use Normalizer2 instead.
  678. */
  679. static UClassID U_EXPORT2 getStaticClassID();
  680. #endif /* U_HIDE_DEPRECATED_API */
  681. #ifndef U_FORCE_HIDE_DEPRECATED_API
  682. /**
  683. * ICU "poor man's RTTI", returns a UClassID for the actual class.
  684. * @return a UClassID for the actual class.
  685. * @deprecated ICU 56 Use Normalizer2 instead.
  686. */
  687. virtual UClassID getDynamicClassID() const override;
  688. #endif // U_FORCE_HIDE_DEPRECATED_API
  689. private:
  690. //-------------------------------------------------------------------------
  691. // Private functions
  692. //-------------------------------------------------------------------------
  693. Normalizer() = delete; // default constructor not implemented
  694. Normalizer &operator=(const Normalizer &that) = delete; // assignment operator not implemented
  695. // Private utility methods for iteration
  696. // For documentation, see the source code
  697. UBool nextNormalize();
  698. UBool previousNormalize();
  699. void init();
  700. void clearBuffer(void);
  701. //-------------------------------------------------------------------------
  702. // Private data
  703. //-------------------------------------------------------------------------
  704. FilteredNormalizer2*fFilteredNorm2; // owned if not nullptr
  705. const Normalizer2 *fNorm2; // not owned; may be equal to fFilteredNorm2
  706. UNormalizationMode fUMode; // deprecated
  707. int32_t fOptions;
  708. // The input text and our position in it
  709. CharacterIterator *text;
  710. // The normalization buffer is the result of normalization
  711. // of the source in [currentIndex..nextIndex[ .
  712. int32_t currentIndex, nextIndex;
  713. // A buffer for holding intermediate results
  714. UnicodeString buffer;
  715. int32_t bufferPos;
  716. };
  717. //-------------------------------------------------------------------------
  718. // Inline implementations
  719. //-------------------------------------------------------------------------
  720. #ifndef U_HIDE_DEPRECATED_API
  721. inline bool
  722. Normalizer::operator!= (const Normalizer& other) const
  723. { return ! operator==(other); }
  724. inline UNormalizationCheckResult
  725. Normalizer::quickCheck(const UnicodeString& source,
  726. UNormalizationMode mode,
  727. UErrorCode &status) {
  728. return quickCheck(source, mode, 0, status);
  729. }
  730. inline UBool
  731. Normalizer::isNormalized(const UnicodeString& source,
  732. UNormalizationMode mode,
  733. UErrorCode &status) {
  734. return isNormalized(source, mode, 0, status);
  735. }
  736. #endif /* U_HIDE_DEPRECATED_API */
  737. inline int32_t
  738. Normalizer::compare(const UnicodeString &s1, const UnicodeString &s2,
  739. uint32_t options,
  740. UErrorCode &errorCode) {
  741. // all argument checking is done in unorm_compare
  742. return unorm_compare(toUCharPtr(s1.getBuffer()), s1.length(),
  743. toUCharPtr(s2.getBuffer()), s2.length(),
  744. options,
  745. &errorCode);
  746. }
  747. U_NAMESPACE_END
  748. #endif /* #if !UCONFIG_NO_NORMALIZATION */
  749. #endif // NORMLZR_H
  750. #endif /* U_SHOW_CPLUSPLUS_API */