Skip to content

Commit 832aa7c

Browse files
authored
Remove backward second level from the API (#6291)
The behavior is still available by loading fr-CA collation data. This was discussed in the context of #6033
1 parent 5b1d4f1 commit 832aa7c

26 files changed

+16
-397
lines changed

components/collator/src/options.rs

+5-47
Original file line numberDiff line numberDiff line change
@@ -225,20 +225,6 @@ pub enum CaseLevel {
225225
On = 1,
226226
}
227227

228-
/// Whether second level compares the last accent difference
229-
/// instead of the first accent difference.
230-
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
231-
#[repr(u8)]
232-
#[non_exhaustive]
233-
pub enum BackwardSecondLevel {
234-
/// Leave off the backward second level option. Diacritics in the second level will be ordered by
235-
/// default from beginning to end.
236-
Off = 0,
237-
/// Turn on backward second level ordering so that the second level compares backwards, starting
238-
/// from the last diacritic letter and moving towards the beginning.
239-
On = 1,
240-
}
241-
242228
/// Options settable by the user of the API.
243229
///
244230
/// With the exception of reordering (BCP47 `kr`), options that can by implied by locale are
@@ -283,17 +269,15 @@ pub enum BackwardSecondLevel {
283269
/// See the [spec](https://www.unicode.org/reports/tr35/tr35-collation.html#Case_Parameters).
284270
/// This is the BCP47 key `kc`. The default is [`CaseLevel::Off`].
285271
///
286-
/// ## Backward second level
287-
///
288-
/// Compare the second level in backward order. This is the BCP47 key `kb`. `kb`
289-
/// is prohibited by ECMA-402. The default is [`BackwardSecondLevel::Off`], except
290-
/// for Canadian French.
291-
///
292272
/// # Unsupported BCP47 options
293273
///
294274
/// Reordering (BCP47 `kr`) currently cannot be set via the API and is implied
295275
/// by the locale of the collation. `kr` is prohibited by ECMA-402.
296276
///
277+
/// Backward second level (BCP47 `kb`) cannot be set via the API and is implied
278+
/// by the locale of the collation (in practice only `fr-CA` turns it on and it's
279+
/// off otherwise). `kb` is prohibited by ECMA-402.
280+
///
297281
/// Normalization is always enabled and cannot be turned off. Therefore, there
298282
/// is no option corresponding to BCP47 `kk`. `kk` is prohibited by ECMA-402.
299283
///
@@ -330,8 +314,6 @@ pub struct CollatorOptions {
330314
pub max_variable: Option<MaxVariable>,
331315
/// User-specified case level collation option.
332316
pub case_level: Option<CaseLevel>,
333-
/// User-specified backward second level collation option.
334-
pub backward_second_level: Option<BackwardSecondLevel>,
335317
}
336318

337319
impl CollatorOptions {
@@ -342,7 +324,6 @@ impl CollatorOptions {
342324
alternate_handling: None,
343325
max_variable: None,
344326
case_level: None,
345-
backward_second_level: None,
346327
}
347328
}
348329
}
@@ -359,7 +340,6 @@ impl From<ResolvedCollatorOptions> for CollatorOptions {
359340
alternate_handling: Some(options.alternate_handling),
360341
max_variable: Some(options.max_variable),
361342
case_level: Some(options.case_level),
362-
backward_second_level: Some(options.backward_second_level),
363343
}
364344
}
365345
}
@@ -403,8 +383,6 @@ pub struct ResolvedCollatorOptions {
403383
pub case_level: CaseLevel,
404384
/// Resolved numeric collation option.
405385
pub numeric: CollationNumericOrdering,
406-
/// Resolved backward second level collation option.
407-
pub backward_second_level: BackwardSecondLevel,
408386
}
409387

410388
impl From<CollatorOptionsBitField> for ResolvedCollatorOptions {
@@ -424,11 +402,7 @@ impl From<CollatorOptionsBitField> for ResolvedCollatorOptions {
424402
} else {
425403
CollationNumericOrdering::False
426404
},
427-
backward_second_level: if options.backward_second_level() {
428-
BackwardSecondLevel::On
429-
} else {
430-
BackwardSecondLevel::Off
431-
},
405+
// `options.backward_second_level()` not exposed.
432406
}
433407
}
434408
}
@@ -660,21 +634,6 @@ impl CollatorOptionsBitField {
660634
}
661635
}
662636

663-
pub fn set_backward_second_level_from_enum(
664-
&mut self,
665-
backward_second_level: Option<BackwardSecondLevel>,
666-
) {
667-
match backward_second_level {
668-
Some(BackwardSecondLevel::On) => {
669-
self.set_backward_second_level(Some(true));
670-
}
671-
Some(BackwardSecondLevel::Off) => {
672-
self.set_backward_second_level(Some(false));
673-
}
674-
None => self.set_backward_second_level(None),
675-
}
676-
}
677-
678637
/// Whether sequences of decimal digits are compared according
679638
/// to their numeric value.
680639
pub fn numeric(self) -> bool {
@@ -784,7 +743,6 @@ impl From<CollatorOptions> for CollatorOptionsBitField {
784743
result.set_max_variable(options.max_variable);
785744
result.set_alternate_handling(options.alternate_handling);
786745
result.set_case_level_from_enum(options.case_level);
787-
result.set_backward_second_level_from_enum(options.backward_second_level);
788746
result
789747
}
790748
}

