#tags #language #validation #normalization #bcp47 #rdf #zero-allocation

no-std oxilangtag

Simple and fast implementation of language tag normalization and validation

4 releases

0.1.5 Mar 10, 2024
0.1.4 Mar 4, 2024
0.1.3 Mar 26, 2022
0.1.2 Apr 16, 2021
0.1.0 May 1, 2020

#174 in Encoding

Download history 3316/week @ 2024-07-22 4730/week @ 2024-07-29 3739/week @ 2024-08-05 4087/week @ 2024-08-12 3490/week @ 2024-08-19 5004/week @ 2024-08-26 3962/week @ 2024-09-02 4204/week @ 2024-09-09 4117/week @ 2024-09-16 3111/week @ 2024-09-23 3266/week @ 2024-09-30 3284/week @ 2024-10-07 3597/week @ 2024-10-14 4670/week @ 2024-10-21 4667/week @ 2024-10-28 3714/week @ 2024-11-04

16,795 downloads per month
Used in 139 crates (20 directly)

MIT license

33KB
688 lines

oxilangtag

actions status Latest Version Released API docs

OxiLangTag is a Rust library allowing to validate and normalize language tags following RFC 5646 (BCP 47).

It is a fork of the language-tags focusing on RDF use cases. You might find the language-tags crate more convenient.

It allows zero stack allocation language tag validation. Getters are also provided to easily retrieve the various language tag components.

If serde is available, LanguageTag implements the Serialize and Deserialize traits and encodes the language tag as a string.

Example:

use oxilangtag::LanguageTag;

// Parsing and validation
let language_tag = LanguageTag::parse("zh-cmn-Hans-CN-x-test").unwrap();
assert_eq!(language_tag.as_str(), "zh-cmn-Hans-CN-x-test");

// Language tag components
assert_eq!(language_tag.primary_language(), "zh");
assert_eq!(language_tag.extended_language(), Some("cmn"));
assert_eq!(language_tag.full_language(), "zh-cmn");
assert_eq!(language_tag.script(), Some("Hans"));
assert_eq!(language_tag.region(), Some("CN"));
assert_eq!(language_tag.extension(), None);
assert_eq!(language_tag.private_use_subtags().collect::<Vec<_>>(), vec!["test"]);

It is also possible to use this crate in no_std (with alloc) by opting-out of the default std feature:

serde = { version = "*", default-features = false }

License

This project is licensed under the MIT license (LICENSE-MIT or <http://opensource.org/licenses/MIT>).

It is based on the language-tags crate by pyfisch under MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Oxilangtag by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~160KB