icu_locale_core/preferences/extensions/unicode/keywords/currency.rs
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
5use crate::preferences::extensions::unicode::errors::PreferencesParseError;
6use crate::preferences::extensions::unicode::struct_keyword;
7use crate::{extensions::unicode::Value, subtags::Subtag};
8use tinystr::TinyAsciiStr;
9
10struct_keyword!(
11 /// A Unicode Currency Identifier defines a type of currency.
12 ///
13 /// The valid values are listed in [LDML](https://unicode.org/reports/tr35/#UnicodeCurrencyIdentifier).
14 CurrencyType,
15 "cu",
16 TinyAsciiStr<3>,
17 |input: Value| {
18 if let Some(subtag) = input.into_single_subtag() {
19 let ts = subtag.as_tinystr();
20 if ts.len() == 3 && ts.is_ascii_alphabetic() {
21 return Ok(Self(ts.resize()));
22 }
23 }
24 Err(PreferencesParseError::InvalidKeywordValue)
25 },
26 |input: CurrencyType| {
27 crate::extensions::unicode::Value::from_subtag(Some(
28 Subtag::from_tinystr_unvalidated(input.0.resize()),
29 ))
30 }
31);