|
Text collation supports language-sensitive comparison of strings, allowing for text searching and alphabetical sorting. The collation classes provide a choice of ordering strength (for example, to ignore or not ignore case differences) and handle ignored, expanding, and contracting characters.
Developers don't need to know anything about the collation rules for various languages. Any features requiring collation can use the collation object associated with the current default locale, or with a specific locale (like France or Japan) if appropriate.
Collation Basics Localizable Collation Customization Details
Correctly sorting strings is tricky, even in English. The results of a sort must be consistent&emdash;any differences in strings must always be sorted the same way. The sort assigns relative priorities to different features of the text, based on the characters themselves and on the current ordering strength of the collation object.
To See This... |
Do This... |
---|---|
Consistent sorting: In English, uppercase letters always sort after lowercase letters whenever there are no other differences in compared strings. |
· Click on the Sort Ascending button. |
Differences in ordering strength: Secondary ordering strength means case differences are disregarded (enabling case-insensitive searching). With primary ordering strength accents are also ignored&emdash;only base letters are compared. |
· Select Primary from the Strength menu. |
Other special characters, including accented or grouped characters, add other complications. For example, the "-" hyphen character in the word "black-bird" is only significant if the other letters in the compared strings are identical.
Different collation objects associated with various locales handle the differences required when sorting text strings for different languages.
To See This... |
Do This... |
---|---|
In French, accent differences are sorted from the end of the word, so the ordering of "pêche" and "péché" changes from the English ordering. |
· Select Tertiary from the Strength menu. |
In German the ordering of "Töne" changes, because German treats o + umlaut (ö) as if it were oe. |
· Select German (Germany) from the Locale menu. |
You can produce a new collation by adding to or changing an existing one. You can do this in the demo using the Collation Rules field in the demonstration. This field shows the rules that make up the collation sequence for that language. (At the start of the list, are a number of odd-looking items such as"\u0308". These use Java notation for Unicode characters, used here because most browsers are currently unable to display the full range of Unicode characters.)
In all of the following examples, you can cut and paste sample rules or test cases instead of typing them in manually. Paste them at the end of the respective fields.
To See This... |
Do This... |
You can modify an existing collation. Adding items at the end of a collation overrides earlier information. For example, you can make the letter P sort at the end of the alphabet. |
· Enter the sample rules at the end of the Collation
Rules field. |
Sample Rules: | |
< p , P |
Making P sort at the end may not seem terribly useful, but it is used to make modifications in the sorting sequence for different languages.
To See This... |
Do This... |
You can add new rules to an existing collation. For example, you can add CH as a single letter after C, as in traditional Spanish sorting. |
· Enter the sample rules at the end of the Collation
Rules field. |
Sample Rules: | |
& c < ch , cH, Ch, CH | |
Sample Test Cases: | |
cat |
As well as adding sequences of characters that act as a single character (this is known as contraction), you can also add characters that act like a sequence of characters (this is known as expansion).
To See This... |
Do This... |
---|---|
You can also add other sequences to the collation rules, such as sorting symbols with their alphabetic equivalents. |
· Enter the sample rules at the end of the Collation
Rules field. |
Sample Rules: | |
Sample Test Cases: | |
? |
Expansion and contraction can actually be combined.
To See This... |
Do This... |
In Japanese there is a length character that acts as though it doubles a character in sorting. Using analogous English letters, it would be as though "a-" sorts as "aa", "e-" sorts as "ee", etc. |
· Enter the sample rules at the end of the Collation
Rules field. |
Sample Rules: | |
& aa ; a- | |
Sample Test Cases: | |
aardvark |
For more information on how collation rules are constructed, see Details. You can also type in additional words to see different collation behaviors. Try it out!