ucol.h 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. *******************************************************************************
  5. * Copyright (c) 1996-2015, International Business Machines Corporation and others.
  6. * All Rights Reserved.
  7. *******************************************************************************
  8. */
  9. #ifndef UCOL_H
  10. #define UCOL_H
  11. #include "unicode/utypes.h"
  12. #if !UCONFIG_NO_COLLATION
  13. #include "unicode/unorm.h"
  14. #include "unicode/parseerr.h"
  15. #include "unicode/uloc.h"
  16. #include "unicode/uset.h"
  17. #include "unicode/uscript.h"
  18. #if U_SHOW_CPLUSPLUS_API
  19. #include "unicode/localpointer.h"
  20. #endif // U_SHOW_CPLUSPLUS_API
  21. /**
  22. * \file
  23. * \brief C API: Collator
  24. *
  25. * <h2> Collator C API </h2>
  26. *
  27. * The C API for Collator performs locale-sensitive
  28. * string comparison. You use this service to build
  29. * searching and sorting routines for natural language text.
  30. * <p>
  31. * For more information about the collation service see
  32. * <a href="https://unicode-org.github.io/icu/userguide/collation">the User Guide</a>.
  33. * <p>
  34. * Collation service provides correct sorting orders for most locales supported in ICU.
  35. * If specific data for a locale is not available, the orders eventually falls back
  36. * to the <a href="http://www.unicode.org/reports/tr35/tr35-collation.html#Root_Collation">CLDR root sort order</a>.
  37. * <p>
  38. * Sort ordering may be customized by providing your own set of rules. For more on
  39. * this subject see the <a href="https://unicode-org.github.io/icu/userguide/collation/customization">
  40. * Collation Customization</a> section of the User Guide.
  41. * <p>
  42. * @see UCollationResult
  43. * @see UNormalizationMode
  44. * @see UCollationStrength
  45. * @see UCollationElements
  46. */
  47. /** A collator.
  48. * For usage in C programs.
  49. */
  50. struct UCollator;
  51. /** structure representing a collator object instance
  52. * @stable ICU 2.0
  53. */
  54. typedef struct UCollator UCollator;
  55. /**
  56. * UCOL_LESS is returned if source string is compared to be less than target
  57. * string in the ucol_strcoll() method.
  58. * UCOL_EQUAL is returned if source string is compared to be equal to target
  59. * string in the ucol_strcoll() method.
  60. * UCOL_GREATER is returned if source string is compared to be greater than
  61. * target string in the ucol_strcoll() method.
  62. * @see ucol_strcoll()
  63. * <p>
  64. * Possible values for a comparison result
  65. * @stable ICU 2.0
  66. */
  67. typedef enum {
  68. /** string a == string b */
  69. UCOL_EQUAL = 0,
  70. /** string a > string b */
  71. UCOL_GREATER = 1,
  72. /** string a < string b */
  73. UCOL_LESS = -1
  74. } UCollationResult ;
  75. /** Enum containing attribute values for controlling collation behavior.
  76. * Here are all the allowable values. Not every attribute can take every value. The only
  77. * universal value is UCOL_DEFAULT, which resets the attribute value to the predefined
  78. * value for that locale
  79. * @stable ICU 2.0
  80. */
  81. typedef enum {
  82. /** accepted by most attributes */
  83. UCOL_DEFAULT = -1,
  84. /** Primary collation strength */
  85. UCOL_PRIMARY = 0,
  86. /** Secondary collation strength */
  87. UCOL_SECONDARY = 1,
  88. /** Tertiary collation strength */
  89. UCOL_TERTIARY = 2,
  90. /** Default collation strength */
  91. UCOL_DEFAULT_STRENGTH = UCOL_TERTIARY,
  92. UCOL_CE_STRENGTH_LIMIT,
  93. /** Quaternary collation strength */
  94. UCOL_QUATERNARY=3,
  95. /** Identical collation strength */
  96. UCOL_IDENTICAL=15,
  97. UCOL_STRENGTH_LIMIT,
  98. /** Turn the feature off - works for UCOL_FRENCH_COLLATION,
  99. UCOL_CASE_LEVEL, UCOL_HIRAGANA_QUATERNARY_MODE
  100. & UCOL_DECOMPOSITION_MODE*/
  101. UCOL_OFF = 16,
  102. /** Turn the feature on - works for UCOL_FRENCH_COLLATION,
  103. UCOL_CASE_LEVEL, UCOL_HIRAGANA_QUATERNARY_MODE
  104. & UCOL_DECOMPOSITION_MODE*/
  105. UCOL_ON = 17,
  106. /** Valid for UCOL_ALTERNATE_HANDLING. Alternate handling will be shifted */
  107. UCOL_SHIFTED = 20,
  108. /** Valid for UCOL_ALTERNATE_HANDLING. Alternate handling will be non ignorable */
  109. UCOL_NON_IGNORABLE = 21,
  110. /** Valid for UCOL_CASE_FIRST -
  111. lower case sorts before upper case */
  112. UCOL_LOWER_FIRST = 24,
  113. /** upper case sorts before lower case */
  114. UCOL_UPPER_FIRST = 25,
  115. #ifndef U_HIDE_DEPRECATED_API
  116. /**
  117. * One more than the highest normal UColAttributeValue value.
  118. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  119. */
  120. UCOL_ATTRIBUTE_VALUE_COUNT
  121. #endif /* U_HIDE_DEPRECATED_API */
  122. } UColAttributeValue;
  123. /**
  124. * Enum containing the codes for reordering segments of the collation table that are not script
  125. * codes. These reordering codes are to be used in conjunction with the script codes.
  126. * @see ucol_getReorderCodes
  127. * @see ucol_setReorderCodes
  128. * @see ucol_getEquivalentReorderCodes
  129. * @see UScriptCode
  130. * @stable ICU 4.8
  131. */
  132. typedef enum {
  133. /**
  134. * A special reordering code that is used to specify the default
  135. * reordering codes for a locale.
  136. * @stable ICU 4.8
  137. */
  138. UCOL_REORDER_CODE_DEFAULT = -1,
  139. /**
  140. * A special reordering code that is used to specify no reordering codes.
  141. * @stable ICU 4.8
  142. */
  143. UCOL_REORDER_CODE_NONE = USCRIPT_UNKNOWN,
  144. /**
  145. * A special reordering code that is used to specify all other codes used for
  146. * reordering except for the codes lised as UColReorderCode values and those
  147. * listed explicitly in a reordering.
  148. * @stable ICU 4.8
  149. */
  150. UCOL_REORDER_CODE_OTHERS = USCRIPT_UNKNOWN,
  151. /**
  152. * Characters with the space property.
  153. * This is equivalent to the rule value "space".
  154. * @stable ICU 4.8
  155. */
  156. UCOL_REORDER_CODE_SPACE = 0x1000,
  157. /**
  158. * The first entry in the enumeration of reordering groups. This is intended for use in
  159. * range checking and enumeration of the reorder codes.
  160. * @stable ICU 4.8
  161. */
  162. UCOL_REORDER_CODE_FIRST = UCOL_REORDER_CODE_SPACE,
  163. /**
  164. * Characters with the punctuation property.
  165. * This is equivalent to the rule value "punct".
  166. * @stable ICU 4.8
  167. */
  168. UCOL_REORDER_CODE_PUNCTUATION = 0x1001,
  169. /**
  170. * Characters with the symbol property.
  171. * This is equivalent to the rule value "symbol".
  172. * @stable ICU 4.8
  173. */
  174. UCOL_REORDER_CODE_SYMBOL = 0x1002,
  175. /**
  176. * Characters with the currency property.
  177. * This is equivalent to the rule value "currency".
  178. * @stable ICU 4.8
  179. */
  180. UCOL_REORDER_CODE_CURRENCY = 0x1003,
  181. /**
  182. * Characters with the digit property.
  183. * This is equivalent to the rule value "digit".
  184. * @stable ICU 4.8
  185. */
  186. UCOL_REORDER_CODE_DIGIT = 0x1004,
  187. #ifndef U_HIDE_DEPRECATED_API
  188. /**
  189. * One more than the highest normal UColReorderCode value.
  190. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  191. */
  192. UCOL_REORDER_CODE_LIMIT = 0x1005
  193. #endif /* U_HIDE_DEPRECATED_API */
  194. } UColReorderCode;
  195. /**
  196. * Base letter represents a primary difference. Set comparison
  197. * level to UCOL_PRIMARY to ignore secondary and tertiary differences.
  198. * Use this to set the strength of a Collator object.
  199. * Example of primary difference, "abc" &lt; "abd"
  200. *
  201. * Diacritical differences on the same base letter represent a secondary
  202. * difference. Set comparison level to UCOL_SECONDARY to ignore tertiary
  203. * differences. Use this to set the strength of a Collator object.
  204. * Example of secondary difference, "&auml;" >> "a".
  205. *
  206. * Uppercase and lowercase versions of the same character represents a
  207. * tertiary difference. Set comparison level to UCOL_TERTIARY to include
  208. * all comparison differences. Use this to set the strength of a Collator
  209. * object.
  210. * Example of tertiary difference, "abc" &lt;&lt;&lt; "ABC".
  211. *
  212. * Two characters are considered "identical" when they have the same
  213. * unicode spellings. UCOL_IDENTICAL.
  214. * For example, "&auml;" == "&auml;".
  215. *
  216. * UCollationStrength is also used to determine the strength of sort keys
  217. * generated from UCollator objects
  218. * These values can be now found in the UColAttributeValue enum.
  219. * @stable ICU 2.0
  220. **/
  221. typedef UColAttributeValue UCollationStrength;
  222. /** Attributes that collation service understands. All the attributes can take UCOL_DEFAULT
  223. * value, as well as the values specific to each one.
  224. * @stable ICU 2.0
  225. */
  226. typedef enum {
  227. /** Attribute for direction of secondary weights - used in Canadian French.
  228. * Acceptable values are UCOL_ON, which results in secondary weights
  229. * being considered backwards and UCOL_OFF which treats secondary
  230. * weights in the order they appear.
  231. * @stable ICU 2.0
  232. */
  233. UCOL_FRENCH_COLLATION,
  234. /** Attribute for handling variable elements.
  235. * Acceptable values are UCOL_NON_IGNORABLE
  236. * which treats all the codepoints with non-ignorable
  237. * primary weights in the same way,
  238. * and UCOL_SHIFTED which causes codepoints with primary
  239. * weights that are equal or below the variable top value
  240. * to be ignored on primary level and moved to the quaternary
  241. * level. The default setting in a Collator object depends on the
  242. * locale data loaded from the resources. For most locales, the
  243. * default is UCOL_NON_IGNORABLE, but for others, such as "th",
  244. * the default could be UCOL_SHIFTED.
  245. * @stable ICU 2.0
  246. */
  247. UCOL_ALTERNATE_HANDLING,
  248. /** Controls the ordering of upper and lower case letters.
  249. * Acceptable values are UCOL_OFF, which orders
  250. * upper and lower case letters in accordance to their tertiary
  251. * weights, UCOL_UPPER_FIRST which forces upper case letters to
  252. * sort before lower case letters, and UCOL_LOWER_FIRST which does
  253. * the opposite. The default setting in a Collator object depends on the
  254. * locale data loaded from the resources. For most locales, the
  255. * default is UCOL_OFF, but for others, such as "da" or "mt",
  256. * the default could be UCOL_UPPER.
  257. * @stable ICU 2.0
  258. */
  259. UCOL_CASE_FIRST,
  260. /** Controls whether an extra case level (positioned before the third
  261. * level) is generated or not. Acceptable values are UCOL_OFF,
  262. * when case level is not generated, and UCOL_ON which causes the case
  263. * level to be generated. Contents of the case level are affected by
  264. * the value of UCOL_CASE_FIRST attribute. A simple way to ignore
  265. * accent differences in a string is to set the strength to UCOL_PRIMARY
  266. * and enable case level. The default setting in a Collator object depends
  267. * on the locale data loaded from the resources.
  268. * @stable ICU 2.0
  269. */
  270. UCOL_CASE_LEVEL,
  271. /** Controls whether the normalization check and necessary normalizations
  272. * are performed. When set to UCOL_OFF no normalization check
  273. * is performed. The correctness of the result is guaranteed only if the
  274. * input data is in so-called FCD form (see users manual for more info).
  275. * When set to UCOL_ON, an incremental check is performed to see whether
  276. * the input data is in the FCD form. If the data is not in the FCD form,
  277. * incremental NFD normalization is performed. The default setting in a
  278. * Collator object depends on the locale data loaded from the resources.
  279. * For many locales, the default is UCOL_OFF, but for others, such as "hi"
  280. * "vi', or "bn", * the default could be UCOL_ON.
  281. * @stable ICU 2.0
  282. */
  283. UCOL_NORMALIZATION_MODE,
  284. /** An alias for UCOL_NORMALIZATION_MODE attribute.
  285. * @stable ICU 2.0
  286. */
  287. UCOL_DECOMPOSITION_MODE = UCOL_NORMALIZATION_MODE,
  288. /** The strength attribute. Can be either UCOL_PRIMARY, UCOL_SECONDARY,
  289. * UCOL_TERTIARY, UCOL_QUATERNARY or UCOL_IDENTICAL. The usual strength
  290. * for most locales (except Japanese) is tertiary.
  291. *
  292. * Quaternary strength
  293. * is useful when combined with shifted setting for alternate handling
  294. * attribute and for JIS X 4061 collation, when it is used to distinguish
  295. * between Katakana and Hiragana.
  296. * Otherwise, quaternary level
  297. * is affected only by the number of non-ignorable code points in
  298. * the string.
  299. *
  300. * Identical strength is rarely useful, as it amounts
  301. * to codepoints of the NFD form of the string.
  302. * @stable ICU 2.0
  303. */
  304. UCOL_STRENGTH,
  305. #ifndef U_HIDE_DEPRECATED_API
  306. /** When turned on, this attribute positions Hiragana before all
  307. * non-ignorables on quaternary level This is a sneaky way to produce JIS
  308. * sort order.
  309. *
  310. * This attribute was an implementation detail of the CLDR Japanese tailoring.
  311. * Since ICU 50, this attribute is not settable any more via API functions.
  312. * Since CLDR 25/ICU 53, explicit quaternary relations are used
  313. * to achieve the same Japanese sort order.
  314. *
  315. * @deprecated ICU 50 Implementation detail, cannot be set via API, was removed from implementation.
  316. */
  317. UCOL_HIRAGANA_QUATERNARY_MODE = UCOL_STRENGTH + 1,
  318. #endif /* U_HIDE_DEPRECATED_API */
  319. /**
  320. * When turned on, this attribute makes
  321. * substrings of digits sort according to their numeric values.
  322. *
  323. * This is a way to get '100' to sort AFTER '2'. Note that the longest
  324. * digit substring that can be treated as a single unit is
  325. * 254 digits (not counting leading zeros). If a digit substring is
  326. * longer than that, the digits beyond the limit will be treated as a
  327. * separate digit substring.
  328. *
  329. * A "digit" in this sense is a code point with General_Category=Nd,
  330. * which does not include circled numbers, roman numerals, etc.
  331. * Only a contiguous digit substring is considered, that is,
  332. * non-negative integers without separators.
  333. * There is no support for plus/minus signs, decimals, exponents, etc.
  334. *
  335. * @stable ICU 2.8
  336. */
  337. UCOL_NUMERIC_COLLATION = UCOL_STRENGTH + 2,
  338. /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
  339. * it is needed for layout of RuleBasedCollator object. */
  340. #ifndef U_FORCE_HIDE_DEPRECATED_API
  341. /**
  342. * One more than the highest normal UColAttribute value.
  343. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  344. */
  345. UCOL_ATTRIBUTE_COUNT
  346. #endif // U_FORCE_HIDE_DEPRECATED_API
  347. } UColAttribute;
  348. /** Options for retrieving the rule string
  349. * @stable ICU 2.0
  350. */
  351. typedef enum {
  352. /**
  353. * Retrieves the tailoring rules only.
  354. * Same as calling the version of getRules() without UColRuleOption.
  355. * @stable ICU 2.0
  356. */
  357. UCOL_TAILORING_ONLY,
  358. /**
  359. * Retrieves the "UCA rules" concatenated with the tailoring rules.
  360. * The "UCA rules" are an <i>approximation</i> of the root collator's sort order.
  361. * They are almost never used or useful at runtime and can be removed from the data.
  362. * See https://unicode-org.github.io/icu/userguide/collation/customization#building-on-existing-locales
  363. * @stable ICU 2.0
  364. */
  365. UCOL_FULL_RULES
  366. } UColRuleOption ;
  367. /**
  368. * Open a UCollator for comparing strings.
  369. *
  370. * For some languages, multiple collation types are available;
  371. * for example, "de@collation=phonebook".
  372. * Starting with ICU 54, collation attributes can be specified via locale keywords as well,
  373. * in the old locale extension syntax ("el@colCaseFirst=upper")
  374. * or in language tag syntax ("el-u-kf-upper").
  375. * See <a href="https://unicode-org.github.io/icu/userguide/collation/api">User Guide: Collation API</a>.
  376. *
  377. * The UCollator pointer is used in all the calls to the Collation
  378. * service. After finished, collator must be disposed of by calling
  379. * {@link #ucol_close }.
  380. * @param loc The locale containing the required collation rules.
  381. * Special values for locales can be passed in -
  382. * if NULL is passed for the locale, the default locale
  383. * collation rules will be used. If empty string ("") or
  384. * "root" are passed, the root collator will be returned.
  385. * @param status A pointer to a UErrorCode to receive any errors
  386. * @return A pointer to a UCollator, or 0 if an error occurred.
  387. * @see ucol_openRules
  388. * @see ucol_clone
  389. * @see ucol_close
  390. * @stable ICU 2.0
  391. */
  392. U_CAPI UCollator* U_EXPORT2
  393. ucol_open(const char *loc, UErrorCode *status);
  394. /**
  395. * Produce a UCollator instance according to the rules supplied.
  396. * The rules are used to change the default ordering, defined in the
  397. * UCA in a process called tailoring. The resulting UCollator pointer
  398. * can be used in the same way as the one obtained by {@link #ucol_strcoll }.
  399. * @param rules A string describing the collation rules. For the syntax
  400. * of the rules please see users guide.
  401. * @param rulesLength The length of rules, or -1 if null-terminated.
  402. * @param normalizationMode The normalization mode: One of
  403. * UCOL_OFF (expect the text to not need normalization),
  404. * UCOL_ON (normalize), or
  405. * UCOL_DEFAULT (set the mode according to the rules)
  406. * @param strength The default collation strength; one of UCOL_PRIMARY, UCOL_SECONDARY,
  407. * UCOL_TERTIARY, UCOL_IDENTICAL,UCOL_DEFAULT_STRENGTH - can be also set in the rules.
  408. * @param parseError A pointer to UParseError to receive information about errors
  409. * occurred during parsing. This argument can currently be set
  410. * to NULL, but at users own risk. Please provide a real structure.
  411. * @param status A pointer to a UErrorCode to receive any errors
  412. * @return A pointer to a UCollator. It is not guaranteed that NULL be returned in case
  413. * of error - please use status argument to check for errors.
  414. * @see ucol_open
  415. * @see ucol_clone
  416. * @see ucol_close
  417. * @stable ICU 2.0
  418. */
  419. U_CAPI UCollator* U_EXPORT2
  420. ucol_openRules( const UChar *rules,
  421. int32_t rulesLength,
  422. UColAttributeValue normalizationMode,
  423. UCollationStrength strength,
  424. UParseError *parseError,
  425. UErrorCode *status);
  426. #ifndef U_HIDE_DEPRECATED_API
  427. /**
  428. * Open a collator defined by a short form string.
  429. * The structure and the syntax of the string is defined in the "Naming collators"
  430. * section of the users guide:
  431. * https://unicode-org.github.io/icu/userguide/collation/concepts#collator-naming-scheme
  432. * Attributes are overridden by the subsequent attributes. So, for "S2_S3", final
  433. * strength will be 3. 3066bis locale overrides individual locale parts.
  434. * The call to this function is equivalent to a call to ucol_open, followed by a
  435. * series of calls to ucol_setAttribute and ucol_setVariableTop.
  436. * @param definition A short string containing a locale and a set of attributes.
  437. * Attributes not explicitly mentioned are left at the default
  438. * state for a locale.
  439. * @param parseError if not NULL, structure that will get filled with error's pre
  440. * and post context in case of error.
  441. * @param forceDefaults if false, the settings that are the same as the collator
  442. * default settings will not be applied (for example, setting
  443. * French secondary on a French collator would not be executed).
  444. * If true, all the settings will be applied regardless of the
  445. * collator default value. If the definition
  446. * strings are to be cached, should be set to false.
  447. * @param status Error code. Apart from regular error conditions connected to
  448. * instantiating collators (like out of memory or similar), this
  449. * API will return an error if an invalid attribute or attribute/value
  450. * combination is specified.
  451. * @return A pointer to a UCollator or 0 if an error occurred (including an
  452. * invalid attribute).
  453. * @see ucol_open
  454. * @see ucol_setAttribute
  455. * @see ucol_setVariableTop
  456. * @see ucol_getShortDefinitionString
  457. * @see ucol_normalizeShortDefinitionString
  458. * @deprecated ICU 54 Use ucol_open() with language tag collation keywords instead.
  459. */
  460. U_DEPRECATED UCollator* U_EXPORT2
  461. ucol_openFromShortString( const char *definition,
  462. UBool forceDefaults,
  463. UParseError *parseError,
  464. UErrorCode *status);
  465. #endif /* U_HIDE_DEPRECATED_API */
  466. #ifndef U_HIDE_DEPRECATED_API
  467. /**
  468. * Get a set containing the contractions defined by the collator. The set includes
  469. * both the root collator's contractions and the contractions defined by the collator. This set
  470. * will contain only strings. If a tailoring explicitly suppresses contractions from
  471. * the root collator (like Russian), removed contractions will not be in the resulting set.
  472. * @param coll collator
  473. * @param conts the set to hold the result. It gets emptied before
  474. * contractions are added.
  475. * @param status to hold the error code
  476. * @return the size of the contraction set
  477. *
  478. * @deprecated ICU 3.4, use ucol_getContractionsAndExpansions instead
  479. */
  480. U_DEPRECATED int32_t U_EXPORT2
  481. ucol_getContractions( const UCollator *coll,
  482. USet *conts,
  483. UErrorCode *status);
  484. #endif /* U_HIDE_DEPRECATED_API */
  485. /**
  486. * Get a set containing the expansions defined by the collator. The set includes
  487. * both the root collator's expansions and the expansions defined by the tailoring
  488. * @param coll collator
  489. * @param contractions if not NULL, the set to hold the contractions
  490. * @param expansions if not NULL, the set to hold the expansions
  491. * @param addPrefixes add the prefix contextual elements to contractions
  492. * @param status to hold the error code
  493. *
  494. * @stable ICU 3.4
  495. */
  496. U_CAPI void U_EXPORT2
  497. ucol_getContractionsAndExpansions( const UCollator *coll,
  498. USet *contractions, USet *expansions,
  499. UBool addPrefixes, UErrorCode *status);
  500. /**
  501. * Close a UCollator.
  502. * Once closed, a UCollator should not be used. Every open collator should
  503. * be closed. Otherwise, a memory leak will result.
  504. * @param coll The UCollator to close.
  505. * @see ucol_open
  506. * @see ucol_openRules
  507. * @see ucol_clone
  508. * @stable ICU 2.0
  509. */
  510. U_CAPI void U_EXPORT2
  511. ucol_close(UCollator *coll);
  512. #if U_SHOW_CPLUSPLUS_API
  513. U_NAMESPACE_BEGIN
  514. /**
  515. * \class LocalUCollatorPointer
  516. * "Smart pointer" class, closes a UCollator via ucol_close().
  517. * For most methods see the LocalPointerBase base class.
  518. *
  519. * @see LocalPointerBase
  520. * @see LocalPointer
  521. * @stable ICU 4.4
  522. */
  523. U_DEFINE_LOCAL_OPEN_POINTER(LocalUCollatorPointer, UCollator, ucol_close);
  524. U_NAMESPACE_END
  525. #endif
  526. /**
  527. * Compare two strings.
  528. * The strings will be compared using the options already specified.
  529. * @param coll The UCollator containing the comparison rules.
  530. * @param source The source string.
  531. * @param sourceLength The length of source, or -1 if null-terminated.
  532. * @param target The target string.
  533. * @param targetLength The length of target, or -1 if null-terminated.
  534. * @return The result of comparing the strings; one of UCOL_EQUAL,
  535. * UCOL_GREATER, UCOL_LESS
  536. * @see ucol_greater
  537. * @see ucol_greaterOrEqual
  538. * @see ucol_equal
  539. * @stable ICU 2.0
  540. */
  541. U_CAPI UCollationResult U_EXPORT2
  542. ucol_strcoll( const UCollator *coll,
  543. const UChar *source,
  544. int32_t sourceLength,
  545. const UChar *target,
  546. int32_t targetLength);
  547. /**
  548. * Compare two strings in UTF-8.
  549. * The strings will be compared using the options already specified.
  550. * Note: When input string contains malformed a UTF-8 byte sequence,
  551. * this function treats these bytes as REPLACEMENT CHARACTER (U+FFFD).
  552. * @param coll The UCollator containing the comparison rules.
  553. * @param source The source UTF-8 string.
  554. * @param sourceLength The length of source, or -1 if null-terminated.
  555. * @param target The target UTF-8 string.
  556. * @param targetLength The length of target, or -1 if null-terminated.
  557. * @param status A pointer to a UErrorCode to receive any errors
  558. * @return The result of comparing the strings; one of UCOL_EQUAL,
  559. * UCOL_GREATER, UCOL_LESS
  560. * @see ucol_greater
  561. * @see ucol_greaterOrEqual
  562. * @see ucol_equal
  563. * @stable ICU 50
  564. */
  565. U_CAPI UCollationResult U_EXPORT2
  566. ucol_strcollUTF8(
  567. const UCollator *coll,
  568. const char *source,
  569. int32_t sourceLength,
  570. const char *target,
  571. int32_t targetLength,
  572. UErrorCode *status);
  573. /**
  574. * Determine if one string is greater than another.
  575. * This function is equivalent to {@link #ucol_strcoll } == UCOL_GREATER
  576. * @param coll The UCollator containing the comparison rules.
  577. * @param source The source string.
  578. * @param sourceLength The length of source, or -1 if null-terminated.
  579. * @param target The target string.
  580. * @param targetLength The length of target, or -1 if null-terminated.
  581. * @return true if source is greater than target, false otherwise.
  582. * @see ucol_strcoll
  583. * @see ucol_greaterOrEqual
  584. * @see ucol_equal
  585. * @stable ICU 2.0
  586. */
  587. U_CAPI UBool U_EXPORT2
  588. ucol_greater(const UCollator *coll,
  589. const UChar *source, int32_t sourceLength,
  590. const UChar *target, int32_t targetLength);
  591. /**
  592. * Determine if one string is greater than or equal to another.
  593. * This function is equivalent to {@link #ucol_strcoll } != UCOL_LESS
  594. * @param coll The UCollator containing the comparison rules.
  595. * @param source The source string.
  596. * @param sourceLength The length of source, or -1 if null-terminated.
  597. * @param target The target string.
  598. * @param targetLength The length of target, or -1 if null-terminated.
  599. * @return true if source is greater than or equal to target, false otherwise.
  600. * @see ucol_strcoll
  601. * @see ucol_greater
  602. * @see ucol_equal
  603. * @stable ICU 2.0
  604. */
  605. U_CAPI UBool U_EXPORT2
  606. ucol_greaterOrEqual(const UCollator *coll,
  607. const UChar *source, int32_t sourceLength,
  608. const UChar *target, int32_t targetLength);
  609. /**
  610. * Compare two strings for equality.
  611. * This function is equivalent to {@link #ucol_strcoll } == UCOL_EQUAL
  612. * @param coll The UCollator containing the comparison rules.
  613. * @param source The source string.
  614. * @param sourceLength The length of source, or -1 if null-terminated.
  615. * @param target The target string.
  616. * @param targetLength The length of target, or -1 if null-terminated.
  617. * @return true if source is equal to target, false otherwise
  618. * @see ucol_strcoll
  619. * @see ucol_greater
  620. * @see ucol_greaterOrEqual
  621. * @stable ICU 2.0
  622. */
  623. U_CAPI UBool U_EXPORT2
  624. ucol_equal(const UCollator *coll,
  625. const UChar *source, int32_t sourceLength,
  626. const UChar *target, int32_t targetLength);
  627. /**
  628. * Compare two UTF-8 encoded strings.
  629. * The strings will be compared using the options already specified.
  630. * @param coll The UCollator containing the comparison rules.
  631. * @param sIter The source string iterator.
  632. * @param tIter The target string iterator.
  633. * @return The result of comparing the strings; one of UCOL_EQUAL,
  634. * UCOL_GREATER, UCOL_LESS
  635. * @param status A pointer to a UErrorCode to receive any errors
  636. * @see ucol_strcoll
  637. * @stable ICU 2.6
  638. */
  639. U_CAPI UCollationResult U_EXPORT2
  640. ucol_strcollIter( const UCollator *coll,
  641. UCharIterator *sIter,
  642. UCharIterator *tIter,
  643. UErrorCode *status);
  644. /**
  645. * Get the collation strength used in a UCollator.
  646. * The strength influences how strings are compared.
  647. * @param coll The UCollator to query.
  648. * @return The collation strength; one of UCOL_PRIMARY, UCOL_SECONDARY,
  649. * UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL
  650. * @see ucol_setStrength
  651. * @stable ICU 2.0
  652. */
  653. U_CAPI UCollationStrength U_EXPORT2
  654. ucol_getStrength(const UCollator *coll);
  655. /**
  656. * Set the collation strength used in a UCollator.
  657. * The strength influences how strings are compared.
  658. * @param coll The UCollator to set.
  659. * @param strength The desired collation strength; one of UCOL_PRIMARY,
  660. * UCOL_SECONDARY, UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL, UCOL_DEFAULT
  661. * @see ucol_getStrength
  662. * @stable ICU 2.0
  663. */
  664. U_CAPI void U_EXPORT2
  665. ucol_setStrength(UCollator *coll,
  666. UCollationStrength strength);
  667. /**
  668. * Retrieves the reordering codes for this collator.
  669. * These reordering codes are a combination of UScript codes and UColReorderCode entries.
  670. * @param coll The UCollator to query.
  671. * @param dest The array to fill with the script ordering.
  672. * @param destCapacity The length of dest. If it is 0, then dest may be NULL and the function
  673. * will only return the length of the result without writing any codes (pre-flighting).
  674. * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate a
  675. * failure before the function call.
  676. * @return The number of reordering codes written to the dest array.
  677. * @see ucol_setReorderCodes
  678. * @see ucol_getEquivalentReorderCodes
  679. * @see UScriptCode
  680. * @see UColReorderCode
  681. * @stable ICU 4.8
  682. */
  683. U_CAPI int32_t U_EXPORT2
  684. ucol_getReorderCodes(const UCollator* coll,
  685. int32_t* dest,
  686. int32_t destCapacity,
  687. UErrorCode *pErrorCode);
  688. /**
  689. * Sets the reordering codes for this collator.
  690. * Collation reordering allows scripts and some other groups of characters
  691. * to be moved relative to each other. This reordering is done on top of
  692. * the DUCET/CLDR standard collation order. Reordering can specify groups to be placed
  693. * at the start and/or the end of the collation order. These groups are specified using
  694. * UScript codes and UColReorderCode entries.
  695. *
  696. * <p>By default, reordering codes specified for the start of the order are placed in the
  697. * order given after several special non-script blocks. These special groups of characters
  698. * are space, punctuation, symbol, currency, and digit. These special groups are represented with
  699. * UColReorderCode entries. Script groups can be intermingled with
  700. * these special non-script groups if those special groups are explicitly specified in the reordering.
  701. *
  702. * <p>The special code OTHERS stands for any script that is not explicitly
  703. * mentioned in the list of reordering codes given. Anything that is after OTHERS
  704. * will go at the very end of the reordering in the order given.
  705. *
  706. * <p>The special reorder code DEFAULT will reset the reordering for this collator
  707. * to the default for this collator. The default reordering may be the DUCET/CLDR order or may be a reordering that
  708. * was specified when this collator was created from resource data or from rules. The
  709. * DEFAULT code <b>must</b> be the sole code supplied when it is used.
  710. * If not, then U_ILLEGAL_ARGUMENT_ERROR will be set.
  711. *
  712. * <p>The special reorder code NONE will remove any reordering for this collator.
  713. * The result of setting no reordering will be to have the DUCET/CLDR ordering used. The
  714. * NONE code <b>must</b> be the sole code supplied when it is used.
  715. *
  716. * @param coll The UCollator to set.
  717. * @param reorderCodes An array of script codes in the new order. This can be NULL if the
  718. * length is also set to 0. An empty array will clear any reordering codes on the collator.
  719. * @param reorderCodesLength The length of reorderCodes.
  720. * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate a
  721. * failure before the function call.
  722. * @see ucol_getReorderCodes
  723. * @see ucol_getEquivalentReorderCodes
  724. * @see UScriptCode
  725. * @see UColReorderCode
  726. * @stable ICU 4.8
  727. */
  728. U_CAPI void U_EXPORT2
  729. ucol_setReorderCodes(UCollator* coll,
  730. const int32_t* reorderCodes,
  731. int32_t reorderCodesLength,
  732. UErrorCode *pErrorCode);
  733. /**
  734. * Retrieves the reorder codes that are grouped with the given reorder code. Some reorder
  735. * codes will be grouped and must reorder together.
  736. * Beginning with ICU 55, scripts only reorder together if they are primary-equal,
  737. * for example Hiragana and Katakana.
  738. *
  739. * @param reorderCode The reorder code to determine equivalence for.
  740. * @param dest The array to fill with the script ordering.
  741. * @param destCapacity The length of dest. If it is 0, then dest may be NULL and the function
  742. * will only return the length of the result without writing any codes (pre-flighting).
  743. * @param pErrorCode Must be a valid pointer to an error code value, which must not indicate
  744. * a failure before the function call.
  745. * @return The number of reordering codes written to the dest array.
  746. * @see ucol_setReorderCodes
  747. * @see ucol_getReorderCodes
  748. * @see UScriptCode
  749. * @see UColReorderCode
  750. * @stable ICU 4.8
  751. */
  752. U_CAPI int32_t U_EXPORT2
  753. ucol_getEquivalentReorderCodes(int32_t reorderCode,
  754. int32_t* dest,
  755. int32_t destCapacity,
  756. UErrorCode *pErrorCode);
  757. /**
  758. * Get the display name for a UCollator.
  759. * The display name is suitable for presentation to a user.
  760. * @param objLoc The locale of the collator in question.
  761. * @param dispLoc The locale for display.
  762. * @param result A pointer to a buffer to receive the attribute.
  763. * @param resultLength The maximum size of result.
  764. * @param status A pointer to a UErrorCode to receive any errors
  765. * @return The total buffer size needed; if greater than resultLength,
  766. * the output was truncated.
  767. * @stable ICU 2.0
  768. */
  769. U_CAPI int32_t U_EXPORT2
  770. ucol_getDisplayName( const char *objLoc,
  771. const char *dispLoc,
  772. UChar *result,
  773. int32_t resultLength,
  774. UErrorCode *status);
  775. /**
  776. * Get a locale for which collation rules are available.
  777. * A UCollator in a locale returned by this function will perform the correct
  778. * collation for the locale.
  779. * @param localeIndex The index of the desired locale.
  780. * @return A locale for which collation rules are available, or 0 if none.
  781. * @see ucol_countAvailable
  782. * @stable ICU 2.0
  783. */
  784. U_CAPI const char* U_EXPORT2
  785. ucol_getAvailable(int32_t localeIndex);
  786. /**
  787. * Determine how many locales have collation rules available.
  788. * This function is most useful as determining the loop ending condition for
  789. * calls to {@link #ucol_getAvailable }.
  790. * @return The number of locales for which collation rules are available.
  791. * @see ucol_getAvailable
  792. * @stable ICU 2.0
  793. */
  794. U_CAPI int32_t U_EXPORT2
  795. ucol_countAvailable(void);
  796. #if !UCONFIG_NO_SERVICE
  797. /**
  798. * Create a string enumerator of all locales for which a valid
  799. * collator may be opened.
  800. * @param status input-output error code
  801. * @return a string enumeration over locale strings. The caller is
  802. * responsible for closing the result.
  803. * @stable ICU 3.0
  804. */
  805. U_CAPI UEnumeration* U_EXPORT2
  806. ucol_openAvailableLocales(UErrorCode *status);
  807. #endif
  808. /**
  809. * Create a string enumerator of all possible keywords that are relevant to
  810. * collation. At this point, the only recognized keyword for this
  811. * service is "collation".
  812. * @param status input-output error code
  813. * @return a string enumeration over locale strings. The caller is
  814. * responsible for closing the result.
  815. * @stable ICU 3.0
  816. */
  817. U_CAPI UEnumeration* U_EXPORT2
  818. ucol_getKeywords(UErrorCode *status);
  819. /**
  820. * Given a keyword, create a string enumeration of all values
  821. * for that keyword that are currently in use.
  822. * @param keyword a particular keyword as enumerated by
  823. * ucol_getKeywords. If any other keyword is passed in, *status is set
  824. * to U_ILLEGAL_ARGUMENT_ERROR.
  825. * @param status input-output error code
  826. * @return a string enumeration over collation keyword values, or NULL
  827. * upon error. The caller is responsible for closing the result.
  828. * @stable ICU 3.0
  829. */
  830. U_CAPI UEnumeration* U_EXPORT2
  831. ucol_getKeywordValues(const char *keyword, UErrorCode *status);
  832. /**
  833. * Given a key and a locale, returns an array of string values in a preferred
  834. * order that would make a difference. These are all and only those values where
  835. * the open (creation) of the service with the locale formed from the input locale
  836. * plus input keyword and that value has different behavior than creation with the
  837. * input locale alone.
  838. * @param key one of the keys supported by this service. For now, only
  839. * "collation" is supported.
  840. * @param locale the locale
  841. * @param commonlyUsed if set to true it will return only commonly used values
  842. * with the given locale in preferred order. Otherwise,
  843. * it will return all the available values for the locale.
  844. * @param status error status
  845. * @return a string enumeration over keyword values for the given key and the locale.
  846. * @stable ICU 4.2
  847. */
  848. U_CAPI UEnumeration* U_EXPORT2
  849. ucol_getKeywordValuesForLocale(const char* key,
  850. const char* locale,
  851. UBool commonlyUsed,
  852. UErrorCode* status);
  853. /**
  854. * Return the functionally equivalent locale for the specified
  855. * input locale, with respect to given keyword, for the
  856. * collation service. If two different input locale + keyword
  857. * combinations produce the same result locale, then collators
  858. * instantiated for these two different input locales will behave
  859. * equivalently. The converse is not always true; two collators
  860. * may in fact be equivalent, but return different results, due to
  861. * internal details. The return result has no other meaning than
  862. * that stated above, and implies nothing as to the relationship
  863. * between the two locales. This is intended for use by
  864. * applications who wish to cache collators, or otherwise reuse
  865. * collators when possible. The functional equivalent may change
  866. * over time. For more information, please see the <a
  867. * href="https://unicode-org.github.io/icu/userguide/locale#locales-and-services">
  868. * Locales and Services</a> section of the ICU User Guide.
  869. * @param result fillin for the functionally equivalent result locale
  870. * @param resultCapacity capacity of the fillin buffer
  871. * @param keyword a particular keyword as enumerated by
  872. * ucol_getKeywords.
  873. * @param locale the specified input locale
  874. * @param isAvailable if non-NULL, pointer to a fillin parameter that
  875. * on return indicates whether the specified input locale was 'available'
  876. * to the collation service. A locale is defined as 'available' if it
  877. * physically exists within the collation locale data.
  878. * @param status pointer to input-output error code
  879. * @return the actual buffer size needed for the locale. If greater
  880. * than resultCapacity, the returned full name will be truncated and
  881. * an error code will be returned.
  882. * @stable ICU 3.0
  883. */
  884. U_CAPI int32_t U_EXPORT2
  885. ucol_getFunctionalEquivalent(char* result, int32_t resultCapacity,
  886. const char* keyword, const char* locale,
  887. UBool* isAvailable, UErrorCode* status);
  888. /**
  889. * Get the collation tailoring rules from a UCollator.
  890. * The rules will follow the rule syntax.
  891. * @param coll The UCollator to query.
  892. * @param length
  893. * @return The collation tailoring rules.
  894. * @stable ICU 2.0
  895. */
  896. U_CAPI const UChar* U_EXPORT2
  897. ucol_getRules( const UCollator *coll,
  898. int32_t *length);
  899. #ifndef U_HIDE_DEPRECATED_API
  900. /** Get the short definition string for a collator. This API harvests the collator's
  901. * locale and the attribute set and produces a string that can be used for opening
  902. * a collator with the same attributes using the ucol_openFromShortString API.
  903. * This string will be normalized.
  904. * The structure and the syntax of the string is defined in the "Naming collators"
  905. * section of the users guide:
  906. * https://unicode-org.github.io/icu/userguide/collation/concepts#collator-naming-scheme
  907. * This API supports preflighting.
  908. * @param coll a collator
  909. * @param locale a locale that will appear as a collators locale in the resulting
  910. * short string definition. If NULL, the locale will be harvested
  911. * from the collator.
  912. * @param buffer space to hold the resulting string
  913. * @param capacity capacity of the buffer
  914. * @param status for returning errors. All the preflighting errors are featured
  915. * @return length of the resulting string
  916. * @see ucol_openFromShortString
  917. * @see ucol_normalizeShortDefinitionString
  918. * @deprecated ICU 54
  919. */
  920. U_DEPRECATED int32_t U_EXPORT2
  921. ucol_getShortDefinitionString(const UCollator *coll,
  922. const char *locale,
  923. char *buffer,
  924. int32_t capacity,
  925. UErrorCode *status);
  926. /** Verifies and normalizes short definition string.
  927. * Normalized short definition string has all the option sorted by the argument name,
  928. * so that equivalent definition strings are the same.
  929. * This API supports preflighting.
  930. * @param source definition string
  931. * @param destination space to hold the resulting string
  932. * @param capacity capacity of the buffer
  933. * @param parseError if not NULL, structure that will get filled with error's pre
  934. * and post context in case of error.
  935. * @param status Error code. This API will return an error if an invalid attribute
  936. * or attribute/value combination is specified. All the preflighting
  937. * errors are also featured
  938. * @return length of the resulting normalized string.
  939. *
  940. * @see ucol_openFromShortString
  941. * @see ucol_getShortDefinitionString
  942. *
  943. * @deprecated ICU 54
  944. */
  945. U_DEPRECATED int32_t U_EXPORT2
  946. ucol_normalizeShortDefinitionString(const char *source,
  947. char *destination,
  948. int32_t capacity,
  949. UParseError *parseError,
  950. UErrorCode *status);
  951. #endif /* U_HIDE_DEPRECATED_API */
  952. /**
  953. * Get a sort key for a string from a UCollator.
  954. * Sort keys may be compared using <TT>strcmp</TT>.
  955. *
  956. * Note that sort keys are often less efficient than simply doing comparison.
  957. * For more details, see the ICU User Guide.
  958. *
  959. * Like ICU functions that write to an output buffer, the buffer contents
  960. * is undefined if the buffer capacity (resultLength parameter) is too small.
  961. * Unlike ICU functions that write a string to an output buffer,
  962. * the terminating zero byte is counted in the sort key length.
  963. * @param coll The UCollator containing the collation rules.
  964. * @param source The string to transform.
  965. * @param sourceLength The length of source, or -1 if null-terminated.
  966. * @param result A pointer to a buffer to receive the attribute.
  967. * @param resultLength The maximum size of result.
  968. * @return The size needed to fully store the sort key.
  969. * If there was an internal error generating the sort key,
  970. * a zero value is returned.
  971. * @see ucol_keyHashCode
  972. * @stable ICU 2.0
  973. */
  974. U_CAPI int32_t U_EXPORT2
  975. ucol_getSortKey(const UCollator *coll,
  976. const UChar *source,
  977. int32_t sourceLength,
  978. uint8_t *result,
  979. int32_t resultLength);
  980. /** Gets the next count bytes of a sort key. Caller needs
  981. * to preserve state array between calls and to provide
  982. * the same type of UCharIterator set with the same string.
  983. * The destination buffer provided must be big enough to store
  984. * the number of requested bytes.
  985. *
  986. * The generated sort key may or may not be compatible with
  987. * sort keys generated using ucol_getSortKey().
  988. * @param coll The UCollator containing the collation rules.
  989. * @param iter UCharIterator containing the string we need
  990. * the sort key to be calculated for.
  991. * @param state Opaque state of sortkey iteration.
  992. * @param dest Buffer to hold the resulting sortkey part
  993. * @param count number of sort key bytes required.
  994. * @param status error code indicator.
  995. * @return the actual number of bytes of a sortkey. It can be
  996. * smaller than count if we have reached the end of
  997. * the sort key.
  998. * @stable ICU 2.6
  999. */
  1000. U_CAPI int32_t U_EXPORT2
  1001. ucol_nextSortKeyPart(const UCollator *coll,
  1002. UCharIterator *iter,
  1003. uint32_t state[2],
  1004. uint8_t *dest, int32_t count,
  1005. UErrorCode *status);
  1006. /** enum that is taken by ucol_getBound API
  1007. * See below for explanation
  1008. * do not change the values assigned to the
  1009. * members of this enum. Underlying code
  1010. * depends on them having these numbers
  1011. * @stable ICU 2.0
  1012. */
  1013. typedef enum {
  1014. /** lower bound */
  1015. UCOL_BOUND_LOWER = 0,
  1016. /** upper bound that will match strings of exact size */
  1017. UCOL_BOUND_UPPER = 1,
  1018. /** upper bound that will match all the strings that have the same initial substring as the given string */
  1019. UCOL_BOUND_UPPER_LONG = 2,
  1020. #ifndef U_HIDE_DEPRECATED_API
  1021. /**
  1022. * One more than the highest normal UColBoundMode value.
  1023. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  1024. */
  1025. UCOL_BOUND_VALUE_COUNT
  1026. #endif /* U_HIDE_DEPRECATED_API */
  1027. } UColBoundMode;
  1028. /**
  1029. * Produce a bound for a given sortkey and a number of levels.
  1030. * Return value is always the number of bytes needed, regardless of
  1031. * whether the result buffer was big enough or even valid.<br>
  1032. * Resulting bounds can be used to produce a range of strings that are
  1033. * between upper and lower bounds. For example, if bounds are produced
  1034. * for a sortkey of string "smith", strings between upper and lower
  1035. * bounds with one level would include "Smith", "SMITH", "sMiTh".<br>
  1036. * There are two upper bounds that can be produced. If UCOL_BOUND_UPPER
  1037. * is produced, strings matched would be as above. However, if bound
  1038. * produced using UCOL_BOUND_UPPER_LONG is used, the above example will
  1039. * also match "Smithsonian" and similar.<br>
  1040. * For more on usage, see example in cintltst/capitst.c in procedure
  1041. * TestBounds.
  1042. * Sort keys may be compared using <TT>strcmp</TT>.
  1043. * @param source The source sortkey.
  1044. * @param sourceLength The length of source, or -1 if null-terminated.
  1045. * (If an unmodified sortkey is passed, it is always null
  1046. * terminated).
  1047. * @param boundType Type of bound required. It can be UCOL_BOUND_LOWER, which
  1048. * produces a lower inclusive bound, UCOL_BOUND_UPPER, that
  1049. * produces upper bound that matches strings of the same length
  1050. * or UCOL_BOUND_UPPER_LONG that matches strings that have the
  1051. * same starting substring as the source string.
  1052. * @param noOfLevels Number of levels required in the resulting bound (for most
  1053. * uses, the recommended value is 1). See users guide for
  1054. * explanation on number of levels a sortkey can have.
  1055. * @param result A pointer to a buffer to receive the resulting sortkey.
  1056. * @param resultLength The maximum size of result.
  1057. * @param status Used for returning error code if something went wrong. If the
  1058. * number of levels requested is higher than the number of levels
  1059. * in the source key, a warning (U_SORT_KEY_TOO_SHORT_WARNING) is
  1060. * issued.
  1061. * @return The size needed to fully store the bound.
  1062. * @see ucol_keyHashCode
  1063. * @stable ICU 2.1
  1064. */
  1065. U_CAPI int32_t U_EXPORT2
  1066. ucol_getBound(const uint8_t *source,
  1067. int32_t sourceLength,
  1068. UColBoundMode boundType,
  1069. uint32_t noOfLevels,
  1070. uint8_t *result,
  1071. int32_t resultLength,
  1072. UErrorCode *status);
  1073. /**
  1074. * Gets the version information for a Collator. Version is currently
  1075. * an opaque 32-bit number which depends, among other things, on major
  1076. * versions of the collator tailoring and UCA.
  1077. * @param coll The UCollator to query.
  1078. * @param info the version # information, the result will be filled in
  1079. * @stable ICU 2.0
  1080. */
  1081. U_CAPI void U_EXPORT2
  1082. ucol_getVersion(const UCollator* coll, UVersionInfo info);
  1083. /**
  1084. * Gets the UCA version information for a Collator. Version is the
  1085. * UCA version number (3.1.1, 4.0).
  1086. * @param coll The UCollator to query.
  1087. * @param info the version # information, the result will be filled in
  1088. * @stable ICU 2.8
  1089. */
  1090. U_CAPI void U_EXPORT2
  1091. ucol_getUCAVersion(const UCollator* coll, UVersionInfo info);
  1092. /**
  1093. * Merges two sort keys. The levels are merged with their corresponding counterparts
  1094. * (primaries with primaries, secondaries with secondaries etc.). Between the values
  1095. * from the same level a separator is inserted.
  1096. *
  1097. * This is useful, for example, for combining sort keys from first and last names
  1098. * to sort such pairs.
  1099. * See http://www.unicode.org/reports/tr10/#Merging_Sort_Keys
  1100. *
  1101. * The recommended way to achieve "merged" sorting is by
  1102. * concatenating strings with U+FFFE between them.
  1103. * The concatenation has the same sort order as the merged sort keys,
  1104. * but merge(getSortKey(str1), getSortKey(str2)) may differ from getSortKey(str1 + '\\uFFFE' + str2).
  1105. * Using strings with U+FFFE may yield shorter sort keys.
  1106. *
  1107. * For details about Sort Key Features see
  1108. * https://unicode-org.github.io/icu/userguide/collation/api#sort-key-features
  1109. *
  1110. * It is possible to merge multiple sort keys by consecutively merging
  1111. * another one with the intermediate result.
  1112. *
  1113. * The length of the merge result is the sum of the lengths of the input sort keys.
  1114. *
  1115. * Example (uncompressed):
  1116. * <pre>191B1D 01 050505 01 910505 00
  1117. * 1F2123 01 050505 01 910505 00</pre>
  1118. * will be merged as
  1119. * <pre>191B1D 02 1F2123 01 050505 02 050505 01 910505 02 910505 00</pre>
  1120. *
  1121. * If the destination buffer is not big enough, then its contents are undefined.
  1122. * If any of source lengths are zero or any of the source pointers are NULL/undefined,
  1123. * the result is of size zero.
  1124. *
  1125. * @param src1 the first sort key
  1126. * @param src1Length the length of the first sort key, including the zero byte at the end;
  1127. * can be -1 if the function is to find the length
  1128. * @param src2 the second sort key
  1129. * @param src2Length the length of the second sort key, including the zero byte at the end;
  1130. * can be -1 if the function is to find the length
  1131. * @param dest the buffer where the merged sort key is written,
  1132. * can be NULL if destCapacity==0
  1133. * @param destCapacity the number of bytes in the dest buffer
  1134. * @return the length of the merged sort key, src1Length+src2Length;
  1135. * can be larger than destCapacity, or 0 if an error occurs (only for illegal arguments),
  1136. * in which cases the contents of dest is undefined
  1137. * @stable ICU 2.0
  1138. */
  1139. U_CAPI int32_t U_EXPORT2
  1140. ucol_mergeSortkeys(const uint8_t *src1, int32_t src1Length,
  1141. const uint8_t *src2, int32_t src2Length,
  1142. uint8_t *dest, int32_t destCapacity);
  1143. /**
  1144. * Universal attribute setter
  1145. * @param coll collator which attributes are to be changed
  1146. * @param attr attribute type
  1147. * @param value attribute value
  1148. * @param status to indicate whether the operation went on smoothly or there were errors
  1149. * @see UColAttribute
  1150. * @see UColAttributeValue
  1151. * @see ucol_getAttribute
  1152. * @stable ICU 2.0
  1153. */
  1154. U_CAPI void U_EXPORT2
  1155. ucol_setAttribute(UCollator *coll, UColAttribute attr, UColAttributeValue value, UErrorCode *status);
  1156. /**
  1157. * Universal attribute getter
  1158. * @param coll collator which attributes are to be changed
  1159. * @param attr attribute type
  1160. * @return attribute value
  1161. * @param status to indicate whether the operation went on smoothly or there were errors
  1162. * @see UColAttribute
  1163. * @see UColAttributeValue
  1164. * @see ucol_setAttribute
  1165. * @stable ICU 2.0
  1166. */
  1167. U_CAPI UColAttributeValue U_EXPORT2
  1168. ucol_getAttribute(const UCollator *coll, UColAttribute attr, UErrorCode *status);
  1169. /**
  1170. * Sets the variable top to the top of the specified reordering group.
  1171. * The variable top determines the highest-sorting character
  1172. * which is affected by UCOL_ALTERNATE_HANDLING.
  1173. * If that attribute is set to UCOL_NON_IGNORABLE, then the variable top has no effect.
  1174. * @param coll the collator
  1175. * @param group one of UCOL_REORDER_CODE_SPACE, UCOL_REORDER_CODE_PUNCTUATION,
  1176. * UCOL_REORDER_CODE_SYMBOL, UCOL_REORDER_CODE_CURRENCY;
  1177. * or UCOL_REORDER_CODE_DEFAULT to restore the default max variable group
  1178. * @param pErrorCode Standard ICU error code. Its input value must
  1179. * pass the U_SUCCESS() test, or else the function returns
  1180. * immediately. Check for U_FAILURE() on output or use with
  1181. * function chaining. (See User Guide for details.)
  1182. * @see ucol_getMaxVariable
  1183. * @stable ICU 53
  1184. */
  1185. U_CAPI void U_EXPORT2
  1186. ucol_setMaxVariable(UCollator *coll, UColReorderCode group, UErrorCode *pErrorCode);
  1187. /**
  1188. * Returns the maximum reordering group whose characters are affected by UCOL_ALTERNATE_HANDLING.
  1189. * @param coll the collator
  1190. * @return the maximum variable reordering group.
  1191. * @see ucol_setMaxVariable
  1192. * @stable ICU 53
  1193. */
  1194. U_CAPI UColReorderCode U_EXPORT2
  1195. ucol_getMaxVariable(const UCollator *coll);
  1196. #ifndef U_HIDE_DEPRECATED_API
  1197. /**
  1198. * Sets the variable top to the primary weight of the specified string.
  1199. *
  1200. * Beginning with ICU 53, the variable top is pinned to
  1201. * the top of one of the supported reordering groups,
  1202. * and it must not be beyond the last of those groups.
  1203. * See ucol_setMaxVariable().
  1204. * @param coll the collator
  1205. * @param varTop one or more (if contraction) UChars to which the variable top should be set
  1206. * @param len length of variable top string. If -1 it is considered to be zero terminated.
  1207. * @param status error code. If error code is set, the return value is undefined.
  1208. * Errors set by this function are:<br>
  1209. * U_CE_NOT_FOUND_ERROR if more than one character was passed and there is no such contraction<br>
  1210. * U_ILLEGAL_ARGUMENT_ERROR if the variable top is beyond
  1211. * the last reordering group supported by ucol_setMaxVariable()
  1212. * @return variable top primary weight
  1213. * @see ucol_getVariableTop
  1214. * @see ucol_restoreVariableTop
  1215. * @deprecated ICU 53 Call ucol_setMaxVariable() instead.
  1216. */
  1217. U_DEPRECATED uint32_t U_EXPORT2
  1218. ucol_setVariableTop(UCollator *coll,
  1219. const UChar *varTop, int32_t len,
  1220. UErrorCode *status);
  1221. #endif /* U_HIDE_DEPRECATED_API */
  1222. /**
  1223. * Gets the variable top value of a Collator.
  1224. * @param coll collator which variable top needs to be retrieved
  1225. * @param status error code (not changed by function). If error code is set,
  1226. * the return value is undefined.
  1227. * @return the variable top primary weight
  1228. * @see ucol_getMaxVariable
  1229. * @see ucol_setVariableTop
  1230. * @see ucol_restoreVariableTop
  1231. * @stable ICU 2.0
  1232. */
  1233. U_CAPI uint32_t U_EXPORT2 ucol_getVariableTop(const UCollator *coll, UErrorCode *status);
  1234. #ifndef U_HIDE_DEPRECATED_API
  1235. /**
  1236. * Sets the variable top to the specified primary weight.
  1237. *
  1238. * Beginning with ICU 53, the variable top is pinned to
  1239. * the top of one of the supported reordering groups,
  1240. * and it must not be beyond the last of those groups.
  1241. * See ucol_setMaxVariable().
  1242. * @param coll collator to be set
  1243. * @param varTop primary weight, as returned by ucol_setVariableTop or ucol_getVariableTop
  1244. * @param status error code
  1245. * @see ucol_getVariableTop
  1246. * @see ucol_setVariableTop
  1247. * @deprecated ICU 53 Call ucol_setMaxVariable() instead.
  1248. */
  1249. U_DEPRECATED void U_EXPORT2
  1250. ucol_restoreVariableTop(UCollator *coll, const uint32_t varTop, UErrorCode *status);
  1251. #endif /* U_HIDE_DEPRECATED_API */
  1252. /**
  1253. * Thread safe cloning operation. The result is a clone of a given collator.
  1254. * @param coll collator to be cloned
  1255. * @param status to indicate whether the operation went on smoothly or there were errors
  1256. * @return pointer to the new clone
  1257. * @see ucol_open
  1258. * @see ucol_openRules
  1259. * @see ucol_close
  1260. * @stable ICU 71
  1261. */
  1262. U_CAPI UCollator* U_EXPORT2 ucol_clone(const UCollator *coll, UErrorCode *status);
  1263. #ifndef U_HIDE_DEPRECATED_API
  1264. /**
  1265. * Thread safe cloning operation. The result is a clone of a given collator.
  1266. * @param coll collator to be cloned
  1267. * @param stackBuffer <em>Deprecated functionality as of ICU 52, use NULL.</em><br>
  1268. * user allocated space for the new clone.
  1269. * If NULL new memory will be allocated.
  1270. * If buffer is not large enough, new memory will be allocated.
  1271. * Clients can use the U_COL_SAFECLONE_BUFFERSIZE.
  1272. * @param pBufferSize <em>Deprecated functionality as of ICU 52, use NULL or 1.</em><br>
  1273. * pointer to size of allocated space.
  1274. * If *pBufferSize == 0, a sufficient size for use in cloning will
  1275. * be returned ('pre-flighting')
  1276. * If *pBufferSize is not enough for a stack-based safe clone,
  1277. * new memory will be allocated.
  1278. * @param status to indicate whether the operation went on smoothly or there were errors
  1279. * An informational status value, U_SAFECLONE_ALLOCATED_ERROR, is used
  1280. * if pBufferSize != NULL and any allocations were necessary
  1281. * @return pointer to the new clone
  1282. * @see ucol_open
  1283. * @see ucol_openRules
  1284. * @see ucol_close
  1285. * @deprecated ICU 71 Use ucol_clone() instead.
  1286. */
  1287. U_DEPRECATED UCollator* U_EXPORT2
  1288. ucol_safeClone(const UCollator *coll,
  1289. void *stackBuffer,
  1290. int32_t *pBufferSize,
  1291. UErrorCode *status);
  1292. /** default memory size for the new clone.
  1293. * @deprecated ICU 52. Do not rely on ucol_safeClone() cloning into any provided buffer.
  1294. */
  1295. #define U_COL_SAFECLONE_BUFFERSIZE 1
  1296. #endif /* U_HIDE_DEPRECATED_API */
  1297. /**
  1298. * Returns current rules. Delta defines whether full rules are returned or just the tailoring.
  1299. * Returns number of UChars needed to store rules. If buffer is NULL or bufferLen is not enough
  1300. * to store rules, will store up to available space.
  1301. *
  1302. * ucol_getRules() should normally be used instead.
  1303. * See https://unicode-org.github.io/icu/userguide/collation/customization#building-on-existing-locales
  1304. * @param coll collator to get the rules from
  1305. * @param delta one of UCOL_TAILORING_ONLY, UCOL_FULL_RULES.
  1306. * @param buffer buffer to store the result in. If NULL, you'll get no rules.
  1307. * @param bufferLen length of buffer to store rules in. If less than needed you'll get only the part that fits in.
  1308. * @return current rules
  1309. * @stable ICU 2.0
  1310. * @see UCOL_FULL_RULES
  1311. */
  1312. U_CAPI int32_t U_EXPORT2
  1313. ucol_getRulesEx(const UCollator *coll, UColRuleOption delta, UChar *buffer, int32_t bufferLen);
  1314. #ifndef U_HIDE_DEPRECATED_API
  1315. /**
  1316. * gets the locale name of the collator. If the collator
  1317. * is instantiated from the rules, then this function returns
  1318. * NULL.
  1319. * @param coll The UCollator for which the locale is needed
  1320. * @param type You can choose between requested, valid and actual
  1321. * locale. For description see the definition of
  1322. * ULocDataLocaleType in uloc.h
  1323. * @param status error code of the operation
  1324. * @return real locale name from which the collation data comes.
  1325. * If the collator was instantiated from rules, returns
  1326. * NULL.
  1327. * @deprecated ICU 2.8 Use ucol_getLocaleByType instead
  1328. */
  1329. U_DEPRECATED const char * U_EXPORT2
  1330. ucol_getLocale(const UCollator *coll, ULocDataLocaleType type, UErrorCode *status);
  1331. #endif /* U_HIDE_DEPRECATED_API */
  1332. /**
  1333. * gets the locale name of the collator. If the collator
  1334. * is instantiated from the rules, then this function returns
  1335. * NULL.
  1336. * @param coll The UCollator for which the locale is needed
  1337. * @param type You can choose between requested, valid and actual
  1338. * locale. For description see the definition of
  1339. * ULocDataLocaleType in uloc.h
  1340. * @param status error code of the operation
  1341. * @return real locale name from which the collation data comes.
  1342. * If the collator was instantiated from rules, returns
  1343. * NULL.
  1344. * @stable ICU 2.8
  1345. */
  1346. U_CAPI const char * U_EXPORT2
  1347. ucol_getLocaleByType(const UCollator *coll, ULocDataLocaleType type, UErrorCode *status);
  1348. /**
  1349. * Get a Unicode set that contains all the characters and sequences tailored in
  1350. * this collator. The result must be disposed of by using uset_close.
  1351. * @param coll The UCollator for which we want to get tailored chars
  1352. * @param status error code of the operation
  1353. * @return a pointer to newly created USet. Must be be disposed by using uset_close
  1354. * @see ucol_openRules
  1355. * @see uset_close
  1356. * @stable ICU 2.4
  1357. */
  1358. U_CAPI USet * U_EXPORT2
  1359. ucol_getTailoredSet(const UCollator *coll, UErrorCode *status);
  1360. #ifndef U_HIDE_INTERNAL_API
  1361. /** Calculates the set of unsafe code points, given a collator.
  1362. * A character is unsafe if you could append any character and cause the ordering to alter significantly.
  1363. * Collation sorts in normalized order, so anything that rearranges in normalization can cause this.
  1364. * Thus if you have a character like a_umlaut, and you add a lower_dot to it,
  1365. * then it normalizes to a_lower_dot + umlaut, and sorts differently.
  1366. * @param coll Collator
  1367. * @param unsafe a fill-in set to receive the unsafe points
  1368. * @param status for catching errors
  1369. * @return number of elements in the set
  1370. * @internal ICU 3.0
  1371. */
  1372. U_CAPI int32_t U_EXPORT2
  1373. ucol_getUnsafeSet( const UCollator *coll,
  1374. USet *unsafe,
  1375. UErrorCode *status);
  1376. /** Touches all resources needed for instantiating a collator from a short string definition,
  1377. * thus filling up the cache.
  1378. * @param definition A short string containing a locale and a set of attributes.
  1379. * Attributes not explicitly mentioned are left at the default
  1380. * state for a locale.
  1381. * @param parseError if not NULL, structure that will get filled with error's pre
  1382. * and post context in case of error.
  1383. * @param forceDefaults if false, the settings that are the same as the collator
  1384. * default settings will not be applied (for example, setting
  1385. * French secondary on a French collator would not be executed).
  1386. * If true, all the settings will be applied regardless of the
  1387. * collator default value. If the definition
  1388. * strings are to be cached, should be set to false.
  1389. * @param status Error code. Apart from regular error conditions connected to
  1390. * instantiating collators (like out of memory or similar), this
  1391. * API will return an error if an invalid attribute or attribute/value
  1392. * combination is specified.
  1393. * @see ucol_openFromShortString
  1394. * @internal ICU 3.2.1
  1395. */
  1396. U_CAPI void U_EXPORT2
  1397. ucol_prepareShortStringOpen( const char *definition,
  1398. UBool forceDefaults,
  1399. UParseError *parseError,
  1400. UErrorCode *status);
  1401. #endif /* U_HIDE_INTERNAL_API */
  1402. /** Creates a binary image of a collator. This binary image can be stored and
  1403. * later used to instantiate a collator using ucol_openBinary.
  1404. * This API supports preflighting.
  1405. * @param coll Collator
  1406. * @param buffer a fill-in buffer to receive the binary image
  1407. * @param capacity capacity of the destination buffer
  1408. * @param status for catching errors
  1409. * @return size of the image
  1410. * @see ucol_openBinary
  1411. * @stable ICU 3.2
  1412. */
  1413. U_CAPI int32_t U_EXPORT2
  1414. ucol_cloneBinary(const UCollator *coll,
  1415. uint8_t *buffer, int32_t capacity,
  1416. UErrorCode *status);
  1417. /** Opens a collator from a collator binary image created using
  1418. * ucol_cloneBinary. Binary image used in instantiation of the
  1419. * collator remains owned by the user and should stay around for
  1420. * the lifetime of the collator. The API also takes a base collator
  1421. * which must be the root collator.
  1422. * @param bin binary image owned by the user and required through the
  1423. * lifetime of the collator
  1424. * @param length size of the image. If negative, the API will try to
  1425. * figure out the length of the image
  1426. * @param base Base collator, for lookup of untailored characters.
  1427. * Must be the root collator, must not be NULL.
  1428. * The base is required to be present through the lifetime of the collator.
  1429. * @param status for catching errors
  1430. * @return newly created collator
  1431. * @see ucol_cloneBinary
  1432. * @stable ICU 3.2
  1433. */
  1434. U_CAPI UCollator* U_EXPORT2
  1435. ucol_openBinary(const uint8_t *bin, int32_t length,
  1436. const UCollator *base,
  1437. UErrorCode *status);
  1438. #endif /* #if !UCONFIG_NO_COLLATION */
  1439. #endif