@@ -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 ]' );
0 commit comments