unic-langid
is an API for managing Unicode Language Identifiers.
The crate provides a way to create a struct from a string, manipulate its fields, canonicalize it, and serialize into a string.
```rust use unic_langid::LanguageIdentifier;
let loc: LanguageIdentifier = "en-US".parse().expect("Parsing failed.");
asserteq!(loc.getlanguage(), "en"); asserteq!(loc.getscript(), None); asserteq!(loc.getregion(), Some("US"));
loc.set_script(Some("latn"));
asserteq!(&loc.tostring(), "en-Latn-US"); ```
```rust use unic_langid::LanguageIdentifier;
let langid = LanguageIdentifier::from_parts( Some("en"), None, None, Some(&["nedis", "macos"]) ).expect("Parsing failed.");
asserteq!(&langid.tostring(), "en-macos-nedis") ```
unic-langid
can be also compiled with features = ["macros"]
which enables langid!
macro:
```rust use unic_langid::langid;
let lang = langid!("en-US");
asserteq!(&langid.tostring(), "en-US") ```
The macro allows for compile-time parsing and validation of literal language identifiers.
The crate is providing fundamental blocks, but is very basic.
In particular, a lot can be done to improve performance and memory usage.
unic-langid
is open-source, licensed under the Apache License, Version 2.0. We
encourage everyone to take a look at our code and we'll listen to your
feedback.