跳到主要内容
uencoder

Unicode Collation Reference

Reference 为 Unicode Collation Algorithm (UCA) 和 locale-aware 字符串 sorting.

Collation Algorithm

The Unicode Collation Algorithm (UCA, UTS #10) provides locale-aware string comparison. It uses a Default Collation Element Table (DUCET) mapping characters to sort weights. Multi-level comparison: primary (base character), secondary (accent), tertiary (case), quaternary (compatibility). Tailoring customizes DUCET for specific locales (e.g., German phonebook, Spanish ch as a digraph). The algorithm handles contractions, expansions, and ignorable characters. ICU implements UCA with extensive locale support.

UCA
Collation algorithm
UTS #10
DUCET
Default weights
base table
tailoring
Locale customization
German, Spanish

Implementation and Use

JavaScript Intl.Collator provides locale-aware comparison with options for sensitivity and numeric sorting. Numeric collation sorts "file2" before "file10" (natural sort). Case-first and accent-first options control tertiary/secondary weight order. Search collation (sensitivity: base) ignores accents and case for matching. Database collation should match application expectations. Sorting performance varies; precompute sort keys for large datasets. Always use Intl.Collator or ICU, never raw code point comparison, for user-facing sorting.

Intl.Collator
JS API
locale-aware
numeric
Natural sort
file2 < file10
search
Sensitivity: base
ignore accents

相关工具

参考链接