unorm2.h 25 KB

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