unorm2.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. // © 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-2015, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. *******************************************************************************
  10. * file name: unorm2.h
  11. * encoding: UTF-8
  12. * tab size: 8 (not used)
  13. * indentation:4
  14. *
  15. * created on: 2009dec15
  16. * created by: Markus W. Scherer
  17. */
  18. #ifndef __UNORM2_H__
  19. #define __UNORM2_H__
  20. /**
  21. * \file
  22. * \brief C API: New API for Unicode Normalization.
  23. *
  24. * Unicode normalization functionality for standard Unicode normalization or
  25. * for using custom mapping tables.
  26. * All instances of UNormalizer2 are unmodifiable/immutable.
  27. * Instances returned by unorm2_getInstance() are singletons that must not be deleted by the caller.
  28. * For more details see the Normalizer2 C++ class.
  29. */
  30. #include "unicode/utypes.h"
  31. #include "unicode/stringoptions.h"
  32. #include "unicode/uset.h"
  33. #if U_SHOW_CPLUSPLUS_API
  34. #include "unicode/localpointer.h"
  35. #endif // U_SHOW_CPLUSPLUS_API
  36. /**
  37. * Constants for normalization modes.
  38. * For details about standard Unicode normalization forms
  39. * and about the algorithms which are also used with custom mapping tables
  40. * see http://www.unicode.org/unicode/reports/tr15/
  41. * @stable ICU 4.4
  42. */
  43. typedef enum {
  44. /**
  45. * Decomposition followed by composition.
  46. * Same as standard NFC when using an "nfc" instance.
  47. * Same as standard NFKC when using an "nfkc" instance.
  48. * For details about standard Unicode normalization forms
  49. * see http://www.unicode.org/unicode/reports/tr15/
  50. * @stable ICU 4.4
  51. */
  52. UNORM2_COMPOSE,
  53. /**
  54. * Map, and reorder canonically.
  55. * Same as standard NFD when using an "nfc" instance.
  56. * Same as standard NFKD when using an "nfkc" instance.
  57. * For details about standard Unicode normalization forms
  58. * see http://www.unicode.org/unicode/reports/tr15/
  59. * @stable ICU 4.4
  60. */
  61. UNORM2_DECOMPOSE,
  62. /**
  63. * "Fast C or D" form.
  64. * If a string is in this form, then further decomposition <i>without reordering</i>
  65. * would yield the same form as DECOMPOSE.
  66. * Text in "Fast C or D" form can be processed efficiently with data tables
  67. * that are "canonically closed", that is, that provide equivalent data for
  68. * equivalent text, without having to be fully normalized.
  69. * Not a standard Unicode normalization form.
  70. * Not a unique form: Different FCD strings can be canonically equivalent.
  71. * For details see http://www.unicode.org/notes/tn5/#FCD
  72. * @stable ICU 4.4
  73. */
  74. UNORM2_FCD,
  75. /**
  76. * Compose only contiguously.
  77. * Also known as "FCC" or "Fast C Contiguous".
  78. * The result will often but not always be in NFC.
  79. * The result will conform to FCD which is useful for processing.
  80. * Not a standard Unicode normalization form.
  81. * For details see http://www.unicode.org/notes/tn5/#FCC
  82. * @stable ICU 4.4
  83. */
  84. UNORM2_COMPOSE_CONTIGUOUS
  85. } UNormalization2Mode;
  86. /**
  87. * Result values for normalization quick check functions.
  88. * For details see http://www.unicode.org/reports/tr15/#Detecting_Normalization_Forms
  89. * @stable ICU 2.0
  90. */
  91. typedef enum UNormalizationCheckResult {
  92. /**
  93. * The input string is not in the normalization form.
  94. * @stable ICU 2.0
  95. */
  96. UNORM_NO,
  97. /**
  98. * The input string is in the normalization form.
  99. * @stable ICU 2.0
  100. */
  101. UNORM_YES,
  102. /**
  103. * The input string may or may not be in the normalization form.
  104. * This value is only returned for composition forms like NFC and FCC,
  105. * when a backward-combining character is found for which the surrounding text
  106. * would have to be analyzed further.
  107. * @stable ICU 2.0
  108. */
  109. UNORM_MAYBE
  110. } UNormalizationCheckResult;
  111. /**
  112. * Opaque C service object type for the new normalization API.
  113. * @stable ICU 4.4
  114. */
  115. struct UNormalizer2;
  116. typedef struct UNormalizer2 UNormalizer2; /**< C typedef for struct UNormalizer2. @stable ICU 4.4 */
  117. #if !UCONFIG_NO_NORMALIZATION
  118. /**
  119. * Returns a UNormalizer2 instance for Unicode NFC normalization.
  120. * Same as unorm2_getInstance(NULL, "nfc", UNORM2_COMPOSE, pErrorCode).
  121. * Returns an unmodifiable singleton instance. Do not delete it.
  122. * @param pErrorCode Standard ICU error code. Its input value must
  123. * pass the U_SUCCESS() test, or else the function returns
  124. * immediately. Check for U_FAILURE() on output or use with
  125. * function chaining. (See User Guide for details.)
  126. * @return the requested Normalizer2, if successful
  127. * @stable ICU 49
  128. */
  129. U_CAPI const UNormalizer2 * U_EXPORT2
  130. unorm2_getNFCInstance(UErrorCode *pErrorCode);
  131. /**
  132. * Returns a UNormalizer2 instance for Unicode NFD normalization.
  133. * Same as unorm2_getInstance(NULL, "nfc", UNORM2_DECOMPOSE, pErrorCode).
  134. * Returns an unmodifiable singleton instance. Do not delete it.
  135. * @param pErrorCode Standard ICU error code. Its input value must
  136. * pass the U_SUCCESS() test, or else the function returns
  137. * immediately. Check for U_FAILURE() on output or use with
  138. * function chaining. (See User Guide for details.)
  139. * @return the requested Normalizer2, if successful
  140. * @stable ICU 49
  141. */
  142. U_CAPI const UNormalizer2 * U_EXPORT2
  143. unorm2_getNFDInstance(UErrorCode *pErrorCode);
  144. /**
  145. * Returns a UNormalizer2 instance for Unicode NFKC normalization.
  146. * Same as unorm2_getInstance(NULL, "nfkc", UNORM2_COMPOSE, pErrorCode).
  147. * Returns an unmodifiable singleton instance. Do not delete it.
  148. * @param pErrorCode Standard ICU error code. Its input value must
  149. * pass the U_SUCCESS() test, or else the function returns
  150. * immediately. Check for U_FAILURE() on output or use with
  151. * function chaining. (See User Guide for details.)
  152. * @return the requested Normalizer2, if successful
  153. * @stable ICU 49
  154. */
  155. U_CAPI const UNormalizer2 * U_EXPORT2
  156. unorm2_getNFKCInstance(UErrorCode *pErrorCode);
  157. /**
  158. * Returns a UNormalizer2 instance for Unicode NFKD normalization.
  159. * Same as unorm2_getInstance(NULL, "nfkc", UNORM2_DECOMPOSE, pErrorCode).
  160. * Returns an unmodifiable singleton instance. Do not delete it.
  161. * @param pErrorCode Standard ICU error code. Its input value must
  162. * pass the U_SUCCESS() test, or else the function returns
  163. * immediately. Check for U_FAILURE() on output or use with
  164. * function chaining. (See User Guide for details.)
  165. * @return the requested Normalizer2, if successful
  166. * @stable ICU 49
  167. */
  168. U_CAPI const UNormalizer2 * U_EXPORT2
  169. unorm2_getNFKDInstance(UErrorCode *pErrorCode);
  170. /**
  171. * Returns a UNormalizer2 instance for Unicode NFKC_Casefold normalization.
  172. * Same as unorm2_getInstance(NULL, "nfkc_cf", UNORM2_COMPOSE, pErrorCode).
  173. * Returns an unmodifiable singleton instance. Do not delete it.
  174. * @param pErrorCode 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 the requested Normalizer2, if successful
  179. * @stable ICU 49
  180. */
  181. U_CAPI const UNormalizer2 * U_EXPORT2
  182. unorm2_getNFKCCasefoldInstance(UErrorCode *pErrorCode);
  183. /**
  184. * Returns a UNormalizer2 instance which uses the specified data file
  185. * (packageName/name similar to ucnv_openPackage() and ures_open()/ResourceBundle)
  186. * and which composes or decomposes text according to the specified mode.
  187. * Returns an unmodifiable singleton instance. Do not delete it.
  188. *
  189. * Use packageName=NULL for data files that are part of ICU's own data.
  190. * Use name="nfc" and UNORM2_COMPOSE/UNORM2_DECOMPOSE for Unicode standard NFC/NFD.
  191. * Use name="nfkc" and UNORM2_COMPOSE/UNORM2_DECOMPOSE for Unicode standard NFKC/NFKD.
  192. * Use name="nfkc_cf" and UNORM2_COMPOSE for Unicode standard NFKC_CF=NFKC_Casefold.
  193. *
  194. * @param packageName NULL for ICU built-in data, otherwise application data package name
  195. * @param name "nfc" or "nfkc" or "nfkc_cf" or name of custom data file
  196. * @param mode normalization mode (compose or decompose etc.)
  197. * @param pErrorCode Standard ICU error code. Its input value must
  198. * pass the U_SUCCESS() test, or else the function returns
  199. * immediately. Check for U_FAILURE() on output or use with
  200. * function chaining. (See User Guide for details.)
  201. * @return the requested UNormalizer2, if successful
  202. * @stable ICU 4.4
  203. */
  204. U_CAPI const UNormalizer2 * U_EXPORT2
  205. unorm2_getInstance(const char *packageName,
  206. const char *name,
  207. UNormalization2Mode mode,
  208. UErrorCode *pErrorCode);
  209. /**
  210. * Constructs a filtered normalizer wrapping any UNormalizer2 instance
  211. * and a filter set.
  212. * Both are aliased and must not be modified or deleted while this object
  213. * is used.
  214. * The filter set should be frozen; otherwise the performance will suffer greatly.
  215. * @param norm2 wrapped UNormalizer2 instance
  216. * @param filterSet USet which determines the characters to be normalized
  217. * @param pErrorCode Standard ICU error code. Its input value must
  218. * pass the U_SUCCESS() test, or else the function returns
  219. * immediately. Check for U_FAILURE() on output or use with
  220. * function chaining. (See User Guide for details.)
  221. * @return the requested UNormalizer2, if successful
  222. * @stable ICU 4.4
  223. */
  224. U_CAPI UNormalizer2 * U_EXPORT2
  225. unorm2_openFiltered(const UNormalizer2 *norm2, const USet *filterSet, UErrorCode *pErrorCode);
  226. /**
  227. * Closes a UNormalizer2 instance from unorm2_openFiltered().
  228. * Do not close instances from unorm2_getInstance()!
  229. * @param norm2 UNormalizer2 instance to be closed
  230. * @stable ICU 4.4
  231. */
  232. U_CAPI void U_EXPORT2
  233. unorm2_close(UNormalizer2 *norm2);
  234. #if U_SHOW_CPLUSPLUS_API
  235. U_NAMESPACE_BEGIN
  236. /**
  237. * \class LocalUNormalizer2Pointer
  238. * "Smart pointer" class, closes a UNormalizer2 via unorm2_close().
  239. * For most methods see the LocalPointerBase base class.
  240. *
  241. * @see LocalPointerBase
  242. * @see LocalPointer
  243. * @stable ICU 4.4
  244. */
  245. U_DEFINE_LOCAL_OPEN_POINTER(LocalUNormalizer2Pointer, UNormalizer2, unorm2_close);
  246. U_NAMESPACE_END
  247. #endif
  248. /**
  249. * Writes the normalized form of the source string to the destination string
  250. * (replacing its contents) and returns the length of the destination string.
  251. * The source and destination strings must be different buffers.
  252. * @param norm2 UNormalizer2 instance
  253. * @param src source string
  254. * @param length length of the source string, or -1 if NUL-terminated
  255. * @param dest destination string; its contents is replaced with normalized src
  256. * @param capacity number of UChars that can be written to dest
  257. * @param pErrorCode Standard ICU error code. Its input value must
  258. * pass the U_SUCCESS() test, or else the function returns
  259. * immediately. Check for U_FAILURE() on output or use with
  260. * function chaining. (See User Guide for details.)
  261. * @return dest
  262. * @stable ICU 4.4
  263. */
  264. U_CAPI int32_t U_EXPORT2
  265. unorm2_normalize(const UNormalizer2 *norm2,
  266. const UChar *src, int32_t length,
  267. UChar *dest, int32_t capacity,
  268. UErrorCode *pErrorCode);
  269. /**
  270. * Appends the normalized form of the second string to the first string
  271. * (merging them at the boundary) and returns the length of the first string.
  272. * The result is normalized if the first string was normalized.
  273. * The first and second strings must be different buffers.
  274. * @param norm2 UNormalizer2 instance
  275. * @param first string, should be normalized
  276. * @param firstLength length of the first string, or -1 if NUL-terminated
  277. * @param firstCapacity number of UChars that can be written to first
  278. * @param second string, will be normalized
  279. * @param secondLength length of the source string, or -1 if NUL-terminated
  280. * @param pErrorCode Standard ICU error code. Its input value must
  281. * pass the U_SUCCESS() test, or else the function returns
  282. * immediately. Check for U_FAILURE() on output or use with
  283. * function chaining. (See User Guide for details.)
  284. * @return first
  285. * @stable ICU 4.4
  286. */
  287. U_CAPI int32_t U_EXPORT2
  288. unorm2_normalizeSecondAndAppend(const UNormalizer2 *norm2,
  289. UChar *first, int32_t firstLength, int32_t firstCapacity,
  290. const UChar *second, int32_t secondLength,
  291. UErrorCode *pErrorCode);
  292. /**
  293. * Appends the second string to the first string
  294. * (merging them at the boundary) and returns the length of the first string.
  295. * The result is normalized if both the strings were normalized.
  296. * The first and second strings must be different buffers.
  297. * @param norm2 UNormalizer2 instance
  298. * @param first string, should be normalized
  299. * @param firstLength length of the first string, or -1 if NUL-terminated
  300. * @param firstCapacity number of UChars that can be written to first
  301. * @param second string, should be normalized
  302. * @param secondLength length of the source string, or -1 if NUL-terminated
  303. * @param pErrorCode Standard ICU error code. Its input value must
  304. * pass the U_SUCCESS() test, or else the function returns
  305. * immediately. Check for U_FAILURE() on output or use with
  306. * function chaining. (See User Guide for details.)
  307. * @return first
  308. * @stable ICU 4.4
  309. */
  310. U_CAPI int32_t U_EXPORT2
  311. unorm2_append(const UNormalizer2 *norm2,
  312. UChar *first, int32_t firstLength, int32_t firstCapacity,
  313. const UChar *second, int32_t secondLength,
  314. UErrorCode *pErrorCode);
  315. /**
  316. * Gets the decomposition mapping of c.
  317. * Roughly equivalent to normalizing the String form of c
  318. * on a UNORM2_DECOMPOSE UNormalizer2 instance, but much faster, and except that this function
  319. * returns a negative value and does not write a string
  320. * if c does not have a decomposition mapping in this instance's data.
  321. * This function is independent of the mode of the UNormalizer2.
  322. * @param norm2 UNormalizer2 instance
  323. * @param c code point
  324. * @param decomposition String buffer which will be set to c's
  325. * decomposition mapping, if there is one.
  326. * @param capacity number of UChars that can be written to decomposition
  327. * @param pErrorCode Standard ICU error code. Its input value must
  328. * pass the U_SUCCESS() test, or else the function returns
  329. * immediately. Check for U_FAILURE() on output or use with
  330. * function chaining. (See User Guide for details.)
  331. * @return the non-negative length of c's decomposition, if there is one; otherwise a negative value
  332. * @stable ICU 4.6
  333. */
  334. U_CAPI int32_t U_EXPORT2
  335. unorm2_getDecomposition(const UNormalizer2 *norm2,
  336. UChar32 c, UChar *decomposition, int32_t capacity,
  337. UErrorCode *pErrorCode);
  338. /**
  339. * Gets the raw decomposition mapping of c.
  340. *
  341. * This is similar to the unorm2_getDecomposition() function but returns the
  342. * raw decomposition mapping as specified in UnicodeData.txt or
  343. * (for custom data) in the mapping files processed by the gennorm2 tool.
  344. * By contrast, unorm2_getDecomposition() returns the processed,
  345. * recursively-decomposed version of this mapping.
  346. *
  347. * When used on a standard NFKC Normalizer2 instance,
  348. * unorm2_getRawDecomposition() returns the Unicode Decomposition_Mapping (dm) property.
  349. *
  350. * When used on a standard NFC Normalizer2 instance,
  351. * it returns the Decomposition_Mapping only if the Decomposition_Type (dt) is Canonical (Can);
  352. * in this case, the result contains either one or two code points (=1..4 UChars).
  353. *
  354. * This function is independent of the mode of the UNormalizer2.
  355. * @param norm2 UNormalizer2 instance
  356. * @param c code point
  357. * @param decomposition String buffer which will be set to c's
  358. * raw decomposition mapping, if there is one.
  359. * @param capacity number of UChars that can be written to decomposition
  360. * @param pErrorCode Standard ICU error code. Its input value must
  361. * pass the U_SUCCESS() test, or else the function returns
  362. * immediately. Check for U_FAILURE() on output or use with
  363. * function chaining. (See User Guide for details.)
  364. * @return the non-negative length of c's raw decomposition, if there is one; otherwise a negative value
  365. * @stable ICU 49
  366. */
  367. U_CAPI int32_t U_EXPORT2
  368. unorm2_getRawDecomposition(const UNormalizer2 *norm2,
  369. UChar32 c, UChar *decomposition, int32_t capacity,
  370. UErrorCode *pErrorCode);
  371. /**
  372. * Performs pairwise composition of a & b and returns the composite if there is one.
  373. *
  374. * Returns a composite code point c only if c has a two-way mapping to a+b.
  375. * In standard Unicode normalization, this means that
  376. * c has a canonical decomposition to a+b
  377. * and c does not have the Full_Composition_Exclusion property.
  378. *
  379. * This function is independent of the mode of the UNormalizer2.
  380. * @param norm2 UNormalizer2 instance
  381. * @param a A (normalization starter) code point.
  382. * @param b Another code point.
  383. * @return The non-negative composite code point if there is one; otherwise a negative value.
  384. * @stable ICU 49
  385. */
  386. U_CAPI UChar32 U_EXPORT2
  387. unorm2_composePair(const UNormalizer2 *norm2, UChar32 a, UChar32 b);
  388. /**
  389. * Gets the combining class of c.
  390. * The default implementation returns 0
  391. * but all standard implementations return the Unicode Canonical_Combining_Class value.
  392. * @param norm2 UNormalizer2 instance
  393. * @param c code point
  394. * @return c's combining class
  395. * @stable ICU 49
  396. */
  397. U_CAPI uint8_t U_EXPORT2
  398. unorm2_getCombiningClass(const UNormalizer2 *norm2, UChar32 c);
  399. /**
  400. * Tests if the string is normalized.
  401. * Internally, in cases where the quickCheck() method would return "maybe"
  402. * (which is only possible for the two COMPOSE modes) this method
  403. * resolves to "yes" or "no" to provide a definitive result,
  404. * at the cost of doing more work in those cases.
  405. * @param norm2 UNormalizer2 instance
  406. * @param s input string
  407. * @param length length of the string, or -1 if NUL-terminated
  408. * @param pErrorCode Standard ICU error code. Its input value must
  409. * pass the U_SUCCESS() test, or else the function returns
  410. * immediately. Check for U_FAILURE() on output or use with
  411. * function chaining. (See User Guide for details.)
  412. * @return true if s is normalized
  413. * @stable ICU 4.4
  414. */
  415. U_CAPI UBool U_EXPORT2
  416. unorm2_isNormalized(const UNormalizer2 *norm2,
  417. const UChar *s, int32_t length,
  418. UErrorCode *pErrorCode);
  419. /**
  420. * Tests if the string is normalized.
  421. * For the two COMPOSE modes, the result could be "maybe" in cases that
  422. * would take a little more work to resolve definitively.
  423. * Use spanQuickCheckYes() and normalizeSecondAndAppend() for a faster
  424. * combination of quick check + normalization, to avoid
  425. * re-checking the "yes" prefix.
  426. * @param norm2 UNormalizer2 instance
  427. * @param s input string
  428. * @param length length of the string, or -1 if NUL-terminated
  429. * @param pErrorCode Standard ICU error code. Its input value must
  430. * pass the U_SUCCESS() test, or else the function returns
  431. * immediately. Check for U_FAILURE() on output or use with
  432. * function chaining. (See User Guide for details.)
  433. * @return UNormalizationCheckResult
  434. * @stable ICU 4.4
  435. */
  436. U_CAPI UNormalizationCheckResult U_EXPORT2
  437. unorm2_quickCheck(const UNormalizer2 *norm2,
  438. const UChar *s, int32_t length,
  439. UErrorCode *pErrorCode);
  440. /**
  441. * Returns the end of the normalized substring of the input string.
  442. * In other words, with <code>end=spanQuickCheckYes(s, ec);</code>
  443. * the substring <code>UnicodeString(s, 0, end)</code>
  444. * will pass the quick check with a "yes" result.
  445. *
  446. * The returned end index is usually one or more characters before the
  447. * "no" or "maybe" character: The end index is at a normalization boundary.
  448. * (See the class documentation for more about normalization boundaries.)
  449. *
  450. * When the goal is a normalized string and most input strings are expected
  451. * to be normalized already, then call this method,
  452. * and if it returns a prefix shorter than the input string,
  453. * copy that prefix and use normalizeSecondAndAppend() for the remainder.
  454. * @param norm2 UNormalizer2 instance
  455. * @param s input string
  456. * @param length length of the string, or -1 if NUL-terminated
  457. * @param pErrorCode Standard ICU error code. Its input value must
  458. * pass the U_SUCCESS() test, or else the function returns
  459. * immediately. Check for U_FAILURE() on output or use with
  460. * function chaining. (See User Guide for details.)
  461. * @return "yes" span end index
  462. * @stable ICU 4.4
  463. */
  464. U_CAPI int32_t U_EXPORT2
  465. unorm2_spanQuickCheckYes(const UNormalizer2 *norm2,
  466. const UChar *s, int32_t length,
  467. UErrorCode *pErrorCode);
  468. /**
  469. * Tests if the character always has a normalization boundary before it,
  470. * regardless of context.
  471. * For details see the Normalizer2 base class documentation.
  472. * @param norm2 UNormalizer2 instance
  473. * @param c character to test
  474. * @return true if c has a normalization boundary before it
  475. * @stable ICU 4.4
  476. */
  477. U_CAPI UBool U_EXPORT2
  478. unorm2_hasBoundaryBefore(const UNormalizer2 *norm2, UChar32 c);
  479. /**
  480. * Tests if the character always has a normalization boundary after it,
  481. * regardless of context.
  482. * For details see the Normalizer2 base class documentation.
  483. * @param norm2 UNormalizer2 instance
  484. * @param c character to test
  485. * @return true if c has a normalization boundary after it
  486. * @stable ICU 4.4
  487. */
  488. U_CAPI UBool U_EXPORT2
  489. unorm2_hasBoundaryAfter(const UNormalizer2 *norm2, UChar32 c);
  490. /**
  491. * Tests if the character is normalization-inert.
  492. * For details see the Normalizer2 base class documentation.
  493. * @param norm2 UNormalizer2 instance
  494. * @param c character to test
  495. * @return true if c is normalization-inert
  496. * @stable ICU 4.4
  497. */
  498. U_CAPI UBool U_EXPORT2
  499. unorm2_isInert(const UNormalizer2 *norm2, UChar32 c);
  500. /**
  501. * Compares two strings for canonical equivalence.
  502. * Further options include case-insensitive comparison and
  503. * code point order (as opposed to code unit order).
  504. *
  505. * Canonical equivalence between two strings is defined as their normalized
  506. * forms (NFD or NFC) being identical.
  507. * This function compares strings incrementally instead of normalizing
  508. * (and optionally case-folding) both strings entirely,
  509. * improving performance significantly.
  510. *
  511. * Bulk normalization is only necessary if the strings do not fulfill the FCD
  512. * conditions. Only in this case, and only if the strings are relatively long,
  513. * is memory allocated temporarily.
  514. * For FCD strings and short non-FCD strings there is no memory allocation.
  515. *
  516. * Semantically, this is equivalent to
  517. * strcmp[CodePointOrder](NFD(foldCase(NFD(s1))), NFD(foldCase(NFD(s2))))
  518. * where code point order and foldCase are all optional.
  519. *
  520. * UAX 21 2.5 Caseless Matching specifies that for a canonical caseless match
  521. * the case folding must be performed first, then the normalization.
  522. *
  523. * @param s1 First source string.
  524. * @param length1 Length of first source string, or -1 if NUL-terminated.
  525. *
  526. * @param s2 Second source string.
  527. * @param length2 Length of second source string, or -1 if NUL-terminated.
  528. *
  529. * @param options A bit set of options:
  530. * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
  531. * Case-sensitive comparison in code unit order, and the input strings
  532. * are quick-checked for FCD.
  533. *
  534. * - UNORM_INPUT_IS_FCD
  535. * Set if the caller knows that both s1 and s2 fulfill the FCD conditions.
  536. * If not set, the function will quickCheck for FCD
  537. * and normalize if necessary.
  538. *
  539. * - U_COMPARE_CODE_POINT_ORDER
  540. * Set to choose code point order instead of code unit order
  541. * (see u_strCompare for details).
  542. *
  543. * - U_COMPARE_IGNORE_CASE
  544. * Set to compare strings case-insensitively using case folding,
  545. * instead of case-sensitively.
  546. * If set, then the following case folding options are used.
  547. *
  548. * - Options as used with case-insensitive comparisons, currently:
  549. *
  550. * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
  551. * (see u_strCaseCompare for details)
  552. *
  553. * - regular normalization options shifted left by UNORM_COMPARE_NORM_OPTIONS_SHIFT
  554. *
  555. * @param pErrorCode ICU error code in/out parameter.
  556. * Must fulfill U_SUCCESS before the function call.
  557. * @return <0 or 0 or >0 as usual for string comparisons
  558. *
  559. * @see unorm_normalize
  560. * @see UNORM_FCD
  561. * @see u_strCompare
  562. * @see u_strCaseCompare
  563. *
  564. * @stable ICU 2.2
  565. */
  566. U_CAPI int32_t U_EXPORT2
  567. unorm_compare(const UChar *s1, int32_t length1,
  568. const UChar *s2, int32_t length2,
  569. uint32_t options,
  570. UErrorCode *pErrorCode);
  571. #endif /* !UCONFIG_NO_NORMALIZATION */
  572. #endif /* __UNORM2_H__ */