normlzr.h 31 KB

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