Skip to content

Commit 4e1c17b

Browse files
committed
Added promptTonesForPinyin static function to PinyinUtils
1 parent 376bc00 commit 4e1c17b

5 files changed

Lines changed: 43 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [2.9.11]
2+
- Added promptTonesForPinyin() static function to PinyinUtils.
3+
It can give you a list of its vowels with all possible tones
14
## [2.9.10]
25
- Added di pinyin to HanziUtils
36
## [2.9.9]

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ packages:
9696
path: ".."
9797
relative: true
9898
source: path
99-
version: "2.9.10"
99+
version: "2.9.11"
100100
flutter_test:
101101
dependency: "direct dev"
102102
description: flutter

lib/formatters/credit_card_number_input_formatter.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class CreditCardNumberInputFormatter extends TextInputFormatter {
8686
);
8787
}
8888

89-
/// this is a small dirty hask to be able to remove the first character
89+
/// this is a small dirty hack to be able to remove the first character
9090
Future _removeFirstLetter() async {
9191
await Future.delayed(
9292
Duration(
@@ -127,14 +127,19 @@ class CreditCardNumberInputFormatter extends TextInputFormatter {
127127
}
128128
}
129129

130-
/// checks not only for length and characters but also
131-
/// for card system code code. If it's not found the succession of numbers
130+
/// checks not only for a length and characters but also
131+
/// for card system code. If it's not found the succession of numbers
132132
/// will not be marked as a valid card number
133133
bool isCardValidNumber(
134134
String cardNumber, {
135135
bool checkLength = false,
136136
}) {
137-
cardNumber = toNumericString(cardNumber);
137+
cardNumber = toNumericString(
138+
cardNumber,
139+
allowAllZeroes: true,
140+
allowHyphen: false,
141+
allowPeriod: false,
142+
);
138143
if (cardNumber.isEmpty) {
139144
return false;
140145
}

lib/utils/pinyin_utils.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,23 @@ class PinyinUtils {
462462
return value.replaceAll(_punctuationRegex, '');
463463
}
464464

465+
/// Pass a tone or untoned pinyin and get a list
466+
/// of toned vowels that can be in this pinyin
467+
static List<String> promptTonesForPinyin(String pinyin) {
468+
final chars = HashSet<String>.from(
469+
PinyinUtils.simplifyPinyin(pinyin).split(''),
470+
).toList();
471+
final temp = <String>[];
472+
for (var i = 0; i < chars.length; i++) {
473+
final char = chars[i];
474+
if (_mappedVowels.containsKey(char)) {
475+
temp.addAll(_mappedVowels[char]!);
476+
}
477+
}
478+
479+
return temp;
480+
}
481+
465482
final _toneRegexp = RegExp(r'[āáǎàēéěèōóǒòīíǐìūúǔùǖǘǚǜü]+');
466483

467484
bool containsTone(String text) {
@@ -500,6 +517,18 @@ class PinyinUtils {
500517
static const _vS = 'v̄v́v̆v̌v̀';
501518
static const _uDottedS = '(?:ü|ǖ|ǘ|ǚ|ǚ|ü̆|ǜ)';
502519

520+
static const Map<String, List<String>> _mappedVowels = {
521+
'a': ['ā', 'á', 'ǎ', 'à'],
522+
'e': ['ē', 'é', 'ě', 'è'],
523+
'i': ['ī', 'í', 'ǐ', 'ì'],
524+
'o': ['ō', 'ó', 'ǒ', 'ò'],
525+
'u': ['ū', 'ú', 'ǔ', 'ù', 'ü', 'ǖ', 'ǘ', 'ǚ', 'ǜ'],
526+
};
527+
528+
static Map<String, List<String>> get mappedVowels {
529+
return _mappedVowels;
530+
}
531+
503532
static final RegExp _aRegex = RegExp('[$_aS]');
504533
static final RegExp _eRegex = RegExp('[$_eS]');
505534
static final RegExp _iRegex = RegExp('[$_iS]');

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_multi_formatter
22
description: A package of formatters for international phone numbers, credit / debit cards and a masked formatter
3-
version: 2.9.10
3+
version: 2.9.11
44
homepage: https://github.com/caseyryan/flutter_multi_formatter
55

66
environment:

0 commit comments

Comments
 (0)