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 tinystr::TinyAsciiStr;
6
7use crate::extensions::{self, Extensions};
8use crate::parser::errors::ParserError;
9use crate::parser::{parse_language_identifier_from_iter, ParserMode, SubtagIterator};
10use crate::{subtags, Locale};
11
12use super::parse_locale_with_single_variant_single_keyword_unicode_extension_from_iter;
13
14pub fn parse_locale(t: &[u8]) -> Result<Locale, ParserError> {
15 let mut iter: SubtagIterator<'_> = SubtagIterator::new(slice:t);
16
17 let id: LanguageIdentifier = parse_language_identifier_from_iter(&mut iter, mode:ParserMode::Locale)?;
18 let extensions: Extensions = if iter.peek().is_some() {
19 Extensions::try_from_iter(&mut iter)?
20 } else {
21 Extensions::default()
22 };
23 Ok(Locale { id, extensions })
24}
25
26#[allow(clippy::type_complexity)]
27pub const fn parse_locale_with_single_variant_single_keyword_unicode_keyword_extension(
28 t: &[u8],
29 mode: ParserMode,
30) -> Result<
31 (
32 subtags::Language,
33 Option<subtags::Script>,
34 Option<subtags::Region>,
35 Option<subtags::Variant>,
36 Option<(extensions::unicode::Key, Option<TinyAsciiStr<8>>)>,
37 ),
38 ParserError,
39> {
40 let iter: SubtagIterator<'_> = SubtagIterator::new(slice:t);
41 parse_locale_with_single_variant_single_keyword_unicode_extension_from_iter(iter, mode)
42}
43