normalizer2.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. // Copyright (C) 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. *******************************************************************************
  5. *
  6. * Copyright (C) 2009-2013, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. *******************************************************************************
  10. * file name: normalizer2.h
  11. * encoding: US-ASCII
  12. * tab size: 8 (not used)
  13. * indentation:4
  14. *
  15. * created on: 2009nov22
  16. * created by: Markus W. Scherer
  17. */
  18. #ifndef __NORMALIZER2_H__
  19. #define __NORMALIZER2_H__
  20. /**
  21. * \file
  22. * \brief C++ API: New API for Unicode Normalization.
  23. */
  24. #include "utypes.h"
  25. #if !UCONFIG_NO_NORMALIZATION
  26. #include "uniset.h"
  27. #include "unistr.h"
  28. #include "unorm2.h"
  29. U_NAMESPACE_BEGIN
  30. /**
  31. * Unicode normalization functionality for standard Unicode normalization or
  32. * for using custom mapping tables.
  33. * All instances of this class are unmodifiable/immutable.
  34. * Instances returned by getInstance() are singletons that must not be deleted by the caller.
  35. * The Normalizer2 class is not intended for public subclassing.
  36. *
  37. * The primary functions are to produce a normalized string and to detect whether
  38. * a string is already normalized.
  39. * The most commonly used normalization forms are those defined in
  40. * http://www.unicode.org/unicode/reports/tr15/
  41. * However, this API supports additional normalization forms for specialized purposes.
  42. * For example, NFKC_Casefold is provided via getInstance("nfkc_cf", COMPOSE)
  43. * and can be used in implementations of UTS #46.
  44. *
  45. * Not only are the standard compose and decompose modes supplied,
  46. * but additional modes are provided as documented in the Mode enum.
  47. *
  48. * Some of the functions in this class identify normalization boundaries.
  49. * At a normalization boundary, the portions of the string
  50. * before it and starting from it do not interact and can be handled independently.
  51. *
  52. * The spanQuickCheckYes() stops at a normalization boundary.
  53. * When the goal is a normalized string, then the text before the boundary
  54. * can be copied, and the remainder can be processed with normalizeSecondAndAppend().
  55. *
  56. * The hasBoundaryBefore(), hasBoundaryAfter() and isInert() functions test whether
  57. * a character is guaranteed to be at a normalization boundary,
  58. * regardless of context.
  59. * This is used for moving from one normalization boundary to the next
  60. * or preceding boundary, and for performing iterative normalization.
  61. *
  62. * Iterative normalization is useful when only a small portion of a
  63. * longer string needs to be processed.
  64. * For example, in ICU, iterative normalization is used by the NormalizationTransliterator
  65. * (to avoid replacing already-normalized text) and ucol_nextSortKeyPart()
  66. * (to process only the substring for which sort key bytes are computed).
  67. *
  68. * The set of normalization boundaries returned by these functions may not be
  69. * complete: There may be more boundaries that could be returned.
  70. * Different functions may return different boundaries.
  71. * @stable ICU 4.4
  72. */
  73. class U_COMMON_API Normalizer2 : public UObject {
  74. public:
  75. /**
  76. * Destructor.
  77. * @stable ICU 4.4
  78. */
  79. ~Normalizer2();
  80. /**
  81. * Returns a Normalizer2 instance for Unicode NFC normalization.
  82. * Same as getInstance(NULL, "nfc", UNORM2_COMPOSE, errorCode).
  83. * Returns an unmodifiable singleton instance. Do not delete it.
  84. * @param errorCode Standard ICU error code. Its input value must
  85. * pass the U_SUCCESS() test, or else the function returns
  86. * immediately. Check for U_FAILURE() on output or use with
  87. * function chaining. (See User Guide for details.)
  88. * @return the requested Normalizer2, if successful
  89. * @stable ICU 49
  90. */
  91. static const Normalizer2 *
  92. getNFCInstance(UErrorCode &errorCode);
  93. /**
  94. * Returns a Normalizer2 instance for Unicode NFD normalization.
  95. * Same as getInstance(NULL, "nfc", UNORM2_DECOMPOSE, errorCode).
  96. * Returns an unmodifiable singleton instance. Do not delete it.
  97. * @param errorCode Standard ICU error code. Its input value must
  98. * pass the U_SUCCESS() test, or else the function returns
  99. * immediately. Check for U_FAILURE() on output or use with
  100. * function chaining. (See User Guide for details.)
  101. * @return the requested Normalizer2, if successful
  102. * @stable ICU 49
  103. */
  104. static const Normalizer2 *
  105. getNFDInstance(UErrorCode &errorCode);
  106. /**
  107. * Returns a Normalizer2 instance for Unicode NFKC normalization.
  108. * Same as getInstance(NULL, "nfkc", UNORM2_COMPOSE, errorCode).
  109. * Returns an unmodifiable singleton instance. Do not delete it.
  110. * @param errorCode Standard ICU error code. Its input value must
  111. * pass the U_SUCCESS() test, or else the function returns
  112. * immediately. Check for U_FAILURE() on output or use with
  113. * function chaining. (See User Guide for details.)
  114. * @return the requested Normalizer2, if successful
  115. * @stable ICU 49
  116. */
  117. static const Normalizer2 *
  118. getNFKCInstance(UErrorCode &errorCode);
  119. /**
  120. * Returns a Normalizer2 instance for Unicode NFKD normalization.
  121. * Same as getInstance(NULL, "nfkc", UNORM2_DECOMPOSE, errorCode).
  122. * Returns an unmodifiable singleton instance. Do not delete it.
  123. * @param errorCode Standard ICU error code. Its input value must
  124. * pass the U_SUCCESS() test, or else the function returns
  125. * immediately. Check for U_FAILURE() on output or use with
  126. * function chaining. (See User Guide for details.)
  127. * @return the requested Normalizer2, if successful
  128. * @stable ICU 49
  129. */
  130. static const Normalizer2 *
  131. getNFKDInstance(UErrorCode &errorCode);
  132. /**
  133. * Returns a Normalizer2 instance for Unicode NFKC_Casefold normalization.
  134. * Same as getInstance(NULL, "nfkc_cf", UNORM2_COMPOSE, errorCode).
  135. * Returns an unmodifiable singleton instance. Do not delete it.
  136. * @param errorCode Standard ICU error code. Its input value must
  137. * pass the U_SUCCESS() test, or else the function returns
  138. * immediately. Check for U_FAILURE() on output or use with
  139. * function chaining. (See User Guide for details.)
  140. * @return the requested Normalizer2, if successful
  141. * @stable ICU 49
  142. */
  143. static const Normalizer2 *
  144. getNFKCCasefoldInstance(UErrorCode &errorCode);
  145. /**
  146. * Returns a Normalizer2 instance which uses the specified data file
  147. * (packageName/name similar to ucnv_openPackage() and ures_open()/ResourceBundle)
  148. * and which composes or decomposes text according to the specified mode.
  149. * Returns an unmodifiable singleton instance. Do not delete it.
  150. *
  151. * Use packageName=NULL for data files that are part of ICU's own data.
  152. * Use name="nfc" and UNORM2_COMPOSE/UNORM2_DECOMPOSE for Unicode standard NFC/NFD.
  153. * Use name="nfkc" and UNORM2_COMPOSE/UNORM2_DECOMPOSE for Unicode standard NFKC/NFKD.
  154. * Use name="nfkc_cf" and UNORM2_COMPOSE for Unicode standard NFKC_CF=NFKC_Casefold.
  155. *
  156. * @param packageName NULL for ICU built-in data, otherwise application data package name
  157. * @param name "nfc" or "nfkc" or "nfkc_cf" or name of custom data file
  158. * @param mode normalization mode (compose or decompose etc.)
  159. * @param errorCode Standard ICU error code. Its input value must
  160. * pass the U_SUCCESS() test, or else the function returns
  161. * immediately. Check for U_FAILURE() on output or use with
  162. * function chaining. (See User Guide for details.)
  163. * @return the requested Normalizer2, if successful
  164. * @stable ICU 4.4
  165. */
  166. static const Normalizer2 *
  167. getInstance(const char *packageName,
  168. const char *name,
  169. UNormalization2Mode mode,
  170. UErrorCode &errorCode);
  171. /**
  172. * Returns the normalized form of the source string.
  173. * @param src source string
  174. * @param errorCode Standard ICU error code. Its input value must
  175. * pass the U_SUCCESS() test, or else the function returns
  176. * immediately. Check for U_FAILURE() on output or use with
  177. * function chaining. (See User Guide for details.)
  178. * @return normalized src
  179. * @stable ICU 4.4
  180. */
  181. UnicodeString
  182. normalize(const UnicodeString &src, UErrorCode &errorCode) const {
  183. UnicodeString result;
  184. normalize(src, result, errorCode);
  185. return result;
  186. }
  187. /**
  188. * Writes the normalized form of the source string to the destination string
  189. * (replacing its contents) and returns the destination string.
  190. * The source and destination strings must be different objects.
  191. * @param src source string
  192. * @param dest destination string; its contents is replaced with normalized src
  193. * @param errorCode Standard ICU error code. Its input value must
  194. * pass the U_SUCCESS() test, or else the function returns
  195. * immediately. Check for U_FAILURE() on output or use with
  196. * function chaining. (See User Guide for details.)
  197. * @return dest
  198. * @stable ICU 4.4
  199. */
  200. virtual UnicodeString &
  201. normalize(const UnicodeString &src,
  202. UnicodeString &dest,
  203. UErrorCode &errorCode) const = 0;
  204. /**
  205. * Appends the normalized form of the second string to the first string
  206. * (merging them at the boundary) and returns the first string.
  207. * The result is normalized if the first string was normalized.
  208. * The first and second strings must be different objects.
  209. * @param first string, should be normalized
  210. * @param second string, will be normalized
  211. * @param errorCode Standard ICU error code. Its input value must
  212. * pass the U_SUCCESS() test, or else the function returns
  213. * immediately. Check for U_FAILURE() on output or use with
  214. * function chaining. (See User Guide for details.)
  215. * @return first
  216. * @stable ICU 4.4
  217. */
  218. virtual UnicodeString &
  219. normalizeSecondAndAppend(UnicodeString &first,
  220. const UnicodeString &second,
  221. UErrorCode &errorCode) const = 0;
  222. /**
  223. * Appends the second string to the first string
  224. * (merging them at the boundary) and returns the first string.
  225. * The result is normalized if both the strings were normalized.
  226. * The first and second strings must be different objects.
  227. * @param first string, should be normalized
  228. * @param second string, should be normalized
  229. * @param errorCode Standard ICU error code. Its input value must
  230. * pass the U_SUCCESS() test, or else the function returns
  231. * immediately. Check for U_FAILURE() on output or use with
  232. * function chaining. (See User Guide for details.)
  233. * @return first
  234. * @stable ICU 4.4
  235. */
  236. virtual UnicodeString &
  237. append(UnicodeString &first,
  238. const UnicodeString &second,
  239. UErrorCode &errorCode) const = 0;
  240. /**
  241. * Gets the decomposition mapping of c.
  242. * Roughly equivalent to normalizing the String form of c
  243. * on a UNORM2_DECOMPOSE Normalizer2 instance, but much faster, and except that this function
  244. * returns FALSE and does not write a string
  245. * if c does not have a decomposition mapping in this instance's data.
  246. * This function is independent of the mode of the Normalizer2.
  247. * @param c code point
  248. * @param decomposition String object which will be set to c's
  249. * decomposition mapping, if there is one.
  250. * @return TRUE if c has a decomposition, otherwise FALSE
  251. * @stable ICU 4.6
  252. */
  253. virtual UBool
  254. getDecomposition(UChar32 c, UnicodeString &decomposition) const = 0;
  255. /**
  256. * Gets the raw decomposition mapping of c.
  257. *
  258. * This is similar to the getDecomposition() method but returns the
  259. * raw decomposition mapping as specified in UnicodeData.txt or
  260. * (for custom data) in the mapping files processed by the gennorm2 tool.
  261. * By contrast, getDecomposition() returns the processed,
  262. * recursively-decomposed version of this mapping.
  263. *
  264. * When used on a standard NFKC Normalizer2 instance,
  265. * getRawDecomposition() returns the Unicode Decomposition_Mapping (dm) property.
  266. *
  267. * When used on a standard NFC Normalizer2 instance,
  268. * it returns the Decomposition_Mapping only if the Decomposition_Type (dt) is Canonical (Can);
  269. * in this case, the result contains either one or two code points (=1..4 UChars).
  270. *
  271. * This function is independent of the mode of the Normalizer2.
  272. * The default implementation returns FALSE.
  273. * @param c code point
  274. * @param decomposition String object which will be set to c's
  275. * raw decomposition mapping, if there is one.
  276. * @return TRUE if c has a decomposition, otherwise FALSE
  277. * @stable ICU 49
  278. */
  279. virtual UBool
  280. getRawDecomposition(UChar32 c, UnicodeString &decomposition) const;
  281. /**
  282. * Performs pairwise composition of a & b and returns the composite if there is one.
  283. *
  284. * Returns a composite code point c only if c has a two-way mapping to a+b.
  285. * In standard Unicode normalization, this means that
  286. * c has a canonical decomposition to a+b
  287. * and c does not have the Full_Composition_Exclusion property.
  288. *
  289. * This function is independent of the mode of the Normalizer2.
  290. * The default implementation returns a negative value.
  291. * @param a A (normalization starter) code point.
  292. * @param b Another code point.
  293. * @return The non-negative composite code point if there is one; otherwise a negative value.
  294. * @stable ICU 49
  295. */
  296. virtual UChar32
  297. composePair(UChar32 a, UChar32 b) const;
  298. /**
  299. * Gets the combining class of c.
  300. * The default implementation returns 0
  301. * but all standard implementations return the Unicode Canonical_Combining_Class value.
  302. * @param c code point
  303. * @return c's combining class
  304. * @stable ICU 49
  305. */
  306. virtual uint8_t
  307. getCombiningClass(UChar32 c) const;
  308. /**
  309. * Tests if the string is normalized.
  310. * Internally, in cases where the quickCheck() method would return "maybe"
  311. * (which is only possible for the two COMPOSE modes) this method
  312. * resolves to "yes" or "no" to provide a definitive result,
  313. * at the cost of doing more work in those cases.
  314. * @param s input string
  315. * @param errorCode Standard ICU error code. Its input value must
  316. * pass the U_SUCCESS() test, or else the function returns
  317. * immediately. Check for U_FAILURE() on output or use with
  318. * function chaining. (See User Guide for details.)
  319. * @return TRUE if s is normalized
  320. * @stable ICU 4.4
  321. */
  322. virtual UBool
  323. isNormalized(const UnicodeString &s, UErrorCode &errorCode) const = 0;
  324. /**
  325. * Tests if the string is normalized.
  326. * For the two COMPOSE modes, the result could be "maybe" in cases that
  327. * would take a little more work to resolve definitively.
  328. * Use spanQuickCheckYes() and normalizeSecondAndAppend() for a faster
  329. * combination of quick check + normalization, to avoid
  330. * re-checking the "yes" prefix.
  331. * @param s input string
  332. * @param errorCode Standard ICU error code. Its input value must
  333. * pass the U_SUCCESS() test, or else the function returns
  334. * immediately. Check for U_FAILURE() on output or use with
  335. * function chaining. (See User Guide for details.)
  336. * @return UNormalizationCheckResult
  337. * @stable ICU 4.4
  338. */
  339. virtual UNormalizationCheckResult
  340. quickCheck(const UnicodeString &s, UErrorCode &errorCode) const = 0;
  341. /**
  342. * Returns the end of the normalized substring of the input string.
  343. * In other words, with <code>end=spanQuickCheckYes(s, ec);</code>
  344. * the substring <code>UnicodeString(s, 0, end)</code>
  345. * will pass the quick check with a "yes" result.
  346. *
  347. * The returned end index is usually one or more characters before the
  348. * "no" or "maybe" character: The end index is at a normalization boundary.
  349. * (See the class documentation for more about normalization boundaries.)
  350. *
  351. * When the goal is a normalized string and most input strings are expected
  352. * to be normalized already, then call this method,
  353. * and if it returns a prefix shorter than the input string,
  354. * copy that prefix and use normalizeSecondAndAppend() for the remainder.
  355. * @param s input string
  356. * @param errorCode Standard ICU error code. Its input value must
  357. * pass the U_SUCCESS() test, or else the function returns
  358. * immediately. Check for U_FAILURE() on output or use with
  359. * function chaining. (See User Guide for details.)
  360. * @return "yes" span end index
  361. * @stable ICU 4.4
  362. */
  363. virtual int32_t
  364. spanQuickCheckYes(const UnicodeString &s, UErrorCode &errorCode) const = 0;
  365. /**
  366. * Tests if the character always has a normalization boundary before it,
  367. * regardless of context.
  368. * If true, then the character does not normalization-interact with
  369. * preceding characters.
  370. * In other words, a string containing this character can be normalized
  371. * by processing portions before this character and starting from this
  372. * character independently.
  373. * This is used for iterative normalization. See the class documentation for details.
  374. * @param c character to test
  375. * @return TRUE if c has a normalization boundary before it
  376. * @stable ICU 4.4
  377. */
  378. virtual UBool hasBoundaryBefore(UChar32 c) const = 0;
  379. /**
  380. * Tests if the character always has a normalization boundary after it,
  381. * regardless of context.
  382. * If true, then the character does not normalization-interact with
  383. * following characters.
  384. * In other words, a string containing this character can be normalized
  385. * by processing portions up to this character and after this
  386. * character independently.
  387. * This is used for iterative normalization. See the class documentation for details.
  388. * Note that this operation may be significantly slower than hasBoundaryBefore().
  389. * @param c character to test
  390. * @return TRUE if c has a normalization boundary after it
  391. * @stable ICU 4.4
  392. */
  393. virtual UBool hasBoundaryAfter(UChar32 c) const = 0;
  394. /**
  395. * Tests if the character is normalization-inert.
  396. * If true, then the character does not change, nor normalization-interact with
  397. * preceding or following characters.
  398. * In other words, a string containing this character can be normalized
  399. * by processing portions before this character and after this
  400. * character independently.
  401. * This is used for iterative normalization. See the class documentation for details.
  402. * Note that this operation may be significantly slower than hasBoundaryBefore().
  403. * @param c character to test
  404. * @return TRUE if c is normalization-inert
  405. * @stable ICU 4.4
  406. */
  407. virtual UBool isInert(UChar32 c) const = 0;
  408. };
  409. /**
  410. * Normalization filtered by a UnicodeSet.
  411. * Normalizes portions of the text contained in the filter set and leaves
  412. * portions not contained in the filter set unchanged.
  413. * Filtering is done via UnicodeSet::span(..., USET_SPAN_SIMPLE).
  414. * Not-in-the-filter text is treated as "is normalized" and "quick check yes".
  415. * This class implements all of (and only) the Normalizer2 API.
  416. * An instance of this class is unmodifiable/immutable but is constructed and
  417. * must be destructed by the owner.
  418. * @stable ICU 4.4
  419. */
  420. class U_COMMON_API FilteredNormalizer2 : public Normalizer2 {
  421. public:
  422. /**
  423. * Constructs a filtered normalizer wrapping any Normalizer2 instance
  424. * and a filter set.
  425. * Both are aliased and must not be modified or deleted while this object
  426. * is used.
  427. * The filter set should be frozen; otherwise the performance will suffer greatly.
  428. * @param n2 wrapped Normalizer2 instance
  429. * @param filterSet UnicodeSet which determines the characters to be normalized
  430. * @stable ICU 4.4
  431. */
  432. FilteredNormalizer2(const Normalizer2 &n2, const UnicodeSet &filterSet) :
  433. norm2(n2), set(filterSet) {}
  434. /**
  435. * Destructor.
  436. * @stable ICU 4.4
  437. */
  438. ~FilteredNormalizer2();
  439. /**
  440. * Writes the normalized form of the source string to the destination string
  441. * (replacing its contents) and returns the destination string.
  442. * The source and destination strings must be different objects.
  443. * @param src source string
  444. * @param dest destination string; its contents is replaced with normalized src
  445. * @param errorCode Standard ICU error code. Its input value must
  446. * pass the U_SUCCESS() test, or else the function returns
  447. * immediately. Check for U_FAILURE() on output or use with
  448. * function chaining. (See User Guide for details.)
  449. * @return dest
  450. * @stable ICU 4.4
  451. */
  452. virtual UnicodeString &
  453. normalize(const UnicodeString &src,
  454. UnicodeString &dest,
  455. UErrorCode &errorCode) const;
  456. /**
  457. * Appends the normalized form of the second string to the first string
  458. * (merging them at the boundary) and returns the first string.
  459. * The result is normalized if the first string was normalized.
  460. * The first and second strings must be different objects.
  461. * @param first string, should be normalized
  462. * @param second string, will be normalized
  463. * @param errorCode Standard ICU error code. Its input value must
  464. * pass the U_SUCCESS() test, or else the function returns
  465. * immediately. Check for U_FAILURE() on output or use with
  466. * function chaining. (See User Guide for details.)
  467. * @return first
  468. * @stable ICU 4.4
  469. */
  470. virtual UnicodeString &
  471. normalizeSecondAndAppend(UnicodeString &first,
  472. const UnicodeString &second,
  473. UErrorCode &errorCode) const;
  474. /**
  475. * Appends the second string to the first string
  476. * (merging them at the boundary) and returns the first string.
  477. * The result is normalized if both the strings were normalized.
  478. * The first and second strings must be different objects.
  479. * @param first string, should be normalized
  480. * @param second string, should be normalized
  481. * @param errorCode Standard ICU error code. Its input value must
  482. * pass the U_SUCCESS() test, or else the function returns
  483. * immediately. Check for U_FAILURE() on output or use with
  484. * function chaining. (See User Guide for details.)
  485. * @return first
  486. * @stable ICU 4.4
  487. */
  488. virtual UnicodeString &
  489. append(UnicodeString &first,
  490. const UnicodeString &second,
  491. UErrorCode &errorCode) const;
  492. /**
  493. * Gets the decomposition mapping of c.
  494. * For details see the base class documentation.
  495. *
  496. * This function is independent of the mode of the Normalizer2.
  497. * @param c code point
  498. * @param decomposition String object which will be set to c's
  499. * decomposition mapping, if there is one.
  500. * @return TRUE if c has a decomposition, otherwise FALSE
  501. * @stable ICU 4.6
  502. */
  503. virtual UBool
  504. getDecomposition(UChar32 c, UnicodeString &decomposition) const;
  505. /**
  506. * Gets the raw decomposition mapping of c.
  507. * For details see the base class documentation.
  508. *
  509. * This function is independent of the mode of the Normalizer2.
  510. * @param c code point
  511. * @param decomposition String object which will be set to c's
  512. * raw decomposition mapping, if there is one.
  513. * @return TRUE if c has a decomposition, otherwise FALSE
  514. * @stable ICU 49
  515. */
  516. virtual UBool
  517. getRawDecomposition(UChar32 c, UnicodeString &decomposition) const;
  518. /**
  519. * Performs pairwise composition of a & b and returns the composite if there is one.
  520. * For details see the base class documentation.
  521. *
  522. * This function is independent of the mode of the Normalizer2.
  523. * @param a A (normalization starter) code point.
  524. * @param b Another code point.
  525. * @return The non-negative composite code point if there is one; otherwise a negative value.
  526. * @stable ICU 49
  527. */
  528. virtual UChar32
  529. composePair(UChar32 a, UChar32 b) const;
  530. /**
  531. * Gets the combining class of c.
  532. * The default implementation returns 0
  533. * but all standard implementations return the Unicode Canonical_Combining_Class value.
  534. * @param c code point
  535. * @return c's combining class
  536. * @stable ICU 49
  537. */
  538. virtual uint8_t
  539. getCombiningClass(UChar32 c) const;
  540. /**
  541. * Tests if the string is normalized.
  542. * For details see the Normalizer2 base class documentation.
  543. * @param s input string
  544. * @param errorCode Standard ICU error code. Its input value must
  545. * pass the U_SUCCESS() test, or else the function returns
  546. * immediately. Check for U_FAILURE() on output or use with
  547. * function chaining. (See User Guide for details.)
  548. * @return TRUE if s is normalized
  549. * @stable ICU 4.4
  550. */
  551. virtual UBool
  552. isNormalized(const UnicodeString &s, UErrorCode &errorCode) const;
  553. /**
  554. * Tests if the string is normalized.
  555. * For details see the Normalizer2 base class documentation.
  556. * @param s input string
  557. * @param errorCode Standard ICU error code. Its input value must
  558. * pass the U_SUCCESS() test, or else the function returns
  559. * immediately. Check for U_FAILURE() on output or use with
  560. * function chaining. (See User Guide for details.)
  561. * @return UNormalizationCheckResult
  562. * @stable ICU 4.4
  563. */
  564. virtual UNormalizationCheckResult
  565. quickCheck(const UnicodeString &s, UErrorCode &errorCode) const;
  566. /**
  567. * Returns the end of the normalized substring of the input string.
  568. * For details see the Normalizer2 base class documentation.
  569. * @param s input string
  570. * @param errorCode Standard ICU error code. Its input value must
  571. * pass the U_SUCCESS() test, or else the function returns
  572. * immediately. Check for U_FAILURE() on output or use with
  573. * function chaining. (See User Guide for details.)
  574. * @return "yes" span end index
  575. * @stable ICU 4.4
  576. */
  577. virtual int32_t
  578. spanQuickCheckYes(const UnicodeString &s, UErrorCode &errorCode) const;
  579. /**
  580. * Tests if the character always has a normalization boundary before it,
  581. * regardless of context.
  582. * For details see the Normalizer2 base class documentation.
  583. * @param c character to test
  584. * @return TRUE if c has a normalization boundary before it
  585. * @stable ICU 4.4
  586. */
  587. virtual UBool hasBoundaryBefore(UChar32 c) const;
  588. /**
  589. * Tests if the character always has a normalization boundary after it,
  590. * regardless of context.
  591. * For details see the Normalizer2 base class documentation.
  592. * @param c character to test
  593. * @return TRUE if c has a normalization boundary after it
  594. * @stable ICU 4.4
  595. */
  596. virtual UBool hasBoundaryAfter(UChar32 c) const;
  597. /**
  598. * Tests if the character is normalization-inert.
  599. * For details see the Normalizer2 base class documentation.
  600. * @param c character to test
  601. * @return TRUE if c is normalization-inert
  602. * @stable ICU 4.4
  603. */
  604. virtual UBool isInert(UChar32 c) const;
  605. private:
  606. UnicodeString &
  607. normalize(const UnicodeString &src,
  608. UnicodeString &dest,
  609. USetSpanCondition spanCondition,
  610. UErrorCode &errorCode) const;
  611. UnicodeString &
  612. normalizeSecondAndAppend(UnicodeString &first,
  613. const UnicodeString &second,
  614. UBool doNormalize,
  615. UErrorCode &errorCode) const;
  616. const Normalizer2 &norm2;
  617. const UnicodeSet &set;
  618. };
  619. U_NAMESPACE_END
  620. #endif // !UCONFIG_NO_NORMALIZATION
  621. #endif // __NORMALIZER2_H__