// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie // SPDX-License-Identifier: MIT //! zig-collate: the Unicode Collation Algorithm, [UTS #10][uca]. //! //! Text compared by code point is not merely unlocalized, it is wrong in a //! way people notice. `Mueller` sorts before `Märtens`, because `u` is //! U+0075 and `ä` is U+00E4. This library exists so that a program which //! needs to put names in order does not have to reimplement a collation to //! get that right, and so that it does not get it wrong in the same way //! every such reimplementation does. //! //! The short version: //! //! ```zig //! const collate = @import("collate"); //! //! const c: collate.Collator = .{}; //! const order = try c.order(gpa, "Märtens", "Mueller"); // .lt //! ``` //! //! Sorting a list means building one sort key per string and then comparing //! the keys, which is what makes the whole thing affordable -- *n* key //! constructions and `n log n` byte comparisons, rather than `n log n` //! collations: //! //! ```zig //! var builder: collate.Builder = .empty; //! defer builder.deinit(gpa); //! //! const key = try builder.sortKeyAlloc(gpa, c, name); //! // ... and later //! if (collate.orderKeys(key_a, key_b) == .lt) { ... } //! ``` //! //! ## What is here and what is not //! //! The root collation, which is the untailored Default Unicode Collation //! Element Table: all four steps of section 7, the variable weighting //! options of section 4, strengths from primary to identical, and the //! derived weights of section 10.1 for everything the table does not //! mention. //! //! Not here: the CLDR tailorings. Those are the only per-language part of a //! collation, and the only part that a `lang=` setting needs. A correct root //! collation is worth having on its own -- it is a better default than code //! point order for every string, whether or not anyone said which language //! it is in. //! //! [uca]: https://www.unicode.org/reports/tr10/ const collator = @import("collator.zig"); const key = @import("key.zig"); const table = @import("table.zig"); pub const Collator = collator.Collator; pub const Builder = collator.Builder; pub const Error = collator.Error; pub const orderKeys = collator.orderKeys; pub const Options = key.Options; pub const Strength = key.Strength; pub const Alternate = key.Alternate; pub const CaseFirst = key.CaseFirst; /// The settings a locale's rules ask for that are a collator's business /// rather than a table's. `Options.applying` is how they are taken up. pub const Settings = @import("data").Settings; pub const Table = table.Table; /// The Default Unicode Collation Element Table, generated at build time from /// the Unicode data files in `data/`. Empty when the library was built with /// `-Dembed-ducet=false`. pub const ducet = table.ducet; /// The CLDR root collation, which is a tailoring of DUCET applied before /// anyone's language is considered: scripts regrouped, the set of variable /// characters narrowed, and the sentinels that sort key merging needs added. /// It is what ICU orders by. /// /// Empty unless the library was built with `-Dembed-cldr`. pub const cldr_root = table.cldr_root; pub const Tailoring = @import("data").Tailoring; /// The CLDR collation tailorings this build was asked for, by `-Dlocales`. /// /// ```zig /// const swedish: collate.Collator = .{ /// .table = collate.ducet.tailored(&collate.locales.sv), /// }; /// ``` /// /// A locale the build was not asked for is a compile error rather than a /// run-time surprise, which is the point of making these declarations rather /// than a lookup by string. pub const locales = @import("locales"); /// Collation elements and the weights they are made of: the vocabulary of /// section 3.1, and the shapes a table is stored in. pub const data = @import("data"); /// Step 1 on its own, for a caller that wants NFD without a collation. pub const nfd = @import("nfd.zig"); /// Steps 2 and 3, for a caller that wants to see the collation elements or /// build a key by hand. pub const elements = @import("elements.zig"); pub const sort_key = key; test { _ = @import("collator.zig"); _ = @import("elements.zig"); _ = @import("key.zig"); _ = @import("nfd.zig"); _ = @import("table.zig"); }