unorm2.h 26 KB

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