ucol.h 61 KB

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