Skip to main content

icu_locale_core/preferences/extensions/unicode/keywords/
dictionary_break.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::extensions::unicode::Value;
6use crate::preferences::extensions::unicode::errors::PreferencesParseError;
7use crate::preferences::extensions::unicode::struct_keyword;
8use crate::subtags::Script;
9use alloc::vec::Vec;
10use core::str::FromStr;
11
12struct_keyword!(
13    /// A Unicode Dictionary Break Exclusion Identifier specifies
14    /// scripts to be excluded from dictionary-based text break (for words and lines).
15    ///
16    /// The valid values are of one or more items of type [`Script`](crate::subtags::Script).
17    ///
18    /// ✨ *Enabled with the `alloc` Cargo feature.*
19    DictionaryBreakScriptExclusions,
20    "dx",
21    Vec<Script>,
22    |input: &Value| {
23        input
24            .as_subtags_slice()
25            .iter()
26            .map(|s| {
27                Script::from_str(s.as_str()).map_err(|_| PreferencesParseError::InvalidKeywordValue)
28            })
29            .collect::<Result<_, _>>()
30            .map(Self)
31    },
32    |input: &DictionaryBreakScriptExclusions| {
33        input.0.iter().copied().map(Into::into).collect()
34    }
35);