-
Notifications
You must be signed in to change notification settings - Fork 2
/
contains_no_diacritics.dart
37 lines (33 loc) · 1.1 KB
/
contains_no_diacritics.dart
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
extension ContainsNoDiacritics on String {
static const diacritics =
"ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž";
static const letters =
"AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz";
String get withoutDiacritics => splitMapJoin(
"",
onNonMatch: (char) => char.isNotEmpty && diacritics.contains(char)
? letters[diacritics.indexOf(char)]
: char,
);
bool containsNoDiacritics(Pattern other, [int startIndex = 0]) =>
withoutDiacritics.contains(other, startIndex);
}
// Test it
void main() {
group("withoutDiacritics", () {
test("should replace diacritics letter with their counterparts", () {
expect(
ContainsNoDiacritics.diacritics.withoutDiacritics,
ContainsNoDiacritics.letters,
);
});
});
group("containsNoDiacritics", () {
test(
"should return true if the word contains é while the pattern include e",
() {
expect("é".containsNoDiacritics("e"), true);
},
);
});
}