components/collator/tests/tests.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1605,10 +1605,8 @@ fn test_backward_second_level() {
16051605
}
16061606
}
16071607

1608-
options.backward_second_level = Some(BackwardSecondLevel::On);
1609-
16101608
{
1611-
let collator = Collator::try_new(Default::default(), options).unwrap();
1609+
let collator = Collator::try_new(locale!("fr-CA").into(), options).unwrap();
16121610

16131611
{
16141612
let cases = ["cote", "côte", "coté", "côté"];
@@ -1805,7 +1803,6 @@ fn test_default_resolved_options() {
18051803
assert_eq!(resolved.max_variable, MaxVariable::Punctuation);
18061804
assert_eq!(resolved.case_level, CaseLevel::Off);
18071805
assert_eq!(resolved.numeric, CollationNumericOrdering::False);
1808-
assert_eq!(resolved.backward_second_level, BackwardSecondLevel::Off);
18091806

18101807
assert_eq!(collator.compare("𝕒", "A"), core::cmp::Ordering::Less);
18111808
assert_eq!(collator.compare("coté", "côte"), core::cmp::Ordering::Less);
@@ -1822,7 +1819,6 @@ fn test_data_resolved_options_th() {
18221819
assert_eq!(resolved.max_variable, MaxVariable::Punctuation);
18231820
assert_eq!(resolved.case_level, CaseLevel::Off);
18241821
assert_eq!(resolved.numeric, CollationNumericOrdering::False);
1825-
assert_eq!(resolved.backward_second_level, BackwardSecondLevel::Off);
18261822

18271823
// There's a separate more comprehensive test for the shifted behavior
18281824
assert_eq!(collator.compare("𝕒", "A"), core::cmp::Ordering::Less);
@@ -1840,7 +1836,6 @@ fn test_data_resolved_options_da() {
18401836
assert_eq!(resolved.max_variable, MaxVariable::Punctuation);
18411837
assert_eq!(resolved.case_level, CaseLevel::Off);
18421838
assert_eq!(resolved.numeric, CollationNumericOrdering::False);
1843-
assert_eq!(resolved.backward_second_level, BackwardSecondLevel::Off);
18441839

18451840
assert_eq!(collator.compare("𝕒", "A"), core::cmp::Ordering::Greater);
18461841
assert_eq!(collator.compare("coté", "côte"), core::cmp::Ordering::Less);
@@ -1857,7 +1852,7 @@ fn test_data_resolved_options_fr_ca() {
18571852
assert_eq!(resolved.max_variable, MaxVariable::Punctuation);
18581853
assert_eq!(resolved.case_level, CaseLevel::Off);
18591854
assert_eq!(resolved.numeric, CollationNumericOrdering::False);
1860-
assert_eq!(resolved.backward_second_level, BackwardSecondLevel::On);
1855+
// bacward second level is hidden from the API
18611856

18621857
assert_eq!(collator.compare("𝕒", "A"), core::cmp::Ordering::Less);
18631858
assert_eq!(
@@ -1879,7 +1874,7 @@ fn test_manual_and_data_resolved_options_fr_ca() {
18791874
assert_eq!(resolved.max_variable, MaxVariable::Punctuation);
18801875
assert_eq!(resolved.case_level, CaseLevel::Off);
18811876
assert_eq!(resolved.numeric, CollationNumericOrdering::False);
1882-
assert_eq!(resolved.backward_second_level, BackwardSecondLevel::On);
1877+
// backwards second level is hidden from the API
18831878

18841879
assert_eq!(collator.compare("𝕒", "A"), core::cmp::Ordering::Greater);
18851880
assert_eq!(
@@ -1901,7 +1896,6 @@ fn test_manual_resolved_options_da() {
19011896
assert_eq!(resolved.max_variable, MaxVariable::Punctuation);
19021897
assert_eq!(resolved.case_level, CaseLevel::Off);
19031898
assert_eq!(resolved.numeric, CollationNumericOrdering::False);
1904-
assert_eq!(resolved.backward_second_level, BackwardSecondLevel::Off);
19051899

19061900
assert_eq!(collator.compare("𝕒", "A"), core::cmp::Ordering::Less);
19071901
assert_eq!(collator.compare("coté", "côte"), core::cmp::Ordering::Less);

ffi/capi/bindings/c/CollatorBackwardSecondLevel.d.h

-23
This file was deleted.

ffi/capi/bindings/c/CollatorBackwardSecondLevel.h

-23
This file was deleted.

ffi/capi/bindings/c/CollatorOptionsV1.d.h

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/capi/bindings/c/CollatorResolvedOptionsV1.d.h

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/capi/bindings/cpp/icu4x/CollatorBackwardSecondLevel.d.hpp

-50
This file was deleted.

ffi/capi/bindings/cpp/icu4x/CollatorBackwardSecondLevel.hpp

-38
This file was deleted.

ffi/capi/bindings/cpp/icu4x/CollatorOptionsV1.d.hpp

-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)