unorm2.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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 toNFKC_Casefold() normalization
  172. * which is equivalent to applying the NFKC_Casefold mappings and then NFC.
  173. * See https://www.unicode.org/reports/tr44/#NFKC_Casefold
  174. *
  175. * Same as unorm2_getInstance(NULL, "nfkc_cf", UNORM2_COMPOSE, pErrorCode).
  176. * Returns an unmodifiable singleton instance. Do not delete it.
  177. * @param pErrorCode Standard ICU error code. Its input value must
  178. * pass the U_SUCCESS() test, or else the function returns
  179. * immediately. Check for U_FAILURE() on output or use with
  180. * function chaining. (See User Guide for details.)
  181. * @return the requested Normalizer2, if successful
  182. * @stable ICU 49
  183. */
  184. U_CAPI const UNormalizer2 * U_EXPORT2
  185. unorm2_getNFKCCasefoldInstance(UErrorCode *pErrorCode);
  186. #ifndef U_HIDE_DRAFT_API
  187. /**
  188. * Returns a UNormalizer2 instance for a variant of Unicode toNFKC_Casefold() normalization
  189. * which is equivalent to applying the NFKC_Simple_Casefold mappings and then NFC.
  190. * See https://www.unicode.org/reports/tr44/#NFKC_Simple_Casefold
  191. *
  192. * Same as unorm2_getInstance(NULL, "nfkc_scf", UNORM2_COMPOSE, pErrorCode).
  193. * Returns an unmodifiable singleton instance. Do not delete it.
  194. * @param pErrorCode Standard ICU error code. Its input value must
  195. * pass the U_SUCCESS() test, or else the function returns
  196. * immediately. Check for U_FAILURE() on output or use with
  197. * function chaining. (See User Guide for details.)
  198. * @return the requested Normalizer2, if successful
  199. * @draft ICU 74
  200. */
  201. U_CAPI const UNormalizer2 * U_EXPORT2
  202. unorm2_getNFKCSimpleCasefoldInstance(UErrorCode *pErrorCode);
  203. #endif // U_HIDE_DRAFT_API
  204. /**
  205. * Returns a UNormalizer2 instance which uses the specified data file
  206. * (packageName/name similar to ucnv_openPackage() and ures_open()/ResourceBundle)
  207. * and which composes or decomposes text according to the specified mode.
  208. * Returns an unmodifiable singleton instance. Do not delete it.
  209. *
  210. * Use packageName=NULL for data files that are part of ICU's own data.
  211. * Use name="nfc" and UNORM2_COMPOSE/UNORM2_DECOMPOSE for Unicode standard NFC/NFD.
  212. * Use name="nfkc" and UNORM2_COMPOSE/UNORM2_DECOMPOSE for Unicode standard NFKC/NFKD.
  213. * Use name="nfkc_cf" and UNORM2_COMPOSE for Unicode standard NFKC_CF=NFKC_Casefold.
  214. *
  215. * @param packageName NULL for ICU built-in data, otherwise application data package name
  216. * @param name "nfc" or "nfkc" or "nfkc_cf" or "nfkc_scf" or name of custom data file
  217. * @param mode normalization mode (compose or decompose etc.)
  218. * @param pErrorCode Standard ICU error code. Its input value must
  219. * pass the U_SUCCESS() test, or else the function returns
  220. * immediately. Check for U_FAILURE() on output or use with
  221. * function chaining. (See User Guide for details.)
  222. * @return the requested UNormalizer2, if successful
  223. * @stable ICU 4.4
  224. */
  225. U_CAPI const UNormalizer2 * U_EXPORT2
  226. unorm2_getInstance(const char *packageName,
  227. const char *name,
  228. UNormalization2Mode mode,
  229. UErrorCode *pErrorCode);
  230. /**
  231. * Constructs a filtered normalizer wrapping any UNormalizer2 instance
  232. * and a filter set.
  233. * Both are aliased and must not be modified or deleted while this object
  234. * is used.
  235. * The filter set should be frozen; otherwise the performance will suffer greatly.
  236. * @param norm2 wrapped UNormalizer2 instance
  237. * @param filterSet USet which determines the characters to be normalized
  238. * @param pErrorCode Standard ICU error code. Its input value must
  239. * pass the U_SUCCESS() test, or else the function returns
  240. * immediately. Check for U_FAILURE() on output or use with
  241. * function chaining. (See User Guide for details.)
  242. * @return the requested UNormalizer2, if successful
  243. * @stable ICU 4.4
  244. */
  245. U_CAPI UNormalizer2 * U_EXPORT2
  246. unorm2_openFiltered(const UNormalizer2 *norm2, const USet *filterSet, UErrorCode *pErrorCode);
  247. /**
  248. * Closes a UNormalizer2 instance from unorm2_openFiltered().
  249. * Do not close instances from unorm2_getInstance()!
  250. * @param norm2 UNormalizer2 instance to be closed
  251. * @stable ICU 4.4
  252. */
  253. U_CAPI void U_EXPORT2
  254. unorm2_close(UNormalizer2 *norm2);
  255. #if U_SHOW_CPLUSPLUS_API
  256. U_NAMESPACE_BEGIN
  257. /**
  258. * \class LocalUNormalizer2Pointer
  259. * "Smart pointer" class, closes a UNormalizer2 via unorm2_close().
  260. * For most methods see the LocalPointerBase base class.
  261. *
  262. * @see LocalPointerBase
  263. * @see LocalPointer
  264. * @stable ICU 4.4
  265. */
  266. U_DEFINE_LOCAL_OPEN_POINTER(LocalUNormalizer2Pointer, UNormalizer2, unorm2_close);
  267. U_NAMESPACE_END
  268. #endif
  269. /**
  270. * Writes the normalized form of the source string to the destination string
  271. * (replacing its contents) and returns the length of the destination string.
  272. * The source and destination strings must be different buffers.
  273. * @param norm2 UNormalizer2 instance
  274. * @param src source string
  275. * @param length length of the source string, or -1 if NUL-terminated
  276. * @param dest destination string; its contents is replaced with normalized src
  277. * @param capacity number of UChars that can be written to dest
  278. * @param pErrorCode Standard ICU error code. Its input value must
  279. * pass the U_SUCCESS() test, or else the function returns
  280. * immediately. Check for U_FAILURE() on output or use with
  281. * function chaining. (See User Guide for details.)
  282. * @return dest
  283. * @stable ICU 4.4
  284. */
  285. U_CAPI int32_t U_EXPORT2
  286. unorm2_normalize(const UNormalizer2 *norm2,
  287. const UChar *src, int32_t length,
  288. UChar *dest, int32_t capacity,
  289. UErrorCode *pErrorCode);
  290. /**
  291. * Appends the normalized form of the second string to the first string
  292. * (merging them at the boundary) and returns the length of the first string.
  293. * The result is normalized if the first string was normalized.
  294. * The first and second strings must be different buffers.
  295. * @param norm2 UNormalizer2 instance
  296. * @param first string, should be normalized
  297. * @param firstLength length of the first string, or -1 if NUL-terminated
  298. * @param firstCapacity number of UChars that can be written to first
  299. * @param second string, will be normalized
  300. * @param secondLength length of the source string, or -1 if NUL-terminated
  301. * @param pErrorCode Standard ICU error code. Its input value must
  302. * pass the U_SUCCESS() test, or else the function returns
  303. * immediately. Check for U_FAILURE() on output or use with
  304. * function chaining. (See User Guide for details.)
  305. * @return first
  306. * @stable ICU 4.4
  307. */
  308. U_CAPI int32_t U_EXPORT2
  309. unorm2_normalizeSecondAndAppend(const UNormalizer2 *norm2,
  310. UChar *first, int32_t firstLength, int32_t firstCapacity,
  311. const UChar *second, int32_t secondLength,
  312. UErrorCode *pErrorCode);
  313. /**
  314. * Appends the second string to the first string
  315. * (merging them at the boundary) and returns the length of the first string.
  316. * The result is normalized if both the strings were normalized.
  317. * The first and second strings must be different buffers.
  318. * @param norm2 UNormalizer2 instance
  319. * @param first string, should be normalized
  320. * @param firstLength length of the first string, or -1 if NUL-terminated
  321. * @param firstCapacity number of UChars that can be written to first
  322. * @param second string, should be normalized
  323. * @param secondLength length of the source string, or -1 if NUL-terminated
  324. * @param pErrorCode Standard ICU error code. Its input value must
  325. * pass the U_SUCCESS() test, or else the function returns
  326. * immediately. Check for U_FAILURE() on output or use with
  327. * function chaining. (See User Guide for details.)
  328. * @return first
  329. * @stable ICU 4.4
  330. */
  331. U_CAPI int32_t U_EXPORT2
  332. unorm2_append(const UNormalizer2 *norm2,
  333. UChar *first, int32_t firstLength, int32_t firstCapacity,
  334. const UChar *second, int32_t secondLength,
  335. UErrorCode *pErrorCode);
  336. /**
  337. * Gets the decomposition mapping of c.
  338. * Roughly equivalent to normalizing the String form of c
  339. * on a UNORM2_DECOMPOSE UNormalizer2 instance, but much faster, and except that this function
  340. * returns a negative value and does not write a string
  341. * if c does not have a decomposition mapping in this instance's data.
  342. * This function is independent of the mode of the UNormalizer2.
  343. * @param norm2 UNormalizer2 instance
  344. * @param c code point
  345. * @param decomposition String buffer which will be set to c's
  346. * decomposition mapping, if there is one.
  347. * @param capacity number of UChars that can be written to decomposition
  348. * @param pErrorCode Standard ICU error code. Its input value must
  349. * pass the U_SUCCESS() test, or else the function returns
  350. * immediately. Check for U_FAILURE() on output or use with
  351. * function chaining. (See User Guide for details.)
  352. * @return the non-negative length of c's decomposition, if there is one; otherwise a negative value
  353. * @stable ICU 4.6
  354. */
  355. U_CAPI int32_t U_EXPORT2
  356. unorm2_getDecomposition(const UNormalizer2 *norm2,
  357. UChar32 c, UChar *decomposition, int32_t capacity,
  358. UErrorCode *pErrorCode);
  359. /**
  360. * Gets the raw decomposition mapping of c.
  361. *
  362. * This is similar to the unorm2_getDecomposition() function but returns the
  363. * raw decomposition mapping as specified in UnicodeData.txt or
  364. * (for custom data) in the mapping files processed by the gennorm2 tool.
  365. * By contrast, unorm2_getDecomposition() returns the processed,
  366. * recursively-decomposed version of this mapping.
  367. *
  368. * When used on a standard NFKC Normalizer2 instance,
  369. * unorm2_getRawDecomposition() returns the Unicode Decomposition_Mapping (dm) property.
  370. *
  371. * When used on a standard NFC Normalizer2 instance,
  372. * it returns the Decomposition_Mapping only if the Decomposition_Type (dt) is Canonical (Can);
  373. * in this case, the result contains either one or two code points (=1..4 UChars).
  374. *
  375. * This function is independent of the mode of the UNormalizer2.
  376. * @param norm2 UNormalizer2 instance
  377. * @param c code point
  378. * @param decomposition String buffer which will be set to c's
  379. * raw decomposition mapping, if there is one.
  380. * @param capacity number of UChars that can be written to decomposition
  381. * @param pErrorCode Standard ICU error code. Its input value must
  382. * pass the U_SUCCESS() test, or else the function returns
  383. * immediately. Check for U_FAILURE() on output or use with
  384. * function chaining. (See User Guide for details.)
  385. * @return the non-negative length of c's raw decomposition, if there is one; otherwise a negative value
  386. * @stable ICU 49
  387. */
  388. U_CAPI int32_t U_EXPORT2
  389. unorm2_getRawDecomposition(const UNormalizer2 *norm2,
  390. UChar32 c, UChar *decomposition, int32_t capacity,
  391. UErrorCode *pErrorCode);
  392. /**
  393. * Performs pairwise composition of a & b and returns the composite if there is one.
  394. *
  395. * Returns a composite code point c only if c has a two-way mapping to a+b.
  396. * In standard Unicode normalization, this means that
  397. * c has a canonical decomposition to a+b
  398. * and c does not have the Full_Composition_Exclusion property.
  399. *
  400. * This function is independent of the mode of the UNormalizer2.
  401. * @param norm2 UNormalizer2 instance
  402. * @param a A (normalization starter) code point.
  403. * @param b Another code point.
  404. * @return The non-negative composite code point if there is one; otherwise a negative value.
  405. * @stable ICU 49
  406. */
  407. U_CAPI UChar32 U_EXPORT2
  408. unorm2_composePair(const UNormalizer2 *norm2, UChar32 a, UChar32 b);
  409. /**
  410. * Gets the combining class of c.
  411. * The default implementation returns 0
  412. * but all standard implementations return the Unicode Canonical_Combining_Class value.
  413. * @param norm2 UNormalizer2 instance
  414. * @param c code point
  415. * @return c's combining class
  416. * @stable ICU 49
  417. */
  418. U_CAPI uint8_t U_EXPORT2
  419. unorm2_getCombiningClass(const UNormalizer2 *norm2, UChar32 c);
  420. /**
  421. * Tests if the string is normalized.
  422. * Internally, in cases where the quickCheck() method would return "maybe"
  423. * (which is only possible for the two COMPOSE modes) this method
  424. * resolves to "yes" or "no" to provide a definitive result,
  425. * at the cost of doing more work in those cases.
  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 true if s is normalized
  434. * @stable ICU 4.4
  435. */
  436. U_CAPI UBool U_EXPORT2
  437. unorm2_isNormalized(const UNormalizer2 *norm2,
  438. const UChar *s, int32_t length,
  439. UErrorCode *pErrorCode);
  440. /**
  441. * Tests if the string is normalized.
  442. * For the two COMPOSE modes, the result could be "maybe" in cases that
  443. * would take a little more work to resolve definitively.
  444. * Use spanQuickCheckYes() and normalizeSecondAndAppend() for a faster
  445. * combination of quick check + normalization, to avoid
  446. * re-checking the "yes" prefix.
  447. * @param norm2 UNormalizer2 instance
  448. * @param s input string
  449. * @param length length of the string, or -1 if NUL-terminated
  450. * @param pErrorCode Standard ICU error code. Its input value must
  451. * pass the U_SUCCESS() test, or else the function returns
  452. * immediately. Check for U_FAILURE() on output or use with
  453. * function chaining. (See User Guide for details.)
  454. * @return UNormalizationCheckResult
  455. * @stable ICU 4.4
  456. */
  457. U_CAPI UNormalizationCheckResult U_EXPORT2
  458. unorm2_quickCheck(const UNormalizer2 *norm2,
  459. const UChar *s, int32_t length,
  460. UErrorCode *pErrorCode);
  461. /**
  462. * Returns the end of the normalized substring of the input string.
  463. * In other words, with <code>end=spanQuickCheckYes(s, ec);</code>
  464. * the substring <code>UnicodeString(s, 0, end)</code>
  465. * will pass the quick check with a "yes" result.
  466. *
  467. * The returned end index is usually one or more characters before the
  468. * "no" or "maybe" character: The end index is at a normalization boundary.
  469. * (See the class documentation for more about normalization boundaries.)
  470. *
  471. * When the goal is a normalized string and most input strings are expected
  472. * to be normalized already, then call this method,
  473. * and if it returns a prefix shorter than the input string,
  474. * copy that prefix and use normalizeSecondAndAppend() for the remainder.
  475. * @param norm2 UNormalizer2 instance
  476. * @param s input string
  477. * @param length length of the string, or -1 if NUL-terminated
  478. * @param pErrorCode Standard ICU error code. Its input value must
  479. * pass the U_SUCCESS() test, or else the function returns
  480. * immediately. Check for U_FAILURE() on output or use with
  481. * function chaining. (See User Guide for details.)
  482. * @return "yes" span end index
  483. * @stable ICU 4.4
  484. */
  485. U_CAPI int32_t U_EXPORT2
  486. unorm2_spanQuickCheckYes(const UNormalizer2 *norm2,
  487. const UChar *s, int32_t length,
  488. UErrorCode *pErrorCode);
  489. /**
  490. * Tests if the character always has a normalization boundary before it,
  491. * regardless of context.
  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 has a normalization boundary before it
  496. * @stable ICU 4.4
  497. */
  498. U_CAPI UBool U_EXPORT2
  499. unorm2_hasBoundaryBefore(const UNormalizer2 *norm2, UChar32 c);
  500. /**
  501. * Tests if the character always has a normalization boundary after it,
  502. * regardless of context.
  503. * For details see the Normalizer2 base class documentation.
  504. * @param norm2 UNormalizer2 instance
  505. * @param c character to test
  506. * @return true if c has a normalization boundary after it
  507. * @stable ICU 4.4
  508. */
  509. U_CAPI UBool U_EXPORT2
  510. unorm2_hasBoundaryAfter(const UNormalizer2 *norm2, UChar32 c);
  511. /**
  512. * Tests if the character is normalization-inert.
  513. * For details see the Normalizer2 base class documentation.
  514. * @param norm2 UNormalizer2 instance
  515. * @param c character to test
  516. * @return true if c is normalization-inert
  517. * @stable ICU 4.4
  518. */
  519. U_CAPI UBool U_EXPORT2
  520. unorm2_isInert(const UNormalizer2 *norm2, UChar32 c);
  521. /**
  522. * Compares two strings for canonical equivalence.
  523. * Further options include case-insensitive comparison and
  524. * code point order (as opposed to code unit order).
  525. *
  526. * Canonical equivalence between two strings is defined as their normalized
  527. * forms (NFD or NFC) being identical.
  528. * This function compares strings incrementally instead of normalizing
  529. * (and optionally case-folding) both strings entirely,
  530. * improving performance significantly.
  531. *
  532. * Bulk normalization is only necessary if the strings do not fulfill the FCD
  533. * conditions. Only in this case, and only if the strings are relatively long,
  534. * is memory allocated temporarily.
  535. * For FCD strings and short non-FCD strings there is no memory allocation.
  536. *
  537. * Semantically, this is equivalent to
  538. * strcmp[CodePointOrder](NFD(foldCase(NFD(s1))), NFD(foldCase(NFD(s2))))
  539. * where code point order and foldCase are all optional.
  540. *
  541. * UAX 21 2.5 Caseless Matching specifies that for a canonical caseless match
  542. * the case folding must be performed first, then the normalization.
  543. *
  544. * @param s1 First source string.
  545. * @param length1 Length of first source string, or -1 if NUL-terminated.
  546. *
  547. * @param s2 Second source string.
  548. * @param length2 Length of second source string, or -1 if NUL-terminated.
  549. *
  550. * @param options A bit set of options:
  551. * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
  552. * Case-sensitive comparison in code unit order, and the input strings
  553. * are quick-checked for FCD.
  554. *
  555. * - UNORM_INPUT_IS_FCD
  556. * Set if the caller knows that both s1 and s2 fulfill the FCD conditions.
  557. * If not set, the function will quickCheck for FCD
  558. * and normalize if necessary.
  559. *
  560. * - U_COMPARE_CODE_POINT_ORDER
  561. * Set to choose code point order instead of code unit order
  562. * (see u_strCompare for details).
  563. *
  564. * - U_COMPARE_IGNORE_CASE
  565. * Set to compare strings case-insensitively using case folding,
  566. * instead of case-sensitively.
  567. * If set, then the following case folding options are used.
  568. *
  569. * - Options as used with case-insensitive comparisons, currently:
  570. *
  571. * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
  572. * (see u_strCaseCompare for details)
  573. *
  574. * - regular normalization options shifted left by UNORM_COMPARE_NORM_OPTIONS_SHIFT
  575. *
  576. * @param pErrorCode ICU error code in/out parameter.
  577. * Must fulfill U_SUCCESS before the function call.
  578. * @return <0 or 0 or >0 as usual for string comparisons
  579. *
  580. * @see unorm_normalize
  581. * @see UNORM_FCD
  582. * @see u_strCompare
  583. * @see u_strCaseCompare
  584. *
  585. * @stable ICU 2.2
  586. */
  587. U_CAPI int32_t U_EXPORT2
  588. unorm_compare(const UChar *s1, int32_t length1,
  589. const UChar *s2, int32_t length2,
  590. uint32_t options,
  591. UErrorCode *pErrorCode);
  592. #endif /* !UCONFIG_NO_NORMALIZATION */
  593. #endif /* __UNORM2_H__ */