Skip to content

Commit 4c28a99

Browse files
New properties API (#5548)
1 parent b279bdc commit 4c28a99

File tree

189 files changed

+7188
-7970
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+7188
-7970
lines changed

components/casemap/src/titlecase.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use crate::provider::CaseMapV1Marker;
77
use crate::CaseMapper;
88
use alloc::string::String;
99
use icu_locale_core::LanguageIdentifier;
10-
use icu_properties::maps::CodePointMapData;
10+
use icu_properties::props::{GeneralCategory, GeneralCategoryGroup};
1111
use icu_properties::provider::GeneralCategoryV1Marker;
12-
use icu_properties::{GeneralCategory, GeneralCategoryGroup};
12+
use icu_properties::CodePointMapData;
1313
use icu_provider::prelude::*;
1414
use writeable::Writeable;
1515

@@ -221,7 +221,8 @@ impl TitlecaseMapper<CaseMapper> {
221221
pub const fn new() -> Self {
222222
Self {
223223
cm: CaseMapper::new(),
224-
gc: icu_properties::maps::general_category().static_to_owned(),
224+
gc: icu_properties::CodePointMapData::<icu_properties::props::GeneralCategory>::new()
225+
.static_to_owned(),
225226
}
226227
}
227228

@@ -240,7 +241,7 @@ impl TitlecaseMapper<CaseMapper> {
240241
P: DataProvider<CaseMapV1Marker> + DataProvider<GeneralCategoryV1Marker> + ?Sized,
241242
{
242243
let cm = CaseMapper::try_new_unstable(provider)?;
243-
let gc = icu_properties::maps::load_general_category(provider)?;
244+
let gc = icu_properties::CodePointMapData::<icu_properties::props::GeneralCategory>::try_new_unstable(provider)?;
244245
Ok(Self { cm, gc })
245246
}
246247
}
@@ -266,7 +267,8 @@ impl<CM: AsRef<CaseMapper>> TitlecaseMapper<CM> {
266267
pub const fn new_with_mapper(casemapper: CM) -> Self {
267268
Self {
268269
cm: casemapper,
269-
gc: icu_properties::maps::general_category().static_to_owned(),
270+
gc: icu_properties::CodePointMapData::<icu_properties::props::GeneralCategory>::new()
271+
.static_to_owned(),
270272
}
271273
}
272274

@@ -276,7 +278,7 @@ impl<CM: AsRef<CaseMapper>> TitlecaseMapper<CM> {
276278
where
277279
P: DataProvider<CaseMapV1Marker> + DataProvider<GeneralCategoryV1Marker> + ?Sized,
278280
{
279-
let gc = icu_properties::maps::load_general_category(provider)?;
281+
let gc = icu_properties::CodePointMapData::<icu_properties::props::GeneralCategory>::try_new_unstable(provider)?;
280282
Ok(Self { cm: casemapper, gc })
281283
}
282284

components/casemap/tests/gen_greek_to_me.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ use icu_casemap::greek_to_me::{
77
};
88
use icu_casemap::CaseMapper;
99
use icu_normalizer::DecomposingNormalizerBorrowed;
10-
use icu_properties::{maps, GeneralCategoryGroup, Script};
10+
use icu_properties::{
11+
props::{GeneralCategory, GeneralCategoryGroup, Script},
12+
CodePointMapData,
13+
};
1114
use std::collections::BTreeMap;
1215
use std::fmt::Write;
1316

1417
fn main() {
1518
let decomposer = DecomposingNormalizerBorrowed::new_nfd();
16-
let script = maps::script();
17-
let gc = maps::general_category();
19+
let script = CodePointMapData::<Script>::new();
20+
let gc = CodePointMapData::<GeneralCategory>::new();
1821
let cm = CaseMapper::new();
1922

2023
let mut vec_370 = vec![0; 0x400 - 0x370];

components/collator/src/elements.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use icu_collections::char16trie::TrieResult;
2323
use icu_collections::codepointtrie::CodePointTrie;
2424
use icu_normalizer::provider::DecompositionDataV1;
2525
use icu_normalizer::provider::DecompositionTablesV1;
26-
use icu_properties::CanonicalCombiningClass;
26+
use icu_properties::props::CanonicalCombiningClass;
2727
use smallvec::SmallVec;
2828
use zerovec::ule::AsULE;
2929
use zerovec::ule::RawBytesULE;

components/collections/src/iterator_utils.rs

Lines changed: 80 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,18 @@ where
6262
mod tests {
6363
use core::fmt::Debug;
6464
use icu::collections::codepointinvlist::CodePointInversionListBuilder;
65-
use icu::collections::codepointtrie::TrieValue;
66-
use icu::properties::maps::{self, CodePointMapDataBorrowed};
67-
use icu::properties::sets::{self, CodePointSetDataBorrowed};
68-
use icu::properties::{GeneralCategory, Script};
65+
use icu::properties::props::{BinaryProperty, EnumeratedProperty};
66+
use icu::properties::{CodePointMapData, CodePointSetData};
6967

70-
fn test_set(data: CodePointSetDataBorrowed<'static>, name: &str) {
68+
fn test_set<P: BinaryProperty>(name: &str) {
7169
let mut builder = CodePointInversionListBuilder::new();
7270
let mut builder_complement = CodePointInversionListBuilder::new();
7371

74-
for range in data.iter_ranges() {
72+
for range in CodePointSetData::new::<P>().iter_ranges() {
7573
builder.add_range32(range)
7674
}
7775

78-
for range in data.iter_ranges_complemented() {
76+
for range in CodePointSetData::new::<P>().iter_ranges_complemented() {
7977
builder_complement.add_range32(range)
8078
}
8179

@@ -85,19 +83,15 @@ mod tests {
8583
assert_eq!(set1, set2, "Set {name} failed to complement correctly");
8684
}
8785

88-
fn test_map<T: TrieValue + Debug>(
89-
data: &CodePointMapDataBorrowed<'static, T>,
90-
value: T,
91-
name: &str,
92-
) {
86+
fn test_map<T: EnumeratedProperty + Debug>(value: T, name: &str) {
9387
let mut builder = CodePointInversionListBuilder::new();
9488
let mut builder_complement = CodePointInversionListBuilder::new();
9589

96-
for range in data.iter_ranges_for_value(value) {
90+
for range in CodePointMapData::<T>::new().iter_ranges_for_value(value) {
9791
builder.add_range32(range)
9892
}
9993

100-
for range in data.iter_ranges_for_value_complemented(value) {
94+
for range in CodePointMapData::<T>::new().iter_ranges_for_value_complemented(value) {
10195
builder_complement.add_range32(range)
10296
}
10397

@@ -112,95 +106,83 @@ mod tests {
112106

113107
#[test]
114108
fn test_complement_sets() {
109+
use icu::properties::props::*;
115110
// Stress test the RangeListIteratorComplementer logic by ensuring it works for
116111
// a whole bunch of binary properties
117-
test_set(sets::ascii_hex_digit(), "ASCII_Hex_Digit");
118-
test_set(sets::alnum(), "Alnum");
119-
test_set(sets::alphabetic(), "Alphabetic");
120-
test_set(sets::bidi_control(), "Bidi_Control");
121-
test_set(sets::bidi_mirrored(), "Bidi_Mirrored");
122-
test_set(sets::blank(), "Blank");
123-
test_set(sets::cased(), "Cased");
124-
test_set(sets::case_ignorable(), "Case_Ignorable");
125-
test_set(
126-
sets::full_composition_exclusion(),
127-
"Full_Composition_Exclusion",
128-
);
129-
test_set(sets::changes_when_casefolded(), "Changes_When_Casefolded");
130-
test_set(sets::changes_when_casemapped(), "Changes_When_Casemapped");
131-
test_set(
132-
sets::changes_when_nfkc_casefolded(),
133-
"Changes_When_NFKC_Casefolded",
134-
);
135-
test_set(sets::changes_when_lowercased(), "Changes_When_Lowercased");
136-
test_set(sets::changes_when_titlecased(), "Changes_When_Titlecased");
137-
test_set(sets::changes_when_uppercased(), "Changes_When_Uppercased");
138-
test_set(sets::dash(), "Dash");
139-
test_set(sets::deprecated(), "Deprecated");
140-
test_set(
141-
sets::default_ignorable_code_point(),
142-
"Default_Ignorable_Code_Point",
143-
);
144-
test_set(sets::diacritic(), "Diacritic");
145-
test_set(sets::emoji_modifier_base(), "Emoji_Modifier_Base");
146-
test_set(sets::emoji_component(), "Emoji_Component");
147-
test_set(sets::emoji_modifier(), "Emoji_Modifier");
148-
test_set(sets::emoji(), "Emoji");
149-
test_set(sets::emoji_presentation(), "Emoji_Presentation");
150-
test_set(sets::extender(), "Extender");
151-
test_set(sets::extended_pictographic(), "Extended_Pictographic");
152-
test_set(sets::graph(), "Graph");
153-
test_set(sets::grapheme_base(), "Grapheme_Base");
154-
test_set(sets::grapheme_extend(), "Grapheme_Extend");
155-
test_set(sets::grapheme_link(), "Grapheme_Link");
156-
test_set(sets::hex_digit(), "Hex_Digit");
157-
test_set(sets::hyphen(), "Hyphen");
158-
test_set(sets::id_continue(), "Id_Continue");
159-
test_set(sets::ideographic(), "Ideographic");
160-
test_set(sets::id_start(), "Id_Start");
161-
test_set(sets::ids_binary_operator(), "Ids_Binary_Operator");
162-
test_set(sets::ids_trinary_operator(), "Ids_Trinary_Operator");
163-
test_set(sets::join_control(), "Join_Control");
164-
test_set(sets::logical_order_exception(), "Logical_Order_Exception");
165-
test_set(sets::lowercase(), "Lowercase");
166-
test_set(sets::math(), "Math");
167-
test_set(sets::noncharacter_code_point(), "Noncharacter_Code_Point");
168-
test_set(sets::nfc_inert(), "NFC_Inert");
169-
test_set(sets::nfd_inert(), "NFD_Inert");
170-
test_set(sets::nfkc_inert(), "NFKC_Inert");
171-
test_set(sets::nfkd_inert(), "NFKD_Inert");
172-
test_set(sets::pattern_syntax(), "Pattern_Syntax");
173-
test_set(sets::pattern_white_space(), "Pattern_White_Space");
174-
test_set(
175-
sets::prepended_concatenation_mark(),
176-
"Prepended_Concatenation_Mark",
177-
);
178-
test_set(sets::print(), "Print");
179-
test_set(sets::quotation_mark(), "Quotation_Mark");
180-
test_set(sets::radical(), "Radical");
181-
test_set(sets::regional_indicator(), "Regional_Indicator");
182-
test_set(sets::soft_dotted(), "Soft_Dotted");
183-
test_set(sets::segment_starter(), "Segment_Starter");
184-
test_set(sets::case_sensitive(), "Case_Sensitive");
185-
test_set(sets::sentence_terminal(), "Sentence_Terminal");
186-
test_set(sets::terminal_punctuation(), "Terminal_Punctuation");
187-
test_set(sets::unified_ideograph(), "Unified_Ideograph");
188-
test_set(sets::uppercase(), "Uppercase");
189-
test_set(sets::variation_selector(), "Variation_Selector");
190-
test_set(sets::white_space(), "White_Space");
191-
test_set(sets::xdigit(), "Xdigit");
192-
test_set(sets::xid_continue(), "XID_Continue");
193-
test_set(sets::xid_start(), "XID_Start");
112+
test_set::<AsciiHexDigit>("ASCII_Hex_Digit");
113+
test_set::<Alnum>("Alnum");
114+
test_set::<Alphabetic>("Alphabetic");
115+
test_set::<BidiControl>("Bidi_Control");
116+
test_set::<BidiMirrored>("Bidi_Mirrored");
117+
test_set::<Blank>("Blank");
118+
test_set::<Cased>("Cased");
119+
test_set::<CaseIgnorable>("Case_Ignorable");
120+
test_set::<FullCompositionExclusion>("Full_Composition_Exclusion");
121+
test_set::<ChangesWhenCasefolded>("Changes_When_Casefolded");
122+
test_set::<ChangesWhenCasemapped>("Changes_When_Casemapped");
123+
test_set::<ChangesWhenNfkcCasefolded>("Changes_When_NFKC_Casefolded");
124+
test_set::<ChangesWhenLowercased>("Changes_When_Lowercased");
125+
test_set::<ChangesWhenTitlecased>("Changes_When_Titlecased");
126+
test_set::<ChangesWhenUppercased>("Changes_When_Uppercased");
127+
test_set::<Dash>("Dash");
128+
test_set::<Deprecated>("Deprecated");
129+
test_set::<DefaultIgnorableCodePoint>("Default_Ignorable_Code_Point");
130+
test_set::<Diacritic>("Diacritic");
131+
test_set::<EmojiModifierBase>("Emoji_Modifier_Base");
132+
test_set::<EmojiComponent>("Emoji_Component");
133+
test_set::<EmojiModifier>("Emoji_Modifier");
134+
test_set::<Emoji>("Emoji");
135+
test_set::<EmojiPresentation>("Emoji_Presentation");
136+
test_set::<Extender>("Extender");
137+
test_set::<ExtendedPictographic>("Extended_Pictographic");
138+
test_set::<Graph>("Graph");
139+
test_set::<GraphemeBase>("Grapheme_Base");
140+
test_set::<GraphemeExtend>("Grapheme_Extend");
141+
test_set::<GraphemeLink>("Grapheme_Link");
142+
test_set::<HexDigit>("Hex_Digit");
143+
test_set::<Hyphen>("Hyphen");
144+
test_set::<IdContinue>("Id_Continue");
145+
test_set::<Ideographic>("Ideographic");
146+
test_set::<IdStart>("Id_Start");
147+
test_set::<IdsBinaryOperator>("Ids_Binary_Operator");
148+
test_set::<IdsTrinaryOperator>("Ids_Trinary_Operator");
149+
test_set::<JoinControl>("Join_Control");
150+
test_set::<LogicalOrderException>("Logical_Order_Exception");
151+
test_set::<Lowercase>("Lowercase");
152+
test_set::<Math>("Math");
153+
test_set::<NoncharacterCodePoint>("Noncharacter_Code_Point");
154+
test_set::<NfcInert>("NFC_Inert");
155+
test_set::<NfdInert>("NFD_Inert");
156+
test_set::<NfkcInert>("NFKC_Inert");
157+
test_set::<NfkdInert>("NFKD_Inert");
158+
test_set::<PatternSyntax>("Pattern_Syntax");
159+
test_set::<PatternWhiteSpace>("Pattern_White_Space");
160+
test_set::<PrependedConcatenationMark>("Prepended_Concatenation_Mark");
161+
test_set::<Print>("Print");
162+
test_set::<QuotationMark>("Quotation_Mark");
163+
test_set::<Radical>("Radical");
164+
test_set::<RegionalIndicator>("Regional_Indicator");
165+
test_set::<SoftDotted>("Soft_Dotted");
166+
test_set::<SegmentStarter>("Segment_Starter");
167+
test_set::<CaseSensitive>("Case_Sensitive");
168+
test_set::<SentenceTerminal>("Sentence_Terminal");
169+
test_set::<TerminalPunctuation>("Terminal_Punctuation");
170+
test_set::<UnifiedIdeograph>("Unified_Ideograph");
171+
test_set::<Uppercase>("Uppercase");
172+
test_set::<VariationSelector>("Variation_Selector");
173+
test_set::<WhiteSpace>("White_Space");
174+
test_set::<Xdigit>("Xdigit");
175+
test_set::<XidContinue>("XID_Continue");
176+
test_set::<XidStart>("XID_Start");
194177
}
195178

196179
#[test]
197180
fn test_complement_maps() {
198-
let gc = maps::general_category();
199-
let script = maps::script();
200-
test_map(&gc, GeneralCategory::UppercaseLetter, "gc");
201-
test_map(&gc, GeneralCategory::OtherPunctuation, "gc");
202-
test_map(&script, Script::Devanagari, "script");
203-
test_map(&script, Script::Latin, "script");
204-
test_map(&script, Script::Common, "script");
181+
use icu::properties::props::{GeneralCategory, Script};
182+
test_map(GeneralCategory::UppercaseLetter, "gc");
183+
test_map(GeneralCategory::OtherPunctuation, "gc");
184+
test_map(Script::Devanagari, "script");
185+
test_map(Script::Latin, "script");
186+
test_map(Script::Common, "script");
205187
}
206188
}

components/experimental/src/personnames/formatter.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
use alloc::string::String;
66
use alloc::vec::Vec;
77
use icu_locale::LocaleFallbacker;
8-
use icu_properties::names::PropertyScriptToIcuScriptMapper;
9-
use icu_properties::script::ScriptWithExtensions;
8+
use icu_properties::script::{ScriptMapper, ScriptWithExtensions};
109

1110
use super::api::{
1211
FormattingOrder, NameField, NameFieldKind, PersonName, PersonNamesFormatterError,
@@ -24,7 +23,7 @@ use zerofrom::ZeroFrom;
2423
pub struct PersonNamesFormatter {
2524
pub(crate) default_options: PersonNamesFormatterOptions,
2625
swe: ScriptWithExtensions,
27-
scripts: PropertyScriptToIcuScriptMapper<icu_properties::Script>,
26+
scripts: ScriptMapper,
2827
fallbacker: LocaleFallbacker,
2928
}
3029

@@ -49,8 +48,8 @@ impl PersonNamesFormatter {
4948
+ DataProvider<icu_locale::provider::LikelySubtagsForLanguageV1Marker>
5049
+ DataProvider<icu_locale::provider::ParentsV1Marker>,
5150
{
52-
let swe = icu_properties::script::load_script_with_extensions_unstable(provider)?;
53-
let scripts = icu_properties::Script::get_enum_to_icu_script_mapper(provider)?;
51+
let swe = icu_properties::script::ScriptWithExtensions::try_new_unstable(provider)?;
52+
let scripts = ScriptMapper::try_new_unstable(provider)?;
5453
let fallbacker = LocaleFallbacker::try_new_unstable(provider)?;
5554
Ok(PersonNamesFormatter {
5655
default_options: options,

components/experimental/src/personnames/specifications/derive_locale.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
use icu_locale_core::subtags::script;
66
use icu_locale_core::{subtags, Locale};
7-
use icu_properties::names::PropertyScriptToIcuScriptMapperBorrowed;
8-
use icu_properties::script::ScriptWithExtensionsBorrowed;
7+
use icu_properties::script::{ScriptMapperBorrowed, ScriptWithExtensionsBorrowed};
98

109
use crate::personnames::api::NameFieldKind::{Given, Surname};
1110
use crate::personnames::api::{NameFieldKind, PersonName, PersonNamesFormatterError};
@@ -45,7 +44,7 @@ fn compatible_scripts(sc1: subtags::Script, sc2: subtags::Script) -> bool {
4544
pub fn likely_person_name_locale<N>(
4645
person_name: &N,
4746
swe: ScriptWithExtensionsBorrowed,
48-
scripts: PropertyScriptToIcuScriptMapperBorrowed<icu_properties::Script>,
47+
scripts: ScriptMapperBorrowed,
4948
) -> Result<Locale, PersonNamesFormatterError>
5049
where
5150
N: PersonName,
@@ -54,14 +53,9 @@ where
5453
if found_name_script.is_none() {
5554
found_name_script = find_script(person_name, swe, Given);
5655
}
57-
let name_script = found_name_script.unwrap_or(icu_properties::Script::Unknown);
58-
59-
let locid_script = scripts
60-
.get(name_script)
61-
.unwrap()
62-
.as_str()
63-
.parse::<subtags::Script>()
64-
.map_err(|_err| PersonNamesFormatterError::InvalidPersonName)?;
56+
let name_script = found_name_script.unwrap_or(icu_properties::props::Script::Unknown);
57+
58+
let locid_script = scripts.get(name_script).unwrap();
6559
person_name.name_locale().map_or_else(
6660
|| {
6761
let mut effective_locale = Locale::default();
@@ -80,11 +74,11 @@ fn find_script<N>(
8074
person_name: &N,
8175
swe: ScriptWithExtensionsBorrowed,
8276
kind: NameFieldKind,
83-
) -> Option<icu_properties::Script>
77+
) -> Option<icu_properties::props::Script>
8478
where
8579
N: PersonName,
8680
{
87-
use icu_properties::Script;
81+
use icu_properties::props::Script;
8882

8983
person_name
9084
.available_name_fields()
@@ -176,8 +170,8 @@ mod tests {
176170

177171
#[test]
178172
fn test_likely_person_names_locale() {
179-
let swe = icu_properties::script::script_with_extensions();
180-
let scripts = icu_properties::Script::enum_to_icu_script_mapper();
173+
let swe = icu_properties::script::ScriptWithExtensions::new();
174+
let scripts = icu_properties::script::ScriptMapper::new();
181175
assert_eq!(
182176
likely_person_name_locale(&person_name("Miyazaki", "Hayao").unwrap(), swe, scripts),
183177
Ok(locale!("und_Latn"))

0 commit comments

Comments
 (0)