1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

//! This module provides APIs for getting exemplar characters for a locale.
//!
//! Exemplars are characters used by a language, separated into different sets.
//! The sets are: main, auxiliary, punctuation, numbers, and index.
//!
//! The sets define, according to typical usage in the language,
//! which characters occur in which contexts with which frequency.
//! For more information, see the documentation in the
//! [Exemplars section in Unicode Technical Standard #35](https://unicode.org/reports/tr35/tr35-general.html#Exemplars)
//! of the LDML specification.
//!
//! # Examples
//!
//! ```
//! use icu::locid::locale;
//! use icu::properties::exemplar_chars;
//!
//! let locale = locale!("en-001").into();
//! let data = exemplar_chars::exemplars_main(&locale)
//!     .expect("locale should be present");
//! let exemplars_main = data.as_borrowed();
//!
//! assert!(exemplars_main.contains_char('a'));
//! assert!(exemplars_main.contains_char('z'));
//! assert!(exemplars_main.contains("a"));
//! assert!(!exemplars_main.contains("รค"));
//! assert!(!exemplars_main.contains("ng"));
//! ```

use crate::provider::*;
use crate::sets::UnicodeSetData;
use crate::PropertiesError;
use icu_provider::prelude::*;

macro_rules! make_exemplar_chars_unicode_set_property {
    (
        // currently unused
        marker: $marker_name:ident;
        keyed_data_marker: $keyed_data_marker:ty;
        func:
        $vis:vis fn $funcname:ident();
        $(#[$attr:meta])*
        $vis2:vis fn $constname:ident();
    ) => {
        #[doc = concat!("A version of [`", stringify!($constname), "()`] that uses custom data provided by a [`DataProvider`].")]
        ///
        /// [๐Ÿ“š Help choosing a constructor](icu_provider::constructors)
        $vis fn $funcname(
            provider: &(impl DataProvider<$keyed_data_marker> + ?Sized),
            locale: &DataLocale,
        ) -> Result<UnicodeSetData, PropertiesError> {
            Ok(provider.load(
                DataRequest {
                    locale,
                    metadata: Default::default(),
                })
                .and_then(DataResponse::take_payload)
                .map(UnicodeSetData::from_data)?
            )
        }
        $(#[$attr])*
        #[cfg(feature = "compiled_data")]
        $vis2 fn $constname(
            locale: &DataLocale,
        ) -> Result<UnicodeSetData, PropertiesError> {
            Ok(UnicodeSetData::from_data(
                DataProvider::<$keyed_data_marker>::load(
                    &crate::provider::Baked,
                    DataRequest {
                        locale,
                        metadata: Default::default(),
                    })
                    .and_then(DataResponse::take_payload)?
            ))
        }
    }
}

make_exemplar_chars_unicode_set_property!(
    marker: ExemplarCharactersMain;
    keyed_data_marker: ExemplarCharactersMainV1Marker;
    func:
    pub fn load_exemplars_main();

    /// Get the "main" set of exemplar characters.
    ///
    /// โœจ *Enabled with the `compiled_data` Cargo feature.*
    ///
    /// [๐Ÿ“š Help choosing a constructor](icu_provider::constructors)
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::locid::locale;
    /// use icu::properties::exemplar_chars;
    ///
    /// let data = exemplar_chars::exemplars_main(&locale!("en").into())
    ///     .expect("locale should be present");
    /// let exemplars_main = data.as_borrowed();
    ///
    /// assert!(exemplars_main.contains_char('a'));
    /// assert!(exemplars_main.contains_char('z'));
    /// assert!(exemplars_main.contains("a"));
    /// assert!(!exemplars_main.contains("รค"));
    /// assert!(!exemplars_main.contains("ng"));
    /// assert!(!exemplars_main.contains("A"));
    /// ```
    pub fn exemplars_main();
);

make_exemplar_chars_unicode_set_property!(
    marker: ExemplarCharactersAuxiliary;
    keyed_data_marker: ExemplarCharactersAuxiliaryV1Marker;
    func:
    pub fn load_exemplars_auxiliary();

    /// Get the "auxiliary" set of exemplar characters.
    ///
    /// โœจ *Enabled with the `compiled_data` Cargo feature.*
    ///
    /// [๐Ÿ“š Help choosing a constructor](icu_provider::constructors)
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::locid::locale;
    /// use icu::properties::exemplar_chars;
    ///
    /// let data =
    ///     exemplar_chars::exemplars_auxiliary(&locale!("en").into())
    ///     .expect("locale should be present");
    /// let exemplars_auxiliary = data.as_borrowed();
    ///
    /// assert!(!exemplars_auxiliary.contains_char('a'));
    /// assert!(!exemplars_auxiliary.contains_char('z'));
    /// assert!(!exemplars_auxiliary.contains("a"));
    /// assert!(exemplars_auxiliary.contains("รค"));
    /// assert!(!exemplars_auxiliary.contains("ng"));
    /// assert!(!exemplars_auxiliary.contains("A"));
    /// ```
    pub fn exemplars_auxiliary();
);

make_exemplar_chars_unicode_set_property!(
    marker: ExemplarCharactersPunctuation;
    keyed_data_marker: ExemplarCharactersPunctuationV1Marker;
    func:
    pub fn load_exemplars_punctuation();

    /// Get the "punctuation" set of exemplar characters.
    ///
    /// โœจ *Enabled with the `compiled_data` Cargo feature.*
    ///
    /// [๐Ÿ“š Help choosing a constructor](icu_provider::constructors)
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::locid::locale;
    /// use icu::properties::exemplar_chars;
    ///
    /// let data =
    ///     exemplar_chars::exemplars_punctuation(&locale!("en").into())
    ///     .expect("locale should be present");
    /// let exemplars_punctuation = data.as_borrowed();
    ///
    /// assert!(!exemplars_punctuation.contains_char('0'));
    /// assert!(!exemplars_punctuation.contains_char('9'));
    /// assert!(!exemplars_punctuation.contains_char('%'));
    /// assert!(exemplars_punctuation.contains_char(','));
    /// assert!(exemplars_punctuation.contains_char('.'));
    /// assert!(exemplars_punctuation.contains_char('!'));
    /// assert!(exemplars_punctuation.contains_char('?'));
    /// ```
    pub fn exemplars_punctuation();
);

make_exemplar_chars_unicode_set_property!(
    marker: ExemplarCharactersNumbers;
    keyed_data_marker: ExemplarCharactersNumbersV1Marker;
    func:
    pub fn load_exemplars_numbers();

    /// Get the "numbers" set of exemplar characters.
    ///
    /// โœจ *Enabled with the `compiled_data` Cargo feature.*
    ///
    /// [๐Ÿ“š Help choosing a constructor](icu_provider::constructors)
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::locid::locale;
    /// use icu::properties::exemplar_chars;
    ///
    /// let data =
    ///     exemplar_chars::exemplars_numbers(&locale!("en").into())
    ///     .expect("locale should be present");
    /// let exemplars_numbers = data.as_borrowed();
    ///
    /// assert!(exemplars_numbers.contains_char('0'));
    /// assert!(exemplars_numbers.contains_char('9'));
    /// assert!(exemplars_numbers.contains_char('%'));
    /// assert!(exemplars_numbers.contains_char(','));
    /// assert!(exemplars_numbers.contains_char('.'));
    /// assert!(!exemplars_numbers.contains_char('!'));
    /// assert!(!exemplars_numbers.contains_char('?'));
    /// ```
    pub fn exemplars_numbers();
);

make_exemplar_chars_unicode_set_property!(
    marker: ExemplarCharactersIndex;
    keyed_data_marker: ExemplarCharactersIndexV1Marker;
    func:
    pub fn load_exemplars_index();

    /// Get the "index" set of exemplar characters.
    ///
    /// โœจ *Enabled with the `compiled_data` Cargo feature.*
    ///
    /// [๐Ÿ“š Help choosing a constructor](icu_provider::constructors)
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::locid::locale;
    /// use icu::properties::exemplar_chars;
    ///
    /// let data =
    ///     exemplar_chars::exemplars_index(&locale!("en").into())
    ///     .expect("locale should be present");
    /// let exemplars_index = data.as_borrowed();
    ///
    /// assert!(!exemplars_index.contains_char('a'));
    /// assert!(!exemplars_index.contains_char('z'));
    /// assert!(!exemplars_index.contains("a"));
    /// assert!(!exemplars_index.contains("รค"));
    /// assert!(!exemplars_index.contains("ng"));
    /// assert!(exemplars_index.contains("A"));
    /// ```
    pub fn exemplars_index();
);