xref: /aosp_15_r20/external/cldr/docs/ldml/tr35-collation.md (revision 912701f9769bb47905792267661f0baf2b85bed5)
1## Unicode Technical Standard #35
2
3# Unicode Locale Data Markup Language (LDML)<br/>Part 5: Collation
4
5|Version|45              |
6|-------|----------------|
7|Editors|Markus Scherer (<a href="mailto:[email protected]">[email protected]</a>) and <a href="tr35.md#Acknowledgments">other CLDR committee members</a>|
8
9For the full header, summary, and status, see [Part 1: Core](tr35.md).
10
11### _Summary_
12
13This document describes parts of an XML format (_vocabulary_) for the exchange of structured locale data. This format is used in the [Unicode Common Locale Data Repository](https://www.unicode.org/cldr/).
14
15This is a partial document, describing only those parts of the LDML that are relevant for collation (sorting, searching & grouping). For the other parts of the LDML see the [main LDML document](tr35.md) and the links above.
16
17_Note:_
18Some links may lead to in-development or older
19versions of the data files.
20See <https://cldr.unicode.org> for up-to-date CLDR release data.
21
22### _Status_
23
24<!-- _This is a draft document which may be updated, replaced, or superseded by other documents at any time.
25Publication does not imply endorsement by the Unicode Consortium.
26This is not a stable document; it is inappropriate to cite this document as other than a work in progress._ -->
27
28_This document has been reviewed by Unicode members and other interested parties, and has been approved for publication by the Unicode Consortium.
29This is a stable document and may be used as reference material or cited as a normative reference by other specifications._
30
31> _**A Unicode Technical Standard (UTS)** is an independent specification. Conformance to the Unicode Standard does not imply conformance to any UTS._
32
33_Please submit corrigenda and other comments with the CLDR bug reporting form [[Bugs](tr35.md#Bugs)]. Related information that is useful in understanding this document is found in the [References](tr35.md#References). For the latest version of the Unicode Standard see [[Unicode](tr35.md#Unicode)]. For a list of current Unicode Technical Reports see [[Reports](tr35.md#Reports)]. For more information about versions of the Unicode Standard, see [[Versions](tr35.md#Versions)]._
34
35## <a name="Parts" href="#Parts">Parts</a>
36
37The LDML specification is divided into the following parts:
38
39*   Part 1: [Core](tr35.md#Contents) (languages, locales, basic structure)
40*   Part 2: [General](tr35-general.md#Contents) (display names & transforms, etc.)
41*   Part 3: [Numbers](tr35-numbers.md#Contents) (number & currency formatting)
42*   Part 4: [Dates](tr35-dates.md#Contents) (date, time, time zone formatting)
43*   Part 5: [Collation](tr35-collation.md#Contents) (sorting, searching, grouping)
44*   Part 6: [Supplemental](tr35-info.md#Contents) (supplemental data)
45*   Part 7: [Keyboards](tr35-keyboards.md#Contents) (keyboard mappings)
46*   Part 8: [Person Names](tr35-personNames.md#Contents) (person names)
47*   Part 9: [MessageFormat](tr35-messageFormat.md#Contents) (message format)
48
49## <a name="Contents" href="#Contents">Contents of Part 5, Collation</a>
50
51* [CLDR Collation](#CLDR_Collation)
52  * [CLDR Collation Algorithm](#CLDR_Collation_Algorithm)
53    * [U+FFFE](#Algorithm_FFFE)
54    * [Context-Sensitive Mappings](#Context_Sensitive_Mappings)
55    * [Case Handling](#Algorithm_Case)
56    * [Reordering Groups](#Algorithm_Reordering_Groups)
57    * [Combining Rules](#Combining_Rules)
58* [Root Collation](#Root_Collation)
59  * [Grouping classes of characters](#grouping_classes_of_characters)
60  * [Non-variable symbols](#non_variable_symbols)
61  * [Additional contractions for Tibetan](#tibetan_contractions)
62  * [Tailored noncharacter weights](#tailored_noncharacter_weights)
63  * [Root Collation Data Files](#Root_Data_Files)
64  * [Root Collation Data File Formats](#Root_Data_File_Formats)
65    * [allkeys_CLDR.txt](#File_Format_allkeys_CLDR_txt)
66    * [FractionalUCA.txt](#File_Format_FractionalUCA_txt)
67    * [UCA_Rules.txt](#File_Format_UCA_Rules_txt)
68* [Collation Tailorings](#Collation_Tailorings)
69  * [Collation Types](#Collation_Types)
70    * [Collation Type Fallback](#Collation_Type_Fallback)
71      * Table: [Sample requested and actual collation locales and types](#Sample_requested_and_actual_collation_locales_and_types)
72  * [Version](#Collation_Version)
73  * [Collation Element](#Collation_Element)
74  * [Setting Options](#Setting_Options)
75    * Table: [Collation Settings](#Collation_Settings)
76    * [Common settings combinations](#Common_Settings)
77    * [Notes on the normalization setting](#Normalization_Setting)
78    * [Notes on variable top settings](#Variable_Top_Settings)
79  * [Collation Rule Syntax](#Rules)
80  * [Orderings](#Orderings)
81    * Table: [Specifying Collation Ordering](#Specifying_Collation_Ordering)
82    * Table: [Abbreviating Ordering Specifications](#Abbreviating_Ordering_Specifications)
83  * [Contractions](#Contractions)
84    * Table: [Specifying Contractions](#Specifying_Contractions)
85  * [Expansions](#Expansions)
86  * [Context Before](#Context_Before)
87    * Table: [Specifying Previous Context](#Specifying_Previous_Context)
88  * [Placing Characters Before Others](#Placing_Characters_Before_Others)
89  * [Logical Reset Positions](#Logical_Reset_Positions)
90    * Table: [Specifying Logical Positions](#Specifying_Logical_Positions)
91  * [Special-Purpose Commands](#Special_Purpose_Commands)
92    * Table: [Special-Purpose Elements](#Special_Purpose_Elements)
93  * [Collation Reordering](#Script_Reordering)
94    * [Interpretation of a reordering list](#Interpretation_reordering)
95    * [Reordering Groups for allkeys.txt](#Reordering_Groups_allkeys)
96  * [Case Parameters](#Case_Parameters)
97    * [Untailored Characters](#Case_Untailored)
98    * [Compute Modified Collation Elements](#Case_Weights)
99    * [Tailored Strings](#Case_Tailored)
100  * [Visibility](#Visibility)
101  * [Collation Indexes](#Collation_Indexes)
102    * [Index Characters](#Index_Characters)
103    * [CJK Index Markers](#CJK_Index_Markers)
104
105## <a name="CLDR_Collation" href="#CLDR_Collation">CLDR Collation</a>
106
107Collation is the general term for the process and function of determining the sorting order of strings of characters, for example for lists of strings presented to users, or in databases for sorting and selecting records.
108
109Collation varies by language, by application (some languages use special phonebook sorting), and other criteria (for example, phonetic vs. visual).
110
111CLDR provides collation data for many languages and styles. The data supports not only sorting but also language-sensitive searching and grouping under index headers. All CLDR collations are based on the [[UCA](https://www.unicode.org/reports/tr41/#UTS10)] default order, with common modifications applied in the CLDR root collation, and further tailored for language and style as needed.
112
113### <a name="CLDR_Collation_Algorithm" href="#CLDR_Collation_Algorithm">CLDR Collation Algorithm</a>
114
115The CLDR collation algorithm is an extension of the [Unicode Collation Algorithm](https://www.unicode.org/reports/tr10/#Main_Algorithm).
116
117#### <a name="Algorithm_FFFE" href="#Algorithm_FFFE">U+FFFE</a>
118
119U+FFFE maps to a CE with a minimal, unique primary weight. Its primary weight is not "variable": U+FFFE must not become ignorable in alternate handling. On the identical level, a minimal, unique “weight” must be emitted for U+FFFE as well. This allows for [Merging Sort Keys](https://www.unicode.org/reports/tr10/#Merging_Sort_Keys) within code point space.
120
121For example, when sorting names in a database, a sortable string can be formed with _last_name_ + '\\uFFFE' + _first_name_. These strings would sort properly, without ever comparing the last part of a last name with the first part of another first name.
122
123For backwards secondary level sorting, text _segments_ separated by U+FFFE are processed in forward segment order, and _within_ each segment the secondary weights are compared backwards. This is so that such combined strings are processed consistently with merging their sort keys (for example, by concatenating them level by level with a low separator).
124
125> �� **Note**: With unique, low weights on _all_ levels it is possible to achieve `sortkey(str1 + "\uFFFE" + str2) == mergeSortkeys(sortkey(str1), sortkey(str2))` . When that is not necessary, then code can be a little simpler (no special handling for U+FFFE except for backwards-secondary), sort keys can be a little shorter (when using compressible common non-primary weights for U+FFFE), and another low weight can be used in tailorings.
126
127#### <a name="Context_Sensitive_Mappings" href="#Context_Sensitive_Mappings">Context-Sensitive Mappings</a>
128
129Contraction matching, as in the UCA, starts from the first character of the contraction string. It slows down processing of that first character even when none of its contractions matches. In some cases, it is preferrable to change such contractions to mappings with a prefix (context before a character), so that complex processing is done only when the less-frequently occurring trailing character is encountered.
130
131For example, the DUCET contains contractions for several variants of L· (L followed by middle dot). Collating ASCII text is slowed down by contraction matching starting with L/l. In the CLDR root collation, these contractions are replaced by prefix mappings (L|·) which are triggered only when the middle dot is encountered. CLDR also uses prefix rules in the Japanese tailoring, for processing of Hiragana/Katakana length and iteration marks.
132
133The mapping is conditional on the prefix match but does not change the mappings for the preceding text. As a result, a contraction mapping for "px" can be replaced by a prefix rule "p|x" only if px maps to the collation elements for p followed by the collation elements for "x if after p". In the DUCET, L· maps to CE(L) followed by a special secondary CE (which differs from CE(·) when · is not preceded by L). In the CLDR root collation, L has no context-sensitive mappings, but · maps to that special secondary CE if preceded by L.
134
135A prefix mapping for p|x behaves mostly like the contraction px, except when there is a contraction that overlaps with the prefix, for example one for "op". A contraction matches only new text (and consumes it), while a prefix matches only already-consumed text.
136
137*   With mappings for "op" and "px", only the first contraction matches in text "opx". (It consumes the "op" characters, and there is no context-sensitive mapping for x.)
138*   With mappings for "op" and "p|x", both the contraction and the prefix rule match in text "opx". (The prefix always matches already-consumed characters, regardless of whether they mapped as part of contractions.)
139
140> �� **Note**: Matching of discontiguous contractions should be implemented without rewriting the text (unlike in the [[UCA](https://www.unicode.org/reports/tr41/#UTS10)] algorithm specification), so that prefix matching is predictable. (It should also help with contraction matching performance.) An implementation that does rewrite the text, as in the UCA, will get different results for some (unusual) combinations of contractions, prefix rules, and input text.
141
142Prefix matching uses a simple longest-match algorithm (op|c wins over p|c). It is recommended that prefix rules be limited to mappings where both the prefix string and the mapped string begin with an NFC boundary (that is, with a normalization starter that does not combine backwards). (In op|ch both o and c should be starters (ccc=0) and NFC_QC=Yes.) Otherwise, prefix matching would be affected by canonical reordering and discontiguous matching, like contractions. Prefix matching is thus always contiguous.
143
144A character can have mappings with both prefixes (context before) and contraction suffixes. Prefixes are matched first. This is to keep them reasonably implementable: When there is a mapping with both a prefix and a contraction suffix (like in Japanese: ぐ|ゞ), then the matching needs to go in both directions. The contraction might involve discontiguous matching, which needs complex text iteration and handling of skipped combining marks, and will consume the matching suffix. Prefix matching should be first because, regardless of whether there is a match, the implementation will always return to the original text index (right after the prefix) from where it will start to look at all of the contractions for that prefix.
145
146If there is a match for a prefix but no match for any of the suffixes for that prefix, then fall back to mappings with the next-longest matching prefix, and so on, ultimately to mappings with no prefix. (Otherwise mappings with longer prefixes would “hide” mappings with shorter prefixes.)
147
148Consider the following mappings.
149
1501. p → CE(p)
1512. h → CE(h)
1523. c → CE(c)
1534. ch → CE(d)
1545. p|c → CE(u)
1556. p|ci → CE(v)
1567. p|ĉ → CE(w)
1578. op|ck → CE(x)
158
159With these, text collates like this:
160
161* pc → CE(p)CE(u)
162* pci → CE(p)CE(v)
163* pch → CE(p)CE(u)CE(h)
164* pĉ → CE(p)CE(w)
165* pĉ̣ → CE(p)CE(w)CE(U+0323) // discontiguous
166* opck → CE(o)CE(p)CE(x)
167* opch → CE(o)CE(p)CE(u)CE(h)
168
169However, if the mapping p|c → CE(u) is missing, then text "pch" maps to CE(p)CE(d), "opch" maps to CE(o)CE(p)CE(d), and "pĉ̣" maps to CE(p)CE(c)CE(U+0323)CE(U+0302) (because discontiguous contraction matching extends _an existing match_ by one non-starter at a time).
170
171#### <a name="Algorithm_Case" href="#Algorithm_Case">Case Handling</a>
172
173CLDR specifies how to sort lowercase or uppercase first, as a stronger distinction than other tertiary variants (**caseFirst**) or while completely ignoring all other tertiary distinctions (**caseLevel**). See _[Setting Options](#Setting_Options)_ and _[Case Parameters](#Case_Parameters)_.
174
175#### <a name="Algorithm_Reordering_Groups" href="#Algorithm_Reordering_Groups">Reordering Groups</a>
176
177CLDR specifies how to do parametric reordering of groups of scripts (e.g., “native script first”) as well as special groups (e.g., “digits after letters”), and provides data for the effective implementation of such reordering.
178
179#### <a name="Combining_Rules" href="#Combining_Rules">Combining Rules</a>
180
181Rules from different sources can be combined, with the later rules overriding the earlier ones. The following is an example of how this can be useful.
182
183There is a root collation for "emoji" in CLDR. So use of "-u-co-emoji" in a Unicode locale identifier will access that ordering.
184
185Example, using ICU:
186
187```java
188collator = Collator.getInstance(ULocale.forLanguageTag("en-u-co-emoji"));
189```
190
191However, use of the emoji will supplant the language's customizations. So the above is the equivalent of:
192
193```java
194collator = Collator.getInstance(ULocale.forLanguageTag("und-u-co-emoji"));
195```
196
197The same structure will not work for a language that does require customization, like Danish. That is, the following will fail.
198
199```java
200collator = Collator.getInstance(ULocale.forLanguageTag("da-u-co-emoji"));
201```
202
203For that, a slightly more cumbersome method needs to be employed, which is to take the rules for Danish, and explicitly add the rules for emoji.
204
205```java
206RuleBasedCollator collator = new RuleBasedCollator(
207((RuleBasedCollator) Collator.getInstance(ULocale.forLanguageTag("da"))).getRules() +
208((RuleBasedCollator) Collator.getInstance(ULocale.forLanguageTag("und-u-co-emoji")))
209.getRules());
210```
211
212The following table shows the differences. When emoji ordering is supported, the two faces will be adjacent. When Danish ordering is supported, the ü is after the y.
213
214<!-- HTML: no header row, jagged -->
215<table><tbody>
216<tr><td>code point order</td><td>,</td><td>Z</td><td>a</td><td>y</td><td>ü</td><td>☹️</td><td>✈️️</td><td>글</td><td>��</td></tr>
217<tr><td>en</td><td>,</td><td>☹️</td><td>✈️️</td><td>��</td><td>a</td><td>ü</td><td>y</td><td>Z</td><td>글</td></tr>
218<tr><td>en-u-co-emoji</td><td>,</td><td>��</td><td>☹️</td><td>✈️️</td><td>a</td><td>ü</td><td>y</td><td>Z</td><td>글</td></tr>
219<tr><td>da</td><td>,</td><td>☹️</td><td>✈️️</td><td>��</td><td>a</td><td>y</td><td><strong><u>ü</u></strong></td><td>Z</td><td>글</td></tr>
220<tr><td>da-u-co-emoji</td><td>,</td><td>��</td><td>☹️</td><td>✈️️</td><td>a</td><td><strong><u>ü</u></strong></td><td>y</td><td>Z</td><td>글</td></tr>
221<tr><td>combined rules</td><td>,</td><td>��</td><td>☹️</td><td>✈️️</td><td>a</td><td>y</td><td><strong><u>ü</u></strong></td><td>Z</td><td>글</td></tr>
222</tbody></table>
223
224## <a name="Root_Collation" href="#Root_Collation">Root Collation</a>
225
226The CLDR root collation order is based on the [Default Unicode Collation Element Table (DUCET)](https://www.unicode.org/reports/tr10/#Default_Unicode_Collation_Element_Table) defined in _UTS #10: Unicode Collation Algorithm_ [[UCA](https://www.unicode.org/reports/tr41/#UTS10)]. It is used by all other locales by default, or as the base for their tailorings. (For a chart view of the UCA, see Collation Chart [[UCAChart](tr35.md#UCAChart)].)
227
228Starting with CLDR 1.9, CLDR uses modified tables for the root collation order. The root locale ordering is tailored in the following ways:
229
230### <a name="grouping_classes_of_characters" href="#grouping_classes_of_characters">Grouping classes of characters</a>
231
232As of Version 6.1.0, the DUCET puts characters into the following ordering:
233
234* First "common characters": whitespace, punctuation, general symbols, some numbers, currency symbols, and other numbers.
235* Then "script characters": Latin, Greek, and the rest of the scripts.
236
237(There are a few exceptions to this general ordering.)
238
239The CLDR root locale modifies the DUCET tailoring by ordering the common characters more strictly by category:
240
241* whitespace, punctuation, general symbols, currency symbols, and numbers.
242
243What the regrouping allows is for users to parametrically reorder the groups. For example, users can reorder numbers after all scripts, or reorder Greek before Latin.
244
245The relative order within each of these groups still matches the DUCET. Symbols, punctuation, and numbers that are grouped with a particular script stay with that script. The differences between CLDR and the DUCET order are:
246
2471. CLDR groups the numbers together after currency symbols, instead of splitting them with some before and some after. Thus the following are put _after_ currencies and just before all the other numbers.
248
249    U+09F4 ( ৴ ) [No] BENGALI CURRENCY NUMERATOR ONE
250    ...
251    U+1D371 ( �� ) [No] COUNTING ROD TENS DIGIT NINE
252
2532. CLDR handles a few other characters differently
254   1. U+10A7F ( �� ) [Po] OLD SOUTH ARABIAN NUMERIC INDICATOR is put with punctuation, not symbols
255   2. U+20A8 ( ₨ ) [Sc] RUPEE SIGN and U+FDFC ( ﷼ ) [Sc] RIAL SIGN are put with currency signs, not with R and REH.
256
257### <a name="non_variable_symbols" href="#non_variable_symbols">Non-variable symbols</a>
258
259There are multiple [Variable-Weighting](https://www.unicode.org/reports/tr10/#Variable_Weighting) options in the UCA for symbols and punctuation, including _non-ignorable_ and _shifted_. With the _shifted_ option, almost all symbols and punctuation are ignored—except at a fourth level. The CLDR root locale ordering is modified so that symbols are not affected by the _shifted_ option. That is, by default, symbols are not “variable” in CLDR. So _shifted_ only causes whitespace and punctuation to be ignored, but not symbols (like ♥). The DUCET behavior can be specified with a locale ID using the "kv" keyword, to set the Variable section to include all of the symbols below it, or be set parametrically where implementations allow access.
260
261See also:
262
263* _[Setting Options](#Setting_Options)_
264* [https://www.unicode.org/charts/collation/](https://www.unicode.org/charts/collation/)
265
266### <a name="tibetan_contractions" href="#tibetan_contractions">Additional contractions for Tibetan</a>
267
268Ten contractions are added for Tibetan: Two to fulfill [well-formedness condition 5](https://www.unicode.org/reports/tr10/#WF5), and eight more to preserve the default order for Tibetan. For details see _UTS #10, Section 3.8.2, [Well-Formedness of the DUCET](https://www.unicode.org/reports/tr10/#Well_Formed_DUCET)_.
269
270### <a name="tailored_noncharacter_weights" href="#tailored_noncharacter_weights">Tailored noncharacter weights</a>
271
272U+FFFE and U+FFFF have special tailorings:
273
274> **U+FFFF:** This code point is tailored to have a primary weight higher than all other characters. This allows the reliable specification of a range, such as “Sch” ≤ X ≤ “Sch\\uFFFF”, to include all strings starting with "sch" or equivalent.
275>
276> **U+FFFE:** This code point produces a CE with minimal, unique weights on primary and identical levels. For details see the _[CLDR Collation Algorithm](#Algorithm_FFFE)_ above.
277
278UCA (beginning with version 6.3) also maps **U+FFFD** to a special collation element with a very high primary weight, so that it is reliably non-[variable](https://www.unicode.org/reports/tr10/#Variable_Weighting), for use with [ill-formed code unit sequences](https://www.unicode.org/reports/tr10/#Handling_Illformed).
279
280In CLDR, so as to maintain the special collation elements, **U+FFFD..U+FFFF** are not further tailorable, and nothing can tailor to them. That is, neither can occur in a collation rule. For example, the following rules are illegal:
281
282```
283&\uFFFF < x
284```
285
286```
287&x <\uFFFF
288```
289
290> �� **Note**: Java uses an early version of this collation syntax, but has not been updated recently. It does not support any of the syntax marked with [...], and its default table is not the DUCET nor the CLDR root collation.
291
292### <a name="Root_Data_Files" href="#Root_Data_Files">Root Collation Data Files</a>
293
294The CLDR root collation data files are in the CLDR repository and release, under the path [common/uca/](https://github.com/unicode-org/cldr/blob/main/common/uca/).
295
296For most data files there are **\_SHORT** versions available. They contain the same data but only minimal comments, to reduce the file sizes.
297
298Comments with DUCET-style weights in files other than allkeys_CLDR.txt and allkeys_DUCET.txt use the weights defined in allkeys_CLDR.txt.
299
300* **allkeys_CLDR** - A file that provides a remapping of UCA DUCET weights for use with CLDR.
301* **allkeys_DUCET** - The same as DUCET allkeys.txt, but in alternate=non-ignorable sort order, for easier comparison with allkeys_CLDR.txt.
302* **FractionalUCA** - A file that provides a remapping of UCA DUCET weights for use with CLDR. The weight values are modified:
303  * The weights have variable length, with 1..4 bytes each. Each secondary or tertiary weight currently uses at most 2 bytes.
304  * There are tailoring gaps between adjacent weights, so that a number of characters can be tailored to sort between any two root collation elements.
305  * There are collation elements with primary weights at the boundaries between reordering groups and Unicode scripts, so that tailoring around the first or last primary of a group/script results in new collation elements that sort and reorder together with that group or script. These boundary weights also define the primary weight ranges for parametric group and script reordering.
306
307  An implementation may modify the weights further to fit the needs of its data structures.
308
309* **UCA_Rules** - A file that specifies the root collation order in the form of [tailoring rules](#Collation_Tailorings). This is only an approximation of the FractionalUCA data, since the rule syntax cannot express every detail of the collation elements. For example, in the DUCET and in FractionalUCA, tertiary differences are usually expressed with special tertiary weights on all collation elements of an expansion, while a typical from-rules builder will modify the tertiary weight of only one of the collation elements.
310* **CollationTest_CLDR** - The CLDR versions of the CollationTest files, which use the tailorings for CLDR. For information on the format, see [CollationTest.html](https://www.unicode.org/Public/UCA/latest/CollationTest.html) in the [UCA data directory](https://www.unicode.org/reports/tr10/#Data10).
311  * CollationTest_CLDR_NON_IGNORABLE.txt
312  * CollationTest_CLDR_SHIFTED.txt
313
314### <a name="Root_Data_File_Formats" href="#Root_Data_File_Formats">Root Collation Data File Formats</a>
315
316The file formats may change between versions of CLDR. The formats for CLDR 23 and beyond are as follows. As usual, text after a # is a comment.
317
318#### <a name="File_Format_allkeys_CLDR_txt" href="#File_Format_allkeys_CLDR_txt">allkeys_CLDR.txt</a>
319
320This file defines CLDR’s tailoring of the DUCET, as described in _[Root Collation](#Root_Collation)_ .
321
322The format is similar to that of [allkeys.txt](https://www.unicode.org/reports/tr10/#File_Format), although there may be some differences in whitespace.
323
324#### <a name="File_Format_FractionalUCA_txt" href="#File_Format_FractionalUCA_txt">FractionalUCA.txt</a>
325
326The format is illustrated by the following sample lines, with commentary afterwards.
327
328```
329[UCA version = 6.0.0]
330```
331
332Provides the version number of the UCA table.
333
334```
335[Unified_Ideograph 4E00..9FCC FA0E..FA0F FA11 FA13..FA14 FA1F FA21 FA23..FA24 FA27..FA29 3400..4DB5 20000..2A6D6 2A700..2B734 2B740..2B81D]
336```
337
338Lists the ranges of Unified_Ideograph characters in collation order. (New in CLDR 24.) They map to collation elements with [implicit (constructed) primary weights](https://www.unicode.org/reports/tr10/#Implicit_Weights).
339
340```
341[radical 6=⼅亅:亅��了��-��亇��予㐧��-��争����亊��-����事㐨��-��������]
342[radical 210=⿑齊:齊����齋䶒䶓��齌������齍��-��齎����齏��-��]
343[radical 210'=⻬齐:齐齑]
344[radical end]
345```
346
347Data for Unihan radical-stroke order. (New in CLDR 26.) Following the [Unified_Ideograph] line, a section of `[radical ...]` lines defines a radical-stroke order of the Unified_Ideograph characters.
348
349For Han characters, an implementation may choose either to implement the order defined in the UCA and the [Unified_Ideograph] data, or to implement the order defined by the `[radical ...]` lines. Beginning with CLDR 26, the CJK type="unihan" tailorings assume that the root collation order sorts Han characters in Unihan radical-stroke order according to the `[radical ...]` data. The CollationTest_CLDR files only contain Han characters that are in the same relative order using implicit weights or the radical-stroke order.
350
351The root collation radical-stroke order is derived from the first (normative) values of the [Unihan kRSUnicode](https://www.unicode.org/reports/tr38/#kRSUnicode) field for each Han character. Han characters are ordered by radical, with traditional forms sorting before simplified ones. Characters with the same radical are ordered by residual stroke count. Characters with the same radical-stroke values are ordered by block and code point, as for [UCA implicit weights](https://www.unicode.org/reports/tr10/#Implicit_Weights).
352
353There is one `[radical ...]` line per radical, in the order of radical numbers. Each line shows the radical number and the representative characters from the [UCD file CJKRadicals.txt](https://www.unicode.org/reports/tr44/#UCD_Files_Table), followed by a colon (“:”) and the Han characters with that radical in the order as described above. A range like `万-丌` indicates that the code points in that range sort in code point order.
354
355The radical number and characters are informational. The sort order is established only by the order of the `[radical ...]` lines, and within each line by the characters and ranges between the colon (“:”) and the bracket (“]”).
356
357Each Unified_Ideograph occurs exactly once. Only Unified_Ideograph characters are listed on `[radical ...]` lines.
358
359This section is terminated with one `[radical end]` line.
360
361```
3620000; [,,]     # Zyyy Cc       [0000.0000.0000]        * <NULL>
363```
364
365Provides a weight line. The first element (before the ";") is a hex codepoint sequence. The second field is a sequence of collation elements. Each collation element has 3 parts separated by commas: the primary weight, secondary weight, and tertiary weight. The tertiary weight actually consists of two components: the top two bits (0xC0) are used for the _case level_, and should be masked off where a case level is not used.
366
367A weight is either empty (meaning a zero or ignorable weight) or is a sequence of one or more bytes. The bytes are interpreted as a "fraction", meaning that the ordering is 04 < 05 05 < 06. The weights are constructed so that no weight is an initial subsequence of another: that is, having both the weights 05 and 05 05 is illegal. The above line consists of all ignorable weights.
368
369The vertical bar (“|”) character is used to indicate context, as in:
370
371```
372006C | 00B7; [, DB A9, 05]
373```
374
375This example indicates that if U+00B7 appears immediately after U+006C, it is given the corresponding collation element instead. This syntax is roughly equivalent to the following contraction, but is more efficient. For details see the specification of _[Context-Sensitive Mappings](#Context_Sensitive_Mappings)_ above.
376
377```
378006C 00B7; CE(006C) [, DB A9, 05]
379```
380
381Single-byte primary weights are given to particularly frequent characters, such as space, digits, and a-z. More frequent characters are given two-byte weights, while relatively infrequent characters are given three-byte weights. For example:
382
383```
384...
3850009; [03 05, 05, 05] # Zyyy Cc       [0100.0020.0002]        * <CHARACTER TABULATION>
386...
3871B60; [06 14 0C, 05, 05]    # Bali Po       [0111.0020.0002]        * BALINESE PAMENENG
388...
3890031; [14, 05, 05]    # Zyyy Nd       [149B.0020.0002]        * DIGIT ONE
390```
391
392The assignment of 2 vs 3 bytes does not reflect importance, or exact frequency.
393
394```
3953041; [76 06, 05, 03]   # Hira Lo       [3888.0020.000D]        * HIRAGANA LETTER SMALL A
3963042; [76 06, 05, 85]   # Hira Lo       [3888.0020.000E]        * HIRAGANA LETTER A
39730A1; [76 06, 05, 10]   # Kana Lo       [3888.0020.000F]        * KATAKANA LETTER SMALL A
39830A2; [76 06, 05, 9E]   # Kana Lo       [3888.0020.0011]        * KATAKANA LETTER A
399```
400
401Beginning with CLDR 27, some primary or secondary collation elements may have below-common tertiary weights (e.g., `03` ), in particular to allow normal Hiragana letters to have common tertiary weights.
402
403```
404# SPECIAL MAX/MIN COLLATION ELEMENTS
405FFFE; [02, 05, 05]     # Special LOWEST primary, for merge/interleaving
406FFFF; [EF FE, 05, 05]  # Special HIGHEST primary, for ranges
407```
408
409The two tailored noncharacters have their own primary weights.
410
411```
412F967; [U+4E0D]  # Hani Lo       [FB40.0020.0002][CE0D.0000.0000]        * CJK COMPATIBILITY IDEOGRAPH-F967
4132F02; [U+4E36, 10]      # Hani So       [FB40.0020.0004][CE36.0000.0000]        * KANGXI RADICAL DOT
4142E80; [U+4E36, 70, 20]  # Hani So       [FB40.0020.0004][CE36.0000.0000][0000.00FC.0004]        * CJK RADICAL REPEAT
415```
416
417Some collation elements are specified by reference to other mappings. This is particularly useful for Han characters which are given implicit/constructed primary weights; the reference to a Unified_Ideograph makes these mappings independent of implementation details. This technique may also be used in other mappings to show the relationship of character variants.
418
419The referenced character must have a mapping listed earlier in the file, or the mapping must have been defined via the [Unified_Ideograph] data line. The referenced character must map to exactly one collation element.
420
421`[U+4E0D]` copies U+4E0D’s entire collation element. `[U+4E36, 10]` copies U+4E36’s primary and secondary weights and specifies a different tertiary weight. `[U+4E36, 70, 20]` only copies U+4E36’s primary weight and specifies other secondary and tertiary weights.
422
423FractionalUCA.txt does not have any explicit mappings for implicit weights. Therefore, an implementation is free to choose an algorithm for computing implicit weights according to the principles specified in the UCA.
424
425```
426FDD1 20AC;      [0D 20 02, 05, 05]      # CURRENCY first primary
427FDD1 0034;      [0E 02 02, 05, 05]      # DIGIT first primary starts new lead byte
428FDD0 FF21;      [26 02 02, 05, 05]      # REORDER_RESERVED_BEFORE_LATIN first primary starts new lead byte
429FDD1 004C;      [28 02 02, 05, 05]      # LATIN first primary starts new lead byte
430FDD0 FF3A;      [5D 02 02, 05, 05]      # REORDER_RESERVED_AFTER_LATIN first primary starts new lead byte
431FDD1 03A9;      [5F 04 02, 05, 05]      # GREEK first primary starts new lead byte (compressible)
432FDD1 03E2;      [5F 60 02, 05, 05]      # COPTIC first primary (compressible)
433```
434
435These are special mappings with primaries at the boundaries of scripts and reordering groups. They serve as tailoring boundaries, so that tailoring near the first or last character of a script or group places the tailored item into the same group. Beginning with CLDR 24, each of these is a contraction of U+FDD1 with a character of the corresponding script (or of the General_Category [Z, P, S, Sc, Nd] corresponding to a special reordering group), mapping to the first possible primary weight per script or group. They can be enumerated for implementations of [Collation Indexes](#Collation_Indexes). (Earlier versions mapped contractions with U+FDD0 to the last primary weights of each group but not each script.)
436
437Beginning with CLDR 27, these mappings alone define the boundaries for reordering single scripts. (There are no mappings for Hrkt, Hans, or Hant because they are not fully distinct scripts; they share primary weights with other scripts: Hrkt=Hira=Kana & Hans=Hant=Hani.) There are some reserved ranges, beginning at boundaries marked with U+FDD0 plus following characters as shown above. The reserved ranges are not used for collation elements and are not available for tailoring.
438
439Some primary lead bytes must be reserved so that reordering of scripts along partial-lead-byte boundaries can “split” the primary lead byte and use up a reserved byte. This is for implementations that write sort keys, which must reorder primary weights by offsetting them by whole lead bytes. There are reorder-reserved ranges before and after Latin, so that reordering scripts with few primary lead bytes relative to Latin can move those scripts into the reserved ranges without changing the primary weights of any other script. Each of these boundaries begins with a new two-byte primary; that is, no two groups/scripts/ranges share the top 16 bits of their primary weights.
440
441```
442FDD0 0034;      [11, 05, 05]    # lead byte for numeric sorting
443```
444
445This mapping specifies the lead byte for numeric sorting. It must be different from the lead byte of any other primary weight, otherwise numeric sorting would generate ill-formed collation elements. Therefore, this mapping itself must be excluded from the set of regular mappings. This value can be ignored by implementations that do not support numeric sorting. (Other contractions with U+FDD0 can normally be ignored altogether.)
446
447```
448# HOMELESS COLLATION ELEMENTS
449FDD0 0063; [, 97, 3D]       # [15E4.0020.0004] [1844.0020.0004] [0000.0041.001F]    * U+01C6 LATIN SMALL LETTER DZ WITH CARON
450FDD0 0064; [, A7, 09]       # [15D1.0020.0004] [0000.0056.0004]     * U+1DD7 COMBINING LATIN SMALL LETTER C CEDILLA
451FDD0 0065; [, B1, 09]       # [1644.0020.0004] [0000.0061.0004]     * U+A7A1 LATIN SMALL LETTER G WITH OBLIQUE STROKE
452```
453
454The DUCET has some weights that don't correspond directly to a character. To allow for implementations to have a mapping for each collation element (necessary for certain implementations of tailoring), this requires the construction of special sequences for those weights. These collation elements can normally be ignored.
455
456Next, a number of tables are defined. The function of each of the tables is summarized afterwards.
457
458```
459# VALUES BASED ON UCA
460...
461[first regular [0D 0A, 05, 05]] # U+0060 GRAVE ACCENT
462[last regular [7A FE, 05, 05]] # U+1342E EGYPTIAN HIEROGLYPH AA032
463[first implicit [E0 04 06, 05, 05]] # CONSTRUCTED
464[last implicit [E4 DF 7E 20, 05, 05]] # CONSTRUCTED
465[first trailing [E5, 05, 05]] # CONSTRUCTED
466[last trailing [E5, 05, 05]] # CONSTRUCTED
467...
468```
469
470This table summarizes ranges of important groups of characters for implementations.
471
472```
473# Top Byte => Reordering Tokens
474[top_byte     00      TERMINATOR ]    #       [0]     TERMINATOR=1
475[top_byte     01      LEVEL-SEPARATOR ]       #       [0]     LEVEL-SEPARATOR=1
476[top_byte     02      FIELD-SEPARATOR ]       #       [0]     FIELD-SEPARATOR=1
477[top_byte     03      SPACE ] #       [9]     SPACE=1 Cc=6 Zl=1 Zp=1 Zs=1
478...
479```
480
481This table defines the reordering groups, for script reordering. The table maps from the first bytes of the fractional weights to a reordering token. The format is "[top_byte " byte-value reordering-token "COMPRESS"? "]". The "COMPRESS" value is present when there is only one byte in the reordering token, and primary-weight compression can be applied. Most reordering tokens are script values; others are special-purpose values, such as PUNCTUATION. Beginning with CLDR 24, this table precedes the regular mappings, so that parsers can use this information while processing and optimizing mappings. Beginning with CLDR 27, most of this data is irrelevant because single scripts can be reordered. Only the "COMPRESS" data is still useful.
482
483```
484# Reordering Tokens => Top Bytes
485[reorderingTokens     Arab    61=910 62=910 ]
486[reorderingTokens     Armi    7A=22 ]
487[reorderingTokens     Armn    5F=82 ]
488[reorderingTokens     Avst    7A=54 ]
489...
490```
491
492This table is an inverse mapping from reordering token to top byte(s). In terms like "61=910", the first value is the top byte, while the second is informational, indicating the number of primaries assigned with that top byte.
493
494```
495# General Categories => Top Byte
496[categories   Cc      03{SPACE}=6 ]
497[categories   Cf      77{Khmr Tale Talu Lana Cham Bali Java Mong Olck Cher Cans Ogam Runr Orkh Vaii Bamu}=2 ]
498[categories   Lm      0D{SYMBOL}=25 0E{SYMBOL}=22 27{Latn}=12 28{Latn}=12 29{Latn}=12 2A{Latn}=12...
499```
500
501This table is informational, providing the top bytes, scripts, and primaries associated with each general category value.
502
503```
504# FIXED VALUES
505[fixed first implicit byte E0]
506[fixed last implicit byte E4]
507[fixed first trail byte E5]
508[fixed last trail byte EF]
509[fixed first special byte F0]
510[fixed last special byte FF]
511
512[fixed secondary common byte 05]
513[fixed last secondary common byte 45]
514[fixed first ignorable secondary byte 80]
515
516[fixed tertiary common byte 05]
517[fixed first ignorable tertiary byte 3C]
518```
519
520The final table gives certain hard-coded byte values. The "trail" area is provided for implementation of the "trailing weights" as described in the UCA.
521
522> �� **Note**: The particular primary lead bytes for Hani vs. IMPLICIT vs. TRAILING are only an example. An implementation is free to move them if it also moves the explicit TRAILING weights. This affects only a small number of explicit mappings in FractionalUCA.txt, such as for U+FFFD, U+FFFF, and the “unassigned first primary”. It is possible to use no SPECIAL bytes at all, and to use only the one primary lead byte FF for TRAILING weights.
523
524#### <a name="File_Format_UCA_Rules_txt" href="#File_Format_UCA_Rules_txt">UCA_Rules.txt</a>
525
526The format for this file uses the CLDR collation syntax, see _[Collation Tailorings](#Collation_Tailorings)_.
527
528## <a name="Collation_Tailorings" href="#Collation_Tailorings">Collation Tailorings</a>
529
530```xml
531<!ELEMENT collations (alias | (defaultCollation?, collation*, special*)) >
532
533<!ELEMENT defaultCollation ( #PCDATA ) >
534```
535
536This element of the LDML format contains one or more `collation` elements, distinguished by type. Each `collation` contains elements with parametric settings, or rules that specify a certain sort order, as a tailoring of the root order, or both.
537
538> �� **Note**: CLDR collation tailoring data should follow the [CLDR Collation Guidelines](https://cldr.unicode.org/index/cldr-spec/collation-guidelines).
539
540### <a name="Collation_Types" href="#Collation_Types">Collation Types</a>
541
542Each locale may have multiple sort orders (types). The `defaultCollation` element defines the default tailoring for a locale and its sublocales. For example:
543
544* root.xml: `<defaultCollation>standard</defaultCollation>`
545* zh.xml: `<defaultCollation>pinyin</defaultCollation>`
546* zh_Hant.xml: `<defaultCollation>stroke</defaultCollation>`
547
548To allow implementations in reduced memory environments to use CJK sorting, there are also short forms of each of these collation sequences. These provide for the most common characters in common use, and are marked with `alt="short"`.
549
550A collation type name that starts with "private-", for example, "private-kana", indicates an incomplete tailoring that is only intended for import into one or more other tailorings (usually for sharing common rules). It does not establish a complete sort order. An implementation should not build data tables for a private collation type, and should not include a private collation type in a list of available types.
551
552> �� **Note**: There is an on-line demonstration of collation at [[LocaleExplorer](tr35.md#LocaleExplorer)] that uses the same rule syntax. (Pick the locale and scroll to "Collation Rules", near the end.)
553
554> �� **Note**: In CLDR 23 and before, LDML collation files used an XML format. Starting with CLDR 24, the XML collation syntax is deprecated and no longer used. See the _[CLDR 23 version of this document](https://www.unicode.org/reports/tr35/tr35-31/tr35-collation.html#Collation_Tailorings)_ for details about the XML collation syntax.
555
556#### <a name="Collation_Type_Fallback" href="#Collation_Type_Fallback">Collation Type Fallback</a>
557
558When loading a requested tailoring from its data file and the parent file chain, use the following type fallback to find the tailoring.
559
5601. Determine the default type from the `<defaultCollation>` element; map the default type to its alias if one is defined. If there is no `<defaultCollation>` element, then use "standard" as the default type.
5612. If the request language tag specifies the collation type (keyword "co"), then map it to its alias if one is defined (e.g., "-co-phonebk" → "phonebook"). If the language tag does not specify the type, then use the default type.
5623. Use the `<collation>` element with this type.
5634. If it does not exist, and the type starts with "search" but is longer, then set the type to "search" and use that `<collation>` element. (For example, "searchjl" → "search".)
5645. If it does not exist, and the type is not the default type, then set the type to the default type and use that `<collation>` element.
5656. If it does not exist, and the type is not "standard", then set the type to "standard" and use that `<collation>` element.
5667. If it does not exist, then use the CLDR root collation.
567
568> �� **Note**: that the CLDR collation/root.xml contains `<defaultCollation>standard</defaultCollation>`, `<collation type="standard">` (with an empty tailoring, so this is the same as the CLDR root collation), and `<collation type="search">`.
569
570For example, assume that we have collation data for the following tailorings. ("da/search" is shorthand for "da-u-co-search".)
571
572* root/defaultCollation=standard
573* root/standard (this is the same as “the CLDR root collator”)
574* root/search
575* da/standard
576* da/search
577* el/standard
578* ko/standard
579* ko/search
580* ko/searchjl
581* zh/defaultCollation=pinyin
582* zh/pinyin
583* zh/stroke
584* zh-Hant/defaultCollation=stroke
585
586###### Table: <a name="Sample_requested_and_actual_collation_locales_and_types" href="#Sample_requested_and_actual_collation_locales_and_types">Sample requested and actual collation locales and types</a>
587
588| requested         | actual        | comment |
589| ----------------- | ------------- | ------- |
590| da/phonebook      | da/standard   | default type for Danish |
591| zh                | zh/pinyin     | default type for zh |
592| zh/standard       | root/standard | no "standard" tailoring for zh, falls back to root |
593| zh/phonebook      | zh/pinyin     | default type for zh |
594| zh-Hant/phonebook | zh/stroke     | default type for zh-Hant is "stroke" |
595| da/searchjl       | da/search     | "search.+" falls back to "search" |
596| el/search         | root/search   | no "search" tailoring for Greek |
597| el/searchjl       | root/search   | "search.+" falls back to "search", found in root |
598| ko/searchjl       | ko/searchjl   | requested data is actually available |
599
600### <a name="Collation_Version" href="#Collation_Version">Version</a>
601
602The `version` attribute is used in case a specific version of the UCA is to be specified. It is optional, and is specified if the results are to be identical on different systems. If it is not supplied, then the version is assumed to be the same as the Unicode version for the system as a whole.
603
604> �� **Note**: For version 3.1.1 of the UCA, the version of Unicode must also be specified with any versioning information; an example would be "3.1.1/3.2" for version 3.1.1 of the UCA, for version 3.2 of Unicode. This was changed by decision of the UTC, so that dual versions were no longer necessary. So for UCA 4.0 and beyond, the version just has a single number.
605
606### <a name="Collation_Element" href="#Collation_Element">Collation Element</a>
607
608```xml
609<!ELEMENT collation (alias | (cr*, special*)) >
610```
611
612The tailoring syntax is designed to be independent of the actual weights used in any particular UCA table. That way the same rules can be applied to UCA versions over time, even if the underlying weights change. The following illustrates the overall structure of a collation:
613
614```xml
615<collation type="phonebook">
616  <cr><![CDATA[
617    [caseLevel on]
618    &c < k
619  ]]></cr>
620</collation>
621```
622
623### <a name="Setting_Options" href="#Setting_Options">Setting Options</a>
624
625Parametric settings can be specified in language tags or in rule syntax (in the form `[keyword value]` ). For example, `-ks-level2` or `[strength 2]` will only compare strings based on their primary and secondary weights.
626
627If a setting is not present, the CLDR default (or the default for the locale, if there is one) is used. That default is listed in bold italics. Where there is a UCA default that is different, it is listed in bold with (**UCA default**). Note that the default value for a locale may be different than the normal default value for the setting.
628
629###### Table: <a name="Collation_Settings" href="#Collation_Settings">Collation Settings</a>
630
631<table><tbody>
632<tr><th>BCP47 Key</th><th>BCP47 Value</th><th>Rule Syntax</th><th>Description</th></tr>
633
634<tr><td rowspan="5">ks</td><td>level1</td><td><code>[strength 1]</code><br/>(primary)</td>
635    <td rowspan="5">Sets the default strength for comparison, as described in the [<a href="https://www.unicode.org/reports/tr41/#UTS10">UCA</a>]. <i>Note that a strength setting of greater than 4 may have the same effect as <b>identical</b>, depending on the locale and implementation.</i></td></tr>
636<tr><td>level2</td><td><code>[strength 2]</code><br/>(secondary)</td></tr>
637<tr><td>level3</td><td><i><b><code>[strength 3]</code><br/>(tertiary)</b></i></td></tr>
638<tr><td>level4</td><td><code>[strength 4]</code><br/>(quaternary)</td></tr>
639<tr><td>identic</td><td><code>[strength I]</code><br/>(identical)</td></tr>
640
641<tr><td rowspan="3">ka</td><td>noignore</td><td><i><b><code>[alternate non-ignorable]</code></b></i><br/></td>
642    <td rowspan="3">Sets alternate handling for variable weights, as described in [<a href="https://www.unicode.org/reports/tr41/#UTS10">UCA</a>], where "shifted" causes certain characters to be ignored in comparison. <i>The default for LDML is different than it is in the UCA. In LDML, the default for alternate handling is <b>non-ignorable</b>, while in UCA it is <b>shifted</b>. In addition, in LDML only whitespace and punctuation are variable by default.</i></td></tr>
643<tr><td>shifted</td><td><b><code>[alternate shifted]</code><br/>(UCA default)</b></td></tr>
644<tr><td><i>n/a</i></td><td><i>n/a</i><br/>(blanked)</td></tr>
645
646<tr><td rowspan="2">kb</td><td>true</td><td><code>[backwards 2]</code></td>
647    <td rowspan="2">Sets the comparison for the second level to be <b>backwards</b>, as described in [<a href="https://www.unicode.org/reports/tr41/#UTS10">UCA</a>].</td></tr>
648<tr><td>false</td><td><i><b>n/a</b></i></td></tr>
649
650<tr><td rowspan="2">kk</td><td>true</td><td><b><code>[normalization on]</code><br/>(UCA default)</b></td>
651    <td rowspan="2">If <b>on</b>, then the normal [<a href="https://www.unicode.org/reports/tr41/#UTS10">UCA</a>] algorithm is used. If <b>off</b>, then most strings should still sort correctly despite not normalizing to NFD first.<br/><i>Note that the default for CLDR locales may be different than in the UCA. The rules for particular locales have it set to <b>on</b>: those locales whose exemplar characters (in forms commonly interchanged) would be affected by normalization.</i></td></tr>
652<tr><td>false</td><td><i><b><code>[normalization off]</code></b></i></td></tr>
653
654<tr><td rowspan="2">kc</td><td>true</td><td><code>[caseLevel on]</code></td>
655    <td rowspan="2">If set to <b>on</b><i>,</i> a level consisting only of case characteristics will be inserted in front of tertiary level, as a "Level 2.5". To ignore accents but take case into account, set strength to <b>primary</b> and case level to <b>on</b>. For details, see <i><a href="#Case_Parameters">Case Parameters</a></i> .</td></tr>
656<tr><td>false</td><td><i><b><code>[caseLevel off]</code></b></i></td></tr>
657
658<tr><td rowspan="3">kf</td><td>upper</td><td><code>[caseFirst upper]</code></td>
659    <td rowspan="3">If set to <b>upper</b>, causes upper case to sort before lower case. If set to <b>lower</b>, causes lower case to sort before upper case. Useful for locales that have already supported ordering but require different order of cases. Affects case and tertiary levels. For details, see <i><a href="#Case_Parameters">Case Parameters</a></i> .</td></tr>
660<tr><td>lower</td><td><code>[caseFirst lower]</code></td></tr>
661<tr><td>false</td><td><i><b><code>[caseFirst off]</code></b></i></td></tr>
662
663<tr><td rowspan="2">kh</td><td>true<br/><i><b>Deprecated:</b></i> Use rules with quater&shy;nary relations instead.</td><td><code>[hiraganaQ on]</code></td>
664    <td rowspan="2">Controls special treatment of Hiragana code points on quaternary level. If turned <b>on</b>, Hiragana codepoints will get lower values than all the other non-variable code points in <b>shifted</b>. That is, the normal Level 4 value for a regular collation element is FFFF, as described in [<a href="https://www.unicode.org/reports/tr41/#UTS10">UCA</a>], <i><a href="https://www.unicode.org/reports/tr10/#Variable_Weighting">Variable Weighting</a></i> . This is changed to FFFE for [:script=Hiragana:] characters. The strength must be greater or equal than quaternary if this attribute is to have any effect.</td></tr>
665<tr><td>false</td><td><i><b><code>[hiraganaQ off]</code></b></i></td></tr>
666
667<tr><td rowspan="2">kn</td><td>true</td><td><code>[numericOrdering on]</code></td>
668    <td rowspan="2">If set to <b>on</b>, any sequence of Decimal Digits (General_Category = Nd in the [<a href="https://www.unicode.org/reports/tr41/#UAX44">UAX44</a>]) is sorted at a primary level with its numeric value. For example, "A-21" &lt; "A-123". The computed primary weights are all at the start of the <b>digit</b> reordering group. Thus with an untailored UCA table, "a$" &lt; "a0" &lt; "a2" &lt; "a12" &lt; "a⓪" &lt; "aa".</td></tr>
669<tr><td>false</td><td><i><b><code>[numericOrdering off]</code></b></i></td></tr>
670
671<tr><td>kr</td><td>a sequence of one or more reorder codes: <b>space, punct, symbol, currency, digit</b>, or any BCP47 script ID</td><td><code>[reorder Grek digit]</code></td>
672    <td>Specifies a reordering of scripts or other significant blocks of characters such as symbols, punctuation, and digits. For the precise meaning and usage of the reorder codes, see <i><a href="#Script_Reordering">Collation Reordering</a>.</i></td></tr>
673
674<tr><td rowspan="4">kv</td><td>space</td><td><code>[maxVariable space]</code></td>
675    <td rowspan="4">Sets the variable top to the top of the specified reordering group. All code points with primary weights less than or equal to the variable top will be considered variable, and thus affected by the alternate handling. Variables are ignorable by default in [<a href="https://www.unicode.org/reports/tr41/#UTS10">UCA</a>], but not in CLDR.</td></tr>
676<tr><td>punct</td><td><i><b><code>[maxVariable punct]</code></b></i></td></tr>
677<tr><td>symbol</td><td><b><code>[maxVariable symbol]</code><br/>(UCA default)</b></td></tr>
678<tr><td>currency</td><td><code>[maxVariable currency]</code></td></tr>
679<tr><td>vt</td><td>See <i>Part 1 <a href="tr35.md#Unicode_Locale_Extension_Data_Files">U Extension Data Files</a></i>.<br/><i><b>Deprecated:</b></i> Use maxVariable instead.</td><td><code>&amp;\u00XX\uYYYY &lt; [variable top]</code><br/><br/>(the default is set to the highest punctuation, thus including spaces and punctuation, but not symbols)</td>
680    <td>The BCP47 value is described in <i>Appendix Q: <a href="tr35.md#Locale_Extension_Key_and_Type_Data">Locale Extension Keys and Types</a>.</i><br/><br/>Sets the string value for the variable top. All the code points with primary weights less than or equal to the variable top will be considered variable, and thus affected by the alternate handling.<br/>An implementation that supports the variableTop setting should also support the maxVariable setting, and it should "pin" ("round up") the variableTop to the top of the containing reordering group.<br/>Variables are ignorable by default in [<a href="https://www.unicode.org/reports/tr41/#UTS10">UCA</a>], but not in CLDR. See below for more information.</td></tr>
681
682<tr><td><i>n/a</i></td><td><i>n/a</i></td><td><i>n/a</i></td>
683    <td>match-boundaries: <i><b>none</b></i> | whole-character | whole-word<br/>Defined by <i><a href="https://www.unicode.org/reports/tr10/#Searching">Searching and Matching</a></i> of [<a href="https://www.unicode.org/reports/tr41/#UTS10">UCA</a>].</td></tr>
684<tr><td><i>n/a</i></td><td><i>n/a</i></td><td><i>n/a</i></td>
685    <td>match-style: <i><b>minimal</b></i> | medial | maximal<br/>Defined by <i><a href="https://www.unicode.org/reports/tr10/#Searching">Searching and Matching</a></i> of [<a href="https://www.unicode.org/reports/tr41/#UTS10">UCA</a>].</td></tr>
686</tbody></table>
687
688#### <a name="Common_Settings" href="#Common_Settings">Common settings combinations</a>
689
690Some commonly used parametric collation settings are available via combinations of LDML settings attributes:
691
692* “Ignore accents”: **strength=primary**
693* “Ignore accents” but take case into account: **strength=primary caseLevel=on**
694* “Ignore case”: **strength=secondary**
695* “Ignore punctuation” (completely): **strength=tertiary alternate=shifted**
696* “Ignore punctuation” but distinguish among punctuation marks: **strength=quaternary alternate=shifted**
697
698#### <a name="Normalization_Setting" href="#Normalization_Setting">Notes on the normalization setting</a>
699
700The UCA always normalizes input strings into NFD form before the rest of the algorithm. However, this results in poor performance.
701
702With **normalization=off**, strings that are in [[FCD](tr35.md#FCD)] and do not contain Tibetan precomposed vowels (U+0F73, U+0F75, U+0F81) should sort correctly. With **normalization=on**, an implementation that does not normalize to NFD must at least perform an incremental FCD check and normalize substrings as necessary. It should also always decompose the Tibetan precomposed vowels. (Otherwise discontiguous contractions across their leading components cannot be handled correctly.)
703
704Another complication for an implementation that does not always use NFD arises when contraction mappings overlap with canonical Decomposition_Mapping strings. For example, the Danish contraction “aa” overlaps with the decompositions of ‘ä’, ‘å’, and other characters. In the root collation (and in the DUCET), Cyrillic ‘ӛ’ maps to a single collation element, which means that its decomposition “ә+◌̈” forms a contraction, and its second character (U+0308) is the same as the first character in the Decomposition_Mapping of U+0344 ‘◌̈́’=“◌̈+◌́”.
705
706In order to handle strings with these characters (e.g., “aä” and “ӛ́” [which are in FCD]) exactly as with prior NFD normalization, an implementation needs to either add overlap contractions to its data (e.g., “a+ä” and “ә+◌̈́”), or it needs to decompose the relevant composites (e.g., ‘ä’ and ‘◌̈́’) as soon as they are encountered.
707
708#### <a name="Variable_Top_Settings" href="#Variable_Top_Settings">Notes on variable top settings</a>
709
710Users may want to include more or fewer characters as Variable. For example, someone could want to restrict the Variable characters to just include space marks. In that case, maxVariable would be set to "space". (In CLDR 24 and earlier, the now-deprecated variableTop would be set to U+1680, see the “Whitespace” [UCA collation chart](https://www.unicode.org/charts/collation/)). Alternatively, someone could want more of the Common characters in them, and include characters up to (but not including) '0', by setting maxVariable to "currency". (In CLDR 24 and earlier, the now-deprecated variableTop would be set to U+20BA, see the “Currency-Symbol” collation chart).
711
712The effect of these settings is to customize to ignore different sets of characters when comparing strings. For example, the locale identifier "de-u-ka-shifted-kv-currency" is requesting settings appropriate for German, including German sorting conventions, and that currency symbols and characters sorting below them are ignored in sorting.
713
714### <a name="Rules" href="#Rules">Collation Rule Syntax</a>
715
716```xml
717<!ELEMENT cr #PCDATA >
718```
719
720The goal for the collation rule syntax is to have clearly expressed rules with a concise format. The CLDR rule syntax is a subset of the [[ICUCollation](tr35.md#ICUCollation)] syntax.
721
722For the CLDR root collation, the FractionalUCA.txt file defines all mappings for all of Unicode directly, and it also provides information about script boundaries, reordering groups, and other details. For tailorings, this is neither necessary nor practical. In particular, while the root collation sort order rarely changes for existing characters, their numeric collation weights change with every version. If tailorings also specified numeric weights directly, then they would have to change with every version, parallel with the root collation. Instead, for tailorings, mappings are added and modified relative to the root collation. (There is no syntax to _remove_ mappings, except via [special \[suppressContractions \[...\]\]](#Special_Purpose_Commands) .)
723
724The ASCII [:P:] and [:S:] characters are reserved for collation syntax: `[\u0021-\u002F \u003A-\u0040 \u005B-\u0060 \u007B-\u007E]`
725
726Unicode Pattern_White_Space characters between tokens are ignored. Unquoted white space terminates reset and relation strings.
727
728A pair of ASCII apostrophes encloses quoted literal text. They are normally used to enclose a syntax character or white space, or a whole reset/relation string containing one or more such characters, so that those are parsed as part of the reset/relation strings rather than treated as syntax. A pair of immediately adjacent apostrophes is used to encode one apostrophe.
729
730Code points can be escaped with `\uhhhh` and `\U00hhhhhh` escapes, as well as common escapes like `\t` and `\n` . (For details see the documentation of ICU `UnicodeString::unescape()`.) This is particularly useful for default-ignorable code points, combining marks, visually indistinct variants, hard-to-type characters, etc. These sequences are unescaped before the rules are parsed; this means that even escaped syntax and white space characters need to be enclosed in apostrophes. For example: `&'\u0020'='\u3000'`. Note: The unescaping is done by ICU tools (genrb) and demos before passing rule strings into the ICU library code. The ICU collation API does not unescape rule strings.
731
732The ASCII double quote must be both escaped (so that the collation syntax can be enclosed in pairs of double quotes in programming environments such as ICU resource bundle .txt files) and quoted. For example: `&'\u0022'<<<x`
733
734Comments are allowed at the beginning, and after any complete reset, relation, setting, or command. A comment begins with a `#` and extends to the end of the line (according to the Unicode Newline Guidelines).
735
736The collation syntax is case-sensitive.
737
738### <a name="Orderings" href="#Orderings">Orderings</a>
739
740The root collation mappings form the initial state. Mappings are added and removed via a sequence of rule chains. Each tailoring rule builds on the current state after all of the preceding rules (and is not affected by any following rules). Rule chains may alternate with comments, settings, and special commands.
741
742A rule chain consists of a reset followed by one or more relations. The reset position is a string which maps to one or more collation elements according to the current state. A relation consists of an operator and a string; it maps the string to the current collation elements, modified according to the operator.
743
744###### Table: <a name="Specifying_Collation_Ordering" href="#Specifying_Collation_Ordering">Specifying Collation Ordering</a>
745
746| Relation Operator | Example | Description |
747| ----------------- | ------- | ----------- |
748| `&`               | `& Z` | Map Z to collation elements according to the current state. These will be modified according to the following relation operators and then assigned to the corresponding relation strings. |
749| `<`               | `& a`<br/>`< b` | Make 'b' sort after 'a', as a _primary_ (base-character) difference |
750| `<<`              | `& a`<br/>`<< ä` | Make 'ä' sort after 'a' as a _secondary_ (accent) difference |
751| `<<<`             | `& a`<br/>`<<< A` | Make 'A' sort after 'a' as a _tertiary_ (case/variant) difference |
752| `<<<<`            | `& か`<br/>`<<<< カ` | Make 'カ' (Katakana Ka) sort after 'か' (Hiragana Ka) as a _quaternary_ difference |
753| `=`               | `& v`<br/>`= w` | Make 'w' sort _identically_ to 'v' |
754
755The following shows the result of serially applying three rules.
756
757|     | Rules       | Result                       | Comment |
758| --- | ----------- | ---------------------------- | ------- |
759|  1  | & a < g     | ... a **<₁ g** ...           | Put g after a. |
760|  2  | & a < h < k | ... a **<₁ h <₁ k** <₁ g ... | Now put h and k after a (inserting before the g). |
761|  3  | & h << g    | ... a <₁ h **<₁ g** <₁ k ... | Now put g after h (inserting before k). |
762
763Notice that relation strings can occur multiple times, and thus override previous rules.
764
765Each relation uses and modifies the collation elements of the immediately preceding reset position or relation. A rule chain with two or more relations is equivalent to a sequence of “atomic rules” where each rule chain has exactly one relation, and each relation is followed by a reset to this same relation string.
766
767_Example:_
768
769| Rules                                          | Equivalent Atomic Rules |
770| ---------------------------------------------- | ----------------------- |
771| & b < q <<< Q<br/>& a < x <<< X << q <<< Q < z | & b < q<br/>& q <<< Q<br/>& a < x<br/>& x <<< X<br/>& X << q<br/>& q <<< Q<br/>& Q < z |
772
773This is not always possible because prefix and extension strings can occur in a relation but not in a reset (see below).
774
775The relation operator `=` maps its relation string to the current collation elements. Any other relation operator modifies the current collation elements as follows.
776
777* Find the _last_ collation element whose strength is at least as great as the strength of the operator. For example, for `<<` find the last primary or secondary CE. This CE will be modified; all following CEs should be removed. If there is no such CE, then reset the collation elements to a single completely-ignorable CE.
778* Increment the collation element weight corresponding to the strength of the operator. For example, for `<<` increment the secondary weight.
779* The new weight must be less than the next weight for the same combination of higher-level weights of any collation element according to the current state.
780* Weights must be allocated in accordance with the [UCA well-formedness conditions](https://www.unicode.org/reports/tr10/#Well-Formed).
781* When incrementing any weight, lower-level weights should be reset to the “common” values, to help with sort key compression.
782
783In all cases, even for `=` , the case bits are recomputed according to _[Case Parameters](#Case_Parameters)_. (This can be skipped if an implementation does not support the caseLevel or caseFirst settings.)
784
785For example, `&ae<x` maps ‘x’ to two collation elements. The first one is the same as for ‘a’, and the second one has a primary weight between those for ‘e’ and ‘f’. As a result, ‘x’ sorts between “ae” and “af”. (If the primary of the first collation element was incremented instead, then ‘x’ would sort after “az”. While also sorting primary-after “ae” this would be surprising and sub-optimal.)
786
787Some additional operators are provided to save space with large tailorings. The addition of a * to the relation operator indicates that each of the following single characters are to be handled as if they were separate relations with the corresponding strength. Each of the following single characters must be NFD-inert, that is, it does not have a canonical decomposition and it does not reorder (ccc=0). This keeps abbreviated rules unambiguous.
788
789A starred relation operator is followed by a sequence of characters with the same quoting/escaping rules as normal relation strings. Such a sequence can also be followed by one or more pairs of ‘-’ and another sequence of characters. The single characters adjacent to the ‘-’ establish a code point order range. The same character cannot be both the end of a range and the start of another range. (For example, `<a-d-g` is not allowed.)
790
791###### Table: <a name="Abbreviating_Ordering_Specifications" href="#Abbreviating_Ordering_Specifications">Abbreviating Ordering Specifications</a>
792
793| Relation Operator | Example                 | Equivalent |
794| ----------------- | ----------------------- | ---------- |
795| `<*`              | `& a`<br/>`<* bcd-gp-s` | `& a`<br/>`< b < c < d < e < f < g < p < q < r < s` |
796| `<<*`             | `& a`<br/>`<<* æᶏɐ`     | `& a`<br/>`<< æ << ᶏ << ɐ` |
797| `<<<*`            | `& p`<br/>`<<<* PpP`  | `& p`<br/>`<<< P <<< p <<< P` |
798| `<<<<*`           | `& k`<br/>`<<<<* qQ`    | `& k`<br/>`<<<< q <<<< Q` |
799| `=*`              | `& v`<br/>`=* VwW`      | `& v`<br/>`= V = w = W` |
800
801### <a name="Contractions" href="#Contractions">Contractions</a>
802
803A multi-character relation string defines a contraction.
804
805###### Table: <a name="Specifying_Contractions" href="#Specifying_Contractions">Specifying Contractions</a>
806
807| Example          | Description |
808| ---------------- | ----------- |
809| `& k`<br/>`< ch` | Make the sequence 'ch' sort after 'k', as a primary (base-character) difference |
810
811### <a name="Expansions" href="#Expansions">Expansions</a>
812
813A mapping to multiple collation elements defines an expansion. This is normally the result of a reset position (and/or preceding relation) that yields multiple collation elements, for example `&ae<x` or `&æ<y` .
814
815A relation string can also be followed by `/` and an _extension string_. The extension string is mapped to collation elements according to the current state, and the relation string is mapped to the concatenation of the regular CEs and the extension CEs. The extension CEs are not modified, not even their case bits. The extension CEs are _not_ retained for following relations.
816
817For example, `&a<z/e` maps ‘z’ to an expansion similar to `&ae<x` . However, the first CE of ‘z’ is primary-after that of ‘a’, and the second CE is exactly that of ‘e’, which yields the order ae < x < af < ag < ... < az < z < b.
818
819The choice of reset-to-expansion vs. use of an extension string can be exploited to affect contextual mappings. For example, `&L·=x` yields a second CE for ‘x’ equal to the context-sensitive middle-dot-after-L (which is a secondary CE in the root collation). On the other hand, `&L=x/·` yields a second CE of the middle dot by itself (which is a primary CE).
820
821The two ways of specifying expansions also differ in how case bits are computed. When some of the CEs are copied verbatim from an extension string, then the relation string’s case bits are distributed over a smaller number of normal CEs. For example, `&aE=Ch` yields an uppercase CE and a lowercase CE, but `&a=Ch/E` yields a mixed-case CE (for ‘C’ and ‘h’ together) followed by an uppercase CE (copied from ‘E’).
822
823In summary, there are two ways of specifying expansions which produce subtly different mappings. The use of extension strings is unusual but sometimes necessary.
824
825### <a name="Context_Before" href="#Context_Before">Context Before</a>
826
827A relation string can have a prefix (context before) which makes the mapping from the relation string to its tailored position conditional on the string occurring after that prefix. For details see the specification of _[Context-Sensitive Mappings](#Context_Sensitive_Mappings)_.
828
829For example, suppose that "-" is sorted like the previous vowel. Then one could have rules that take "a-", "e-", and so on. However, that means that every time a very common character (a, e, ...) is encountered, a system will slow down as it looks for possible contractions. An alternative is to indicate that when "-" is encountered, and it comes after an 'a', it sorts like an 'a', and so on.
830
831###### Table: <a name="Specifying_Previous_Context" href="#Specifying_Previous_Context">Specifying Previous Context</a>
832
833| Rules |
834| ----- |
835| `& a <<< a \| '-'`<br/>`& e <<< e \| '-'`<br/>`...` |
836
837Both the prefix and extension strings can occur in a relation. For example, the following are allowed:
838
839* `< abc | def / ghi`
840* `< def / ghi`
841* `< abc | def`
842
843### <a name="Placing_Characters_Before_Others" href="#Placing_Characters_Before_Others">Placing Characters Before Others</a>
844
845There are certain circumstances where characters need to be placed before a given character, rather than after. This is the case with Pinyin, for example, where certain accented letters are positioned before the base letter. That is accomplished with the following syntax.
846
847`&[before 2] a << à`
848
849The before-strength can be 1 (primary), 2 (secondary), or 3 (tertiary).
850
851It is an error if the strength of the reset-before differs from the strength of the immediately following relation. Thus the following are errors.
852
853*   `&[before 2] a < à # error`
854*   `&[before 2] a <<< à # error`
855
856### <a name="Logical_Reset_Positions" href="#Logical_Reset_Positions">Logical Reset Positions</a>
857
858The CLDR table (based on UCA) has the following overall structure for weights, going from low to high.
859
860###### Table: <a name="Specifying_Logical_Positions" href="#Specifying_Logical_Positions">Specifying Logical Positions</a>
861
862| Name                                                           | Description      | UCA Examples |
863| -------------------------------------------------------------- | ---------------- | ------------ |
864| first tertiary ignorable<br/>...<br/>last tertiary ignorable   | p, s, t = ignore | Control Codes<br/>Format Characters<br/>Hebrew Points<br/>Tibetan Signs<br/>... |
865| first secondary ignorable<br/>...<br/>last secondary ignorable | p, s = ignore    | None in UCA |
866| first primary ignorable<br/>...<br/>last primary ignorable     | p = ignore       | Most combining marks |
867| first variable<br/>...<br/>last variable                       | _**if** alternate = non-ignorable<br/>_p != ignore,<br/>_**if** alternate = shifted_<br/>p, s, t = ignore | Whitespace,<br/>Punctuation |
868| first regular<br/>...<br/>last regular                         | p != ignore      | General Symbols<br/>Currency Symbols<br/>Numbers<br/>Latin<br/>Greek<br/>... |
869| first implicit<br/>...<br/>last implicit                       | p != ignore, assigned automatically | CJK, CJK compatibility (those that are not decomposed)<br/>CJK Extension A, B, C, ...<br/>Unassigned |
870| first trailing<br/>...<br/>last trailing                       | p != ignore,<br/>used for trailing syllable components | Jamo Trailing<br/>Jamo Leading<br/>U+FFFD<br/>U+FFFF |
871
872Each of the above Names can be used with a reset to position characters relative to that logical position. That allows characters to be ordered before or after a _logical_ position rather than a specific character.
873
874> �� **Note**: The reason for this is so that tailorings can be more stable. A future version of the UCA might add characters at any point in the above list. Suppose that you set character X to be after Y. It could be that you want X to come after Y, no matter what future characters are added; or it could be that you just want Y to come after a given logical position, for example, after the last primary ignorable.
875
876Each of these special reset positions always maps to a single collation element.
877
878Here is an example of the syntax:
879
880`& [first tertiary ignorable] << à`
881
882For example, to make a character be a secondary ignorable, one can make it be immediately after (at a secondary level) a specific character (like a combining diaeresis), or one can make it be immediately after the last secondary ignorable.
883
884Each special reset position adjusts to the effects of preceding rules, just like normal reset position strings. For example, if a tailoring rule creates a new collation element after `&[last variable]` (via explicit tailoring after that, or via tailoring after the relevant character), then this new CE becomes the new _last variable_ CE, and is used in following resets to `[last variable]` .
885
886[first variable] and [first regular] and [first trailing] should be the first real such CEs (e.g., CE(U+0060 \`)), as adjusted according to the tailoring, not the boundary CEs (see the FractionalUCA.txt “first primary” mappings starting with U+FDD1).
887
888`[last regular]` is not actually the last normal CE with a primary weight before implicit primaries. It is used to tailor large numbers of characters, usually CJK, into the script=Hani range between the last regular script and the first implicit CE. (The first group of implicit CEs is for Han characters.) Therefore, `[last regular]` is set to the first Hani CE, the artificial script boundary CE at the beginning of this range. For example: `&[last regular]<*亜唖娃阿...`
889
890The [last trailing] is the CE of U+FFFF. Tailoring to that is not allowed.
891
892The `[last variable]` indicates the "highest" character that is treated as punctuation with alternate handling.
893
894The value can be changed by using the maxVariable setting. This takes effect, however, after the rules have been built, and does not affect any characters that are reset relative to the `[last variable]` value when the rules are being built. The maxVariable setting might also be changed via a runtime parameter. That also does not affect the rules.
895(In CLDR 24 and earlier, the variable top could also be set by using a tailoring rule with `[variable top]` in the place of a relation string.)
896
897### <a name="Special_Purpose_Commands" href="#Special_Purpose_Commands">Special-Purpose Commands</a>
898
899The import command imports rules from another collation. This allows for better maintenance and smaller rule sizes. The source is a BCP 47 language tag with an optional collation type but without other extensions. The collation type is the BCP 47 form of the collation type in the source; it defaults to "standard".
900
901_Examples:_
902
903* `[import de-u-co-phonebk]` (not "...-co-phonebook")
904* `[import und-u-co-search]` (not "root-...")
905* `[import ja-u-co-private-kana]` (language "ja" required even when this import itself is in another "ja" tailoring.)
906
907###### Table: <a name="Special_Purpose_Elements" href="#Special_Purpose_Elements">Special-Purpose Elements</a>
908
909| Rule Syntax |
910| ----------- |
911| [suppressContractions [Љ-ґ]] |
912| [optimize [Ά-ώ]] |
913
914The _suppress contractions_ tailoring command turns off any existing contractions that begin with those characters, as well as any prefixes for those characters. It is typically used to turn off the Cyrillic contractions in the UCA, since they are not used in many languages and have a considerable performance penalty. The argument is a [Unicode Set](tr35.md#Unicode_Sets).
915
916The _suppress contractions_ command has immediate effect on the current set of mappings, including mappings added by preceding rules. Following rules are processed after removing any context-sensitive mappings originating from any of the characters in the set.
917
918The _optimize_ tailoring command is purely for performance. It indicates that those characters are sufficiently common in the target language for the tailoring that their performance should be enhanced.
919
920The reason that these are not settings is so that their contents can be arbitrary characters.
921
922* * *
923
924_Example:_
925
926The following is a simple example that combines portions of different tailorings for illustration. For more complete examples, see the actual locale data: [Japanese](https://github.com/unicode-org/cldr/blob/main/common/collation/ja.xml), [Chinese](https://github.com/unicode-org/cldr/blob/main/common/collation/zh.xml), [Swedish](https://github.com/unicode-org/cldr/blob/main/common/collation/sv.xml), and [German](https://github.com/unicode-org/cldr/blob/main/common/collation/de.xml) (type="phonebook") are particularly illustrative.
927
928```xml
929<collation>
930  <cr><![CDATA[
931    [caseLevel on]
932    &Z
933    < æ <<< Æ
934    < å <<< Å <<< aa <<< aA <<< Aa <<< AA
935    < ä <<< Ä
936    < ö <<< Ö << ű <<< Ű
937    < ő <<< Ő << ø <<< Ø
938    &V <<<* wW
939    &Y <<<* üÜ
940    &[last non-ignorable]
941    # The following is equivalent to <亜<唖<娃...
942    <* 亜唖娃阿哀愛挨姶逢葵茜穐悪握渥旭葦芦
943    <* 鯵梓圧斡扱
944  ]]></cr>
945</collation>
946```
947
948### <a name="Script_Reordering" href="#Script_Reordering">Collation Reordering</a>
949
950Collation reordering allows scripts and certain other defined blocks of characters to be moved relative to each other parametrically, without changing the detailed rules for all the characters involved. This reordering is done on top of any specific ordering rules within the script or block currently in effect. Reordering can specify groups to be placed at the start and/or the end of the collation order. For example, to reorder Greek characters before Latin characters, and digits afterwards (but before other scripts), the following can be used:
951
952| Rule Syntax                 | Locale Identifier |
953| --------------------------- | ----------------- |
954| `[reorder Grek Latn digit]` | `en-u-kr-grek-latn-digit` |
955
956In each case, a sequence of _**reorder_codes**_ is used, separated by spaces in the settings attribute and in rule syntax, and by hyphens in locale identifiers.
957
958A **_reorder_code_** is any of the following special codes:
959
9601. **space, punct, symbol, currency, digit** - core groups of characters below 'a'
9612. **any script code** except **Common** and **Inherited**.
962   * Some pairs of scripts sort primary-equal and always reorder together. For example, Katakana characters are are always reordered with Hiragana.
9633. **others** - where all codes not explicitly mentioned should be ordered. The script code **Zzzz** (Unknown Script) is a synonym for **others**.
964
965It is an error if a code occurs multiple times.
966
967It is an error if the sequence of reorder codes is empty in the XML attribute or in the locale identifier. Some implementations may interpret an empty sequence in the `[reorder]` rule syntax as a reset to the DUCET ordering, synonymous with `[reorder others]` ; other implementations may forbid an empty sequence in the rule syntax as well.
968
969Interaction with **alternate=shifted**: Whether a primary weight is “variable” is determined according to the “variable top”, before applying script reordering. Once that is determined, script reordering is applied to the primary weight regardless of whether it is “regular” (used in the primary level) or “shifted” (used in the quaternary level).
970
971#### <a name="Interpretation_reordering" href="#Interpretation_reordering">Interpretation of a reordering list</a>
972
973The reordering list is interpreted as if it were processed in the following way.
974
9751. If any core code is not present, then it is inserted at the front of the list in the order given above.
9762. If the **others** code is not present, then it is inserted at the end of the list.
9773. The **others** code is replaced by the list of all script codes not explicitly mentioned, in DUCET order.
9784. The reordering list is now complete, and used to reorder characters in collation accordingly.
979
980The locale data may have a particular ordering. For example, the Czech locale data could put digits after all letters, with `[reorder others digit]` . Any reordering codes specified on top of that (such as with a bcp47 locale identifier) completely replace what was there. To specify a version of collation that completely resets any existing reordering to the DUCET ordering, the single code **Zzzz** or **others** can be used, as below.
981
982_Examples:_
983
984| Locale Identifier                 | Effect |
985| --------------------------------- | ------ |
986| `en-u-kr-latn-digit`              | Reorder digits after Latin characters (but before other scripts like Cyrillic). |
987| `en-u-kr-others-digit`            | Reorder digits after all other characters. |
988| `en-u-kr-arab-cyrl-others-symbol` | Reorder Arabic characters first, then Cyrillic, and put symbols at the end—after all other characters. |
989| `en-u-kr-others`                  | Remove any locale-specific reordering, and use DUCET order for reordering blocks. |
990
991The default reordering groups are defined by the FractionalUCA.txt file, based on the primary weights of associated collation elements. The file contains special mappings for the start of each group, script, and reorder-reserved range, see _[FractionalUCA.txt](#File_Format_FractionalUCA_txt)_.
992
993There are some special cases:
994
995* The **Hani** group includes implicit weights for _Han characters_ according to the UCA as well as any characters tailored relative to a Han character, or after `&[first Hani]`.
996* Implicit weights for _unassigned code points_ according to the UCA reorder as the last weights in the **others** (**Zzzz**) group.
997  There is no script code to explicitly reorder the unassigned-implicit weights into a particular position. (Unassigned-implicit weights are used for non-Hani code points without any mappings. For a given Unicode version they are the code points with General_Category values Cn, Co, Cs.)
998* The TRAILING group, the FIELD-SEPARATOR (associated with U+FFFE), and collation elements with only zero primary weights are not reordered.
999* The TERMINATOR, LEVEL-SEPARATOR, and SPECIAL groups are never associated with characters.
1000
1001For example, `reorder="Hani Zzzz Grek"` sorts Hani, Latin, Cyrillic, ... (all other scripts) ..., unassigned, Greek, TRAILING.
1002
1003Notes for implementations that write sort keys:
1004
1005* Primaries must always be offset by one or more whole primary lead bytes. (Otherwise the number of bytes in a fractional weight may change, compressible scripts may span multiple lead bytes, or trailing primary bytes may collide with separators and primary-compression terminators.)
1006* When a script is reordered that does not start and end on whole-primary-lead-byte boundaries, then the lead byte needs to be “split”, and a reserved byte is used up. The data supports this via reorder-reserved ranges of primary weights that are not used for collation elements.
1007* Primary weights from different original lead bytes can be reordered to a shared lead byte, as long as they do not overlap. Primary compression ends when the target lead byte differs or when the original lead byte of the next primary is not compressible.
1008* Non-compressible groups and scripts begin or end on whole-primary-lead-byte boundaries (or both), so that reordering cannot surround a non-compressible script by two compressible ones within the same target lead byte. This is so that primary compression can be terminated reliably (choosing the low or high terminator byte) simply by comparing the previous and current primary weights. Otherwise it would have to also check for another condition (e.g., equal scripts).
1009
1010#### <a name="Reordering_Groups_allkeys" href="#Reordering_Groups_allkeys">Reordering Groups for allkeys.txt</a>
1011
1012For allkeys_CLDR.txt, the start of each reordering group can be determined from FractionalUCA.txt, by finding the first real mapping (after “xyz first primary”) of that group (e.g., `0060; [0D 07, 05, 05] # Zyyy Sk [0312.0020.0002] * GRAVE ACCENT` ), and looking for that mapping's character sequence ( `0060` ) in allkeys_CLDR.txt. The comment in FractionalUCA.txt ( `[0312.0020.0002]` ) also shows the allkeys_CLDR.txt collation elements.
1013
1014The DUCET ordering of some characters is slightly different from the CLDR root collation order. The reordering groups for the DUCET are not specified. The following describes how reordering groups for the DUCET can be derived.
1015
1016For allkeys_DUCET.txt, the start of each reordering group is normally the primary weight corresponding to the same character sequence as for allkeys_CLDR.txt. In a few cases this requires adjustment, especially for the special reordering groups, due to CLDR’s ordering the common characters more strictly by category than the DUCET (as described in _[Root Collation](#Root_Collation)_). The necessary adjustment would set the start of each allkeys_DUCET.txt reordering group to the primary weight of the first mapping for the relevant General_Category for a special reordering group (for characters that sort before ‘a’), or the primary weight of the first mapping for the first script (e.g., sc=Grek) of an “alphabetic” group (for characters that sort at or after ‘a’).
1017
1018Note that the following only applies to primary weights greater than the one for U+FFFE and less than "trailing" weights.
1019
1020The special reordering groups correspond to General_Category values as follows:
1021
1022* punct: P
1023* symbol: Sk, Sm, So
1024* space: Z, Cc
1025* currency: Sc
1026* digit: Nd
1027
1028In the DUCET, some characters that sort below ‘a’ and have other General_Category values not mentioned above (e.g., gc=Lm) are also grouped with symbols. Variants of numbers (gc=No or Nl) can be found among punctuation, symbols, and digits.
1029
1030Each collation element of an expansion may be in a different reordering group, for example for parenthesized characters.
1031
1032### <a name="Case_Parameters" href="#Case_Parameters">Case Parameters</a>
1033
1034The **case level** is an _optional_ intermediate level ("2.5") between Level 2 and Level 3 (or after Level 1, if there is no Level 2 due to strength settings). The case level is used to support two parametric features: ignoring non-case variants (Level 3 differences) except for case, and giving case differences a higher-level priority than other tertiary differences. Distinctions between small and large Kana characters are also included as case differences, to support Japanese collation.
1035
1036The **case first** parameter controls whether to swap the order of upper and lowercase. It can be used with or without the case level.
1037
1038Importantly, the case parameters have no effect in many instances. For example, they have no effect on the comparison of two non-ignorable characters with different primary weights, or with different secondary weights if the strength = **secondary (or higher).**
1039
1040When either the **case level** or **case first** parameters are set, the following describes the derivation of the modified collation elements. It assumes the original levels for the code point are [p.s.t] (primary, secondary, tertiary). This derivation may change in future versions of LDML, to track the case characteristics more closely.
1041
1042#### <a name="Case_Untailored" href="#Case_Untailored">Untailored Characters</a>
1043
1044For untailored characters and strings, that is, for mappings in the root collation, the case value for each collation element is computed from the tertiary weight listed in allkeys_CLDR.txt. This is used to modify the collation element.
1045
1046Look up a case value for the tertiary weight x of each collation element:
1047
10481. UPPER if x ∈ {08-0C, 0E, 11, 12, 1D}
10492. UNCASED otherwise
10503. FractionalUCA.txt encodes the case information in bits 6 and 7 of the first byte in each tertiary weight. The case bits are set to 00 for UNCASED and LOWERCASE, and 10 for UPPER. There is no MIXED case value (01) in the root collation.
1051
1052#### <a name="Case_Weights" href="#Case_Weights">Compute Modified Collation Elements</a>
1053
1054From a computed case value, set a weight **c** according to the following.
1055
10561. If **CaseFirst=UpperFirst**, set **c** = UPPER ? **1** : MIXED ? 2 : **3**
10572. Otherwise set **c** = UPPER ? **3** : MIXED ? 2 : **1**
1058
1059Compute a new collation element according to the following table. The notation _xt_ means that the values are numerically combined into a single level, such that xt < yu whenever x < y. The fourth level (if it exists) is unaffected. Note that a secondary CE must have a secondary weight S which is greater than the secondary weight s of any primary CE; and a tertiary CE must have a tertiary weight T which is greater than the tertiary weight t of any primary or secondary CE ([[UCA](https://www.unicode.org/reports/tr41/#UTS10)] [WF2](https://www.unicode.org/reports/tr10/#WF2)).
1060
1061<table><tbody>
1062<tr><th>Case Level</th><th>Strength</th><th>Original CE</th><th>Modified CE</th><th>Comment</th></tr>
1063
1064<tr><td rowspan="5"><strong>on</strong></td><td rowspan="2"><strong>primary</strong></td><td><code>0.S.t</code></td><td><code>0.0</code></td><td rowspan="2">ignore case level weights of primary-ignorable CEs</td></tr>
1065<tr><td><code>p.s.t</code></td><td><code>p.c</code></td></tr>
1066
1067<tr><td rowspan="3"><strong>secondary<br></strong> or higher</td><td><code>0.0.T</code></td> <td><code>0.0.0.T</code></td><td rowspan="3">ignore case level weights of secondary-ignorable CEs</td></tr>
1068    <tr><td><code>0.S.t</code></td><td><code>0.S.c.t</code></td></tr>
1069    <tr><td><code>p.s.t</code></td><td><code>p.s.c.t</code></td></tr>
1070
1071<tr><td rowspan="4"><strong>off</strong></td><td rowspan="4">any</td><td><code>0.0.0</code></td><td><code>0.0.00</code></td><td rowspan="4">ignore case level weights of tertiary-ignorable CEs</td></tr>
1072    <tr><td><code>0.0.T</code></td><td><code>0.0.3T</code></td></tr>
1073    <tr><td><code>0.S.t</code></td><td><code>0.S.ct</code></td></tr>
1074    <tr><td><code>p.s.t</code></td><td><code>p.s.ct</code></td></tr>
1075</tbody></table>
1076
1077For primary+case, which is used for “ignore accents but not case” collation, primary ignorables are ignored so that a = ä. For secondary+case, which would by analogy mean “ignore variants but not case”, secondary ignorables are ignored for equivalent behavior.
1078
1079When using **caseFirst** but not **caseLevel**, the combined case+tertiary weight of a tertiary CE must be greater than the combined case+tertiary weight of any primary or secondary CE so that [[UCA](https://www.unicode.org/reports/tr41/#UTS10)] [well-formedness condition 2](https://www.unicode.org/reports/tr10/#WF2) is fulfilled. Since the tertiary CE’s tertiary weight T is already greater than any t of primary or secondary CEs, it is sufficient to set its case weight to UPPER=3. It must not be affected by **caseFirst=upper**. (The table uses the constant 3 in this case rather than the computed c.)
1080
1081The case weight of a tertiary-ignorable CE must be 0 so that [[UCA](https://www.unicode.org/reports/tr41/#UTS10)] [well-formedness condition 1](https://www.unicode.org/reports/tr10/#WF1) is fulfilled.
1082
1083#### <a name="Case_Tailored" href="#Case_Tailored">Tailored Strings</a>
1084
1085Characters and strings that are tailored have case values computed from their root collation case bits.
1086
10871. Look up the tailored string’s root CEs. (Ignore any prefix or extension strings.) N=number of primary root CEs.
10882. Determine the number and type (primary vs. weaker) of CEs a tailored string maps to. M=number of primary tailored CEs.
10893. If N<=M (no more root than tailoring primary CEs): Copy the root case bits for primary CEs 0..N-1.
1090   * If N<M (fewer root primary CEs): Clear the case bits of the remaining tailored primary CEs. (uncased/lowercase/small Kana)
10914. If N>M (more root primary CEs): Copy the root case bits for primary CEs 0..M-2. Set the case bits for tailored primary CE M-1 according to the remaining root primary CEs M-1..N-1:
1092   * Set to uncased/lower if all remaining root primary CEs have uncased/lower.
1093   * Set to uppercase if all remaining root primary CEs have uppercase.
1094   * Otherwise, set to mixed.
10955. Clear the case bits for secondary CEs 0.s.t.
10966. Tertiary CEs 0.0.t must get uppercase bits.
10977. Tertiary-ignorable CEs 0.0.0 must get ignorable-case=lowercase bits.
1098
1099> �� **Note**: Almost all Cased characters have primary (non-ignorable) root collation CEs, except for U+0345 Combining Ypogegrammeni which is Lowercase. All Uppercase characters have primary root collation CEs.
1100
1101### <a name="Visibility" href="#Visibility">Visibility</a>
1102
1103Collations have external visibility by default, meaning that they can be displayed in a list of collation options for users to choose from. A collation whose type name starts with "private-" is internal and should not be shown in such a list. Collations are typically internal when they are partial sequences included in other collations. See _[Collation Types](#Collation_Types)_ .
1104
1105### <a name="Collation_Indexes" href="#Collation_Indexes">Collation Indexes</a>
1106
1107#### <a name="Index_Characters" href="#Index_Characters">Index Characters</a>
1108
1109The main data includes `<exemplarCharacters>` for collation indexes. See _Part 2 General, [Character Elements](tr35-general.md#Character_Elements)_, for general information about exemplar characters.
1110
1111The index characters are a set of characters for use as a UI "index", that is, a list of clickable characters (or character sequences) that allow the user to see a segment of a larger "target" list. Each character corresponds to a bucket in the target list. One may have different kinds of index lists; one that produces an index list that is relatively static, and the other is a list that produces roughly equally-sized buckets. While CLDR is mostly focused on the first, there is provision for supporting the second as well.
1112
1113The index characters need to be used in conjunction with a collation for the locale, which will determine the order of the characters. It will also determine which index characters show up.
1114
1115The static list would be presented as something like the following (either vertically or horizontally):
1116
1117… A B C D E F G H CH I J K L M N O P Q R S T U V W X Y Z …
1118
1119In the "A" bucket, you would find all items that are primary greater than or equal to "A" in collation order, and primary less than "B". The use of the list requires that the target list be sorted according to the locale that is used to create that list. Although we say "character" above, the index character could be a sequence, like "CH" above. The index exemplar characters must always be used with a collation appropriate for the locale. Any characters that do not have primary differences from others in the set should be removed.
1120
1121Details:
1122
11231. The primary weight (according to the collation) is used to determine which bucket a string is in. There are special buckets for before the first character, between buckets of different scripts, and after the last bucket (and of a different script).
11242. Characters in the _index characters_ do not need to have distinct primary weights. That is, the _index characters_ are adapted to the underlying collation: normally Ё is in the Е bucket for Russian, but if someone used a variant of Russian collation that distinguished them on a primary level, then Ё would show up as its own bucket.
11253. If an _index character_ string ends with a single "\*" (U+002A), for example "Sch\*" and "St\*" in German, then there will be a separate bucket for the string minus the "\*", for example "Sch" and "St", even if that string does not sort distinctly.
11264. An _index character_ can have multiple primary weights, for example "Æ" and "Sch". Names that have the same initial primary weights sort into this _index character_’s bucket. This can be achieved by using an upper-boundary string that is the concatenation of the _index character_ and U+FFFF, for example "Æ\\uFFFF" and "Sch\\uFFFF". Names that sort greater than this upper boundary but less than the next index character are redirected to the last preceding single-primary index character (A and S for the examples here).
1127
1128For example, for index characters `[A Æ B R S {Sch*} {St*} T]` the following sample names are sorted into an index as shown.
1129
1130* A — Adelbert, Afrika
1131* Æ — Æsculap, Aesthet
1132* B — Berlin
1133* R — Rilke
1134* S — Sacher, Seiler, Sultan
1135* Sch — Schiller
1136* St — Steiff
1137* T — Thomas
1138
1139The … items are special: each is a bucket for everything else, either less or greater. They are inserted at the start and end of the index list, _and_ on script boundaries. Each script has its own range, except where scripts sort primary-equal (e.g., Hira & Kana). All characters that sort in one of the low reordering groups (whitespace, punctuation, symbols, currency symbols, digits) are treated as a single script for this purpose.
1140
1141If you tailor a Greek character into the Cyrillic script, that Greek character will be bucketed (and sorted) among the Cyrillic ones.
1142
1143Even in an implementation that reorders groups of scripts rather than single scripts, for example Hebrew together with Phoenician and Samaritan, the index boundaries are really script boundaries, _not_ multi-script-group boundaries. So if you had a collation that reordered Hebrew after Ethiopic, you would still get index boundaries between the following (and in that order):
1144
11451. Ethiopic
11462. Hebrew
11473. Phoenician _// included in the Hebrew reordering group_
11484. Samaritan _// included in the Hebrew reordering group_
11495. Devanagari
1150
1151(Beginning with CLDR 27, single scripts can be reordered.)
1152
1153In the UI, an index character could also be omitted or grayed out if its bucket is empty. For example, if there is nothing in the bucket for Q, then Q could be omitted. That would be up to the implementation. Additional buckets could be added if other characters are present. For example, we might see something like the following:
1154
1155| Sample Greek Index                                          | Contents |
1156| :---------------------------------------------------------: | -------- |
1157|           Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω   | With only content beginning with Greek letters |
1158|         … Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω … | With some content before or after |
1159| … 9       Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω … | With numbers, and nothing between 9 and Alpha |
1160| … 9 _A-Z_ Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω … | With numbers, some Latin |
1161
1162Here is a sample of the XML structure:
1163
1164```xml
1165<exemplarCharacters type="index">[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z]</exemplarCharacters>
1166```
1167
1168The display of the index characters can be modified with the Index labels elements, discussed in the _Part 2 General, [Index Labels](tr35-general.md#IndexLabels)_.
1169
1170#### <a name="CJK_Index_Markers" href="#CJK_Index_Markers">CJK Index Markers</a>
1171
1172Special index markers have been added to the CJK collations for stroke, pinyin, zhuyin, and unihan. These markers allow for effective and robust use of indexes for these collations.
1173
1174The per-language index exemplar characters are not useful for collation indexes for CJK because for each such language there are multiple sort orders in use (for example, Chinese pinyin vs. stroke vs. unihan vs. zhuyin), and these sort orders use very different index characters. In addition, sometimes the boundary strings are different from the bucket label strings. For collations that contain index markers, the boundary strings and bucket labels should be derived from those index markers, ignoring the index exemplar characters.
1175
1176For example, near the start of the pinyin tailoring there is the following:
1177
1178```html
1179<p> A</p><!-- INDEX A -->
1180<pc>阿呵��锕����</pc><!-- ā -->
11811182<pc>翶</pc><!-- ao -->
1183<p> B</p><!-- INDEX B -->
1184```
1185
1186These indicate the boundaries of "buckets" that can be used for indexing. They are always two characters starting with the noncharacter U+FDD0, and thus will not occur in normal text. For pinyin the second character is A-Z; for unihan it is one of the radicals; and for stroke it is a character after U+2800 indicating the number of strokes, such as ⠁. For zhuyin the second character is one of the standard Bopomofo characters in the range U+3105 through U+3129.
1187
1188The corresponding bucket label strings are the boundary strings with the leading U+FDD0 removed. For example, the Pinyin boundary string "\\uFDD0A" yields the label string "A".
1189
1190However, for stroke order, the label string is the stroke count (second character minus U+2800) as a decimal-digit number followed by 劃 (U+5283). For example, the stroke order boundary string "\\uFDD0\\u2805" yields the label string "5劃".
1191
1192* * *
1193
1194Copyright © 2001–2024 Unicode, Inc. All Rights Reserved. The Unicode Consortium makes no expressed or implied warranty of any kind, and assumes no liability for errors or omissions. No liability is assumed for incidental and consequential damages in connection with or arising out of the use of the information or programs contained or accompanying this technical report. The Unicode [Terms of Use](https://www.unicode.org/copyright.html) apply.
1195
1196Unicode and the Unicode logo are trademarks of Unicode, Inc., and are registered in some jurisdictions.
1197