ucol.h 62 KB

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