1// This file is part of ICU4X. For terms of use, please see the file
2// called LICENSE at the top level of the ICU4X source tree
3// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5//! Language Identifier and Locale contains a set of subtags
6//! which represent different fields of the structure.
7//!
8//! * [`Language`] is the only mandatory field, which when empty,
9//! takes the value `und`.
10//! * [`Script`] is an optional field representing the written script used by the locale.
11//! * [`Region`] is the region used by the locale.
12//! * [`Variants`] is a list of optional [`Variant`] subtags containing information about the
13//! variant adjustments used by the locale.
14//!
15//! Subtags can be used in isolation, and all basic operations such as parsing, syntax canonicalization
16//! and serialization are supported on each individual subtag, but most commonly
17//! they are used to construct a [`LanguageIdentifier`] instance.
18//!
19//! [`Variants`] is a special structure which contains a list of [`Variant`] subtags.
20//! It is wrapped around to allow for sorting and deduplication of variants, which
21//! is one of the required steps of language identifier and locale syntax canonicalization.
22//!
23//! # Examples
24//!
25//! ```
26//! use icu::locid::subtags::{Language, Region, Script, Variant};
27//!
28//! let language: Language =
29//! "en".parse().expect("Failed to parse a language subtag.");
30//! let script: Script =
31//! "arab".parse().expect("Failed to parse a script subtag.");
32//! let region: Region =
33//! "cn".parse().expect("Failed to parse a region subtag.");
34//! let variant: Variant =
35//! "MacOS".parse().expect("Failed to parse a variant subtag.");
36//!
37//! assert_eq!(language.as_str(), "en");
38//! assert_eq!(script.as_str(), "Arab");
39//! assert_eq!(region.as_str(), "CN");
40//! assert_eq!(variant.as_str(), "macos");
41//! ```
42//!
43//! `Notice`: The subtags are canonicalized on parsing. That means
44//! that all operations work on a canonicalized version of the subtag
45//! and serialization is very cheap.
46//!
47//! [`LanguageIdentifier`]: super::LanguageIdentifier
48mod language;
49mod region;
50mod script;
51mod variant;
52mod variants;
53
54#[doc(inline)]
55pub use language::{language, Language};
56#[doc(inline)]
57pub use region::{region, Region};
58#[doc(inline)]
59pub use script::{script, Script};
60#[doc(inline)]
61pub use variant::{variant, Variant};
62pub use variants::Variants;
63