ucol.h 61 KB

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