Skip to content

Commit 8f7772b

Browse files
committed
testing collation
1 parent 280fa6a commit 8f7772b

File tree

5 files changed

+12
-78
lines changed

5 files changed

+12
-78
lines changed

pkgs/intl4x/lib/src/collation/collation_4x.dart

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,22 @@ CollationImpl getCollator4X(
1919
class Collation4X extends CollationImpl {
2020
final icu.Collator _collator;
2121

22-
Collation4X(super.locale, Data data, super.options)
23-
: _collator = icu.Collator(
24-
data.to4X(),
25-
locale.to4X(),
26-
options.to4xOptions(),
27-
);
22+
Collation4X(super.locale, Data? data, super.options)
23+
: _collator =
24+
data != null
25+
? icu.Collator.createWithProvider(
26+
data.to4X(),
27+
locale.to4X(),
28+
options.to4xOptions(),
29+
)
30+
: icu.Collator(locale.to4X(), options.to4xOptions());
2831

2932
@override
3033
int compareImpl(String a, String b) => _collator.compare(a, b);
3134
}
3235

3336
extension on CollationOptions {
3437
icu.CollatorOptions to4xOptions() {
35-
final icuNumeric =
36-
numeric ? icu.CollatorNumeric.on : icu.CollatorNumeric.off;
37-
38-
final icuCaseFirst = switch (caseFirst) {
39-
CaseFirst.upper => icu.CollatorCaseFirst.upperFirst,
40-
CaseFirst.lower => icu.CollatorCaseFirst.lowerFirst,
41-
CaseFirst.localeDependent => icu.CollatorCaseFirst.off,
42-
};
43-
4438
final icuStrength = switch (sensitivity) {
4539
Sensitivity.base => icu.CollatorStrength.primary,
4640
Sensitivity.accent => icu.CollatorStrength.secondary,
@@ -56,12 +50,9 @@ extension on CollationOptions {
5650

5751
return icu.CollatorOptions(
5852
strength: icuStrength,
59-
numeric: icuNumeric,
60-
caseFirst: icuCaseFirst,
6153
caseLevel: icuCaseLevel,
6254
alternateHandling: icu.CollatorAlternateHandling.nonIgnorable,
63-
backwardSecondLevel: icu.CollatorBackwardSecondLevel.off,
64-
maxVariable: icu.CollatorMaxVariable.auto,
55+
//TODO(mosuem) maxVariable: map to ecma
6556
);
6657
}
6758
}

pkgs/intl4x/lib/src/collation/collation_ecma.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ extension on CollationOptions {
6767
JSAny toJsOptions() =>
6868
{
6969
'localeMatcher': localeMatcher.jsName,
70-
'usage': usage.name,
7170
if (sensitivity != null) 'sensitivity': sensitivity!.jsName,
72-
'ignorePunctuation': ignorePunctuation,
73-
'numeric': numeric,
74-
'caseFirst': caseFirst.jsName,
75-
if (collation != null) 'collation': collation,
7671
}.jsify()!;
7772
}

pkgs/intl4x/lib/src/collation/collation_options.dart

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,26 @@
55
import '../options.dart';
66

77
class CollationOptions {
8-
final Usage usage;
9-
final Sensitivity? sensitivity;
10-
final bool ignorePunctuation;
11-
final bool numeric;
12-
final CaseFirst caseFirst;
13-
final String? collation;
148
final LocaleMatcher localeMatcher;
9+
final Sensitivity? sensitivity;
1510

1611
const CollationOptions({
1712
this.localeMatcher = LocaleMatcher.bestfit,
18-
this.usage = Usage.sort,
1913
this.sensitivity,
20-
this.ignorePunctuation = false,
21-
this.numeric = false,
22-
this.caseFirst = CaseFirst.localeDependent,
23-
this.collation,
2414
});
2515

2616
CollationOptions copyWith({
27-
Usage? usage,
28-
Sensitivity? sensitivity,
29-
bool? ignorePunctuation,
30-
bool? numeric,
31-
CaseFirst? caseFirst,
32-
String? collation,
3317
LocaleMatcher? localeMatcher,
18+
Sensitivity? sensitivity,
3419
}) {
3520
return CollationOptions(
36-
usage: usage ?? this.usage,
3721
sensitivity: sensitivity ?? this.sensitivity,
38-
ignorePunctuation: ignorePunctuation ?? this.ignorePunctuation,
39-
numeric: numeric ?? this.numeric,
40-
caseFirst: caseFirst ?? this.caseFirst,
41-
collation: collation ?? this.collation,
4222
localeMatcher: localeMatcher ?? this.localeMatcher,
4323
);
4424
}
4525
}
4626

47-
/// Whether to use collation for searching for strings in an array, or rather
48-
/// sorting an array of strings.
49-
///
50-
/// Example: For the `de` locale, `['AE', 'Ä']` is the correct order for
51-
/// [Usage.search], but `['Ä', 'AE']` for [Usage.sort].
52-
enum Usage { search, sort }
53-
5427
/// Which differences in the strings should lead to non-zero result values.
55-
/// The default is [Sensitivity.variant] for usage [Usage.sort]; it's locale
56-
/// dependent for [Usage.search].
5728
enum Sensitivity {
5829
/// Only strings that differ in base letters compare as unequal.
5930
/// Examples: a ≠ b, a = á, a = A.
@@ -78,16 +49,3 @@ enum Sensitivity {
7849

7950
const Sensitivity([this._jsName]);
8051
}
81-
82-
/// How upper case or lower case letters should be sorted.
83-
enum CaseFirst {
84-
upper,
85-
lower,
86-
localeDependent('false');
87-
88-
String get jsName => _jsName ?? name;
89-
90-
final String? _jsName;
91-
92-
const CaseFirst([this._jsName]);
93-
}

pkgs/intl4x/lib/src/data.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,3 @@ final class AssetData extends Data {
1111

1212
const AssetData(this.key);
1313
}
14-
15-
final class BundleData extends Data {
16-
const BundleData();
17-
}
18-
19-
final class NoData extends Data {
20-
const NoData();
21-
}

pkgs/intl4x/lib/src/data_4x.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,5 @@ extension DataProvider on Data {
1111
AssetData() => icu.DataProvider.fromByteSlice(
1212
File((this as AssetData).key).readAsBytesSync().buffer,
1313
),
14-
BundleData() => icu.DataProvider.compiled(),
15-
NoData() => icu.DataProvider.empty(),
1614
};
1715
}

0 commit comments

Comments
 (0)