Skip to content

Commit b28ce0a

Browse files
committed
Update casemapper
1 parent 2ac12f3 commit b28ce0a

3 files changed

Lines changed: 23 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Add new methods to `ILibLocaleInfo`:
44
`getLanguageName()`, `getRegionName()`, `getClock()`, `getLocale()`, `getUnits()`, `getCalendar()`, `getTimeZone()`, `getPrimaryGroupingDigits()`, `getSecondaryGroupingDigits()`, `getPercentageSymbol()`, `getExponential()`, `getNativeExponential()`, `getNativePercentageSymbol()`, `getNegativeNumberFormat()`, `getDigitsStyle()`, `getDigits()`, `getNativeDigits()`, `getRoundingMode()`, `getScript()`, `getDefaultScript()`, `getAllScripts()`, `getMeridiemsStyle()`, `getPaperSize()`, `getDelimiterQuotationStart()`, `getDelimiterQuotationEnd()`
55
* Implement `ILibLocale`
6-
* Implement `ILibCaseMapper'
6+
* Implement `ILibCaseMapper`
77

88
## 1.6.0
99
* Implement the `ILibNumFmt` class to enable NumberFormatting

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ _flutterIlibPlugin.evaluateILib(jscode1);
194194
```
195195
To give a more efficient way, we provide some classes that can be easily used in a Flutter app.
196196
Currently, we have the following classes:
197+
- `ILibCaseMapper`
197198
- `ILibDateFmt`
198199
- `ILibLocaleInfo`
199200
- `ILibDurationFmt`

lib/ilib_casemapper.dart

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,31 @@ class ILibCaseMapper {
2828
};
2929
}
3030

31-
switch (this.locale.getLanguage()) {
32-
case 'az':
33-
case 'tr':
34-
case 'crh':
35-
case 'kk':
36-
case 'krc':
37-
case 'tt':
38-
_setUpMap('iı', 'İI');
39-
break;
31+
const Set<String> specialLanguages = {'az', 'tr', 'crh', 'kk', 'krc', 'tt'};
32+
if (specialLanguages.contains(this.locale.getLanguage())) {
33+
_setUpMap('iı', 'İI');
4034
}
4135
}
4236
bool up;
4337
ILibLocale locale;
4438
Map<String, String> mapData = <String, String>{};
4539

40+
String _handleGreekSigma(String string, int i) {
41+
if (i < string.length) {
42+
final String nextChar = string[i];
43+
final int code = nextChar.codeUnitAt(0);
44+
// If the next char is not a Greek letter, this is the end of the word,
45+
// so use the final form of sigma. Otherwise, use the mid-word form.
46+
final bool isNotGreek =
47+
(code < 0x0388 && code != 0x0386) || code > 0x03CE;
48+
return (isNotGreek ? 'ς' : 'σ') + nextChar.toLowerCase();
49+
} else {
50+
// No next char means this is the end of the word,
51+
// so use the final form of sigma.
52+
return 'ς';
53+
}
54+
}
55+
4656
String? _charMapper(String? string) {
4757
if (string == null || string.isEmpty) {
4858
return string;
@@ -57,29 +67,12 @@ class ILibCaseMapper {
5767
i++;
5868

5969
if (!up && c == 'Σ') {
70+
buffer.write(_handleGreekSigma(string, i));
6071
if (i < len) {
61-
final String nextChar = string[i];
6272
i++;
63-
64-
final int code = nextChar.codeUnitAt(0);
65-
66-
// if the next char is not a greek letter, this is the end of the word so use the
67-
// final form of sigma. Otherwise, use the mid-word form.
68-
final bool isNotGreek =
69-
(code < 0x0388 && code != 0x0386) || code > 0x03CE;
70-
buffer.write(isNotGreek ? 'ς' : 'σ');
71-
72-
buffer.write(nextChar.toLowerCase());
73-
} else {
74-
// no next char means this is the end of the word, so use the final form of sigma
75-
buffer.write('ς');
7673
}
7774
} else {
78-
if (mapData.containsKey(c)) {
79-
buffer.write(mapData[c]);
80-
} else {
81-
buffer.write(up ? c.toUpperCase() : c.toLowerCase());
82-
}
75+
buffer.write(mapData[c] ?? (up ? c.toUpperCase() : c.toLowerCase()));
8376
}
8477
}
8578

0 commit comments

Comments
 (0)