ucol.h 61 KB

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