Skip to content

Commit 4c47366

Browse files
committed
fixes to PinyinUtils
1 parent 43cceeb commit 4c47366

4 files changed

Lines changed: 36 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## [2.10.1]
2+
- A few fixes to PinyinUtils
13
## [2.10.0]
24
- Merged https://github.com/caseyryan/flutter_multi_formatter/pull/112
35
## [2.9.14]

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.10.0"
99+
version: "2.10.1"
100100
flutter_test:
101101
dependency: "direct dev"
102102
description: flutter

lib/utils/pinyin_utils.dart

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class PinyinUtils {
221221
"wei",
222222
"hao",
223223
"tai",
224+
"lue",
224225
"gan",
225226
"lve",
226227
"zha",
@@ -436,14 +437,17 @@ class PinyinUtils {
436437
"me",
437438
"si",
438439
"ma",
440+
"pi",
439441
"mi",
440442
"ce",
441443
"te",
442444
"na",
443445
"ai",
444446
"fa",
445447
"ba",
448+
"ou",
446449
"e",
450+
"o",
447451
"a",
448452
"r",
449453
];
@@ -487,7 +491,13 @@ class PinyinUtils {
487491

488492
/// Returns a list of tones for the whole sentence
489493
static List<int> getPinyinTones(String sentence) {
490-
return splitToSyllables<String>(sentence).map(getPinyinTone).toList();
494+
return splitToSyllables<SyllableData>(sentence)
495+
.where((e) => e.isValid)
496+
.map(
497+
(e) => e.value,
498+
)
499+
.map(getPinyinTone)
500+
.toList();
491501
}
492502

493503
/// Detects a tone of a single syllable where 5 means neutral tone
@@ -588,31 +598,49 @@ class PinyinUtils {
588598
/// converts all spcial symbols in pinyin to it's
589599
/// normal latin analog like ě -> e or ǔ -> u
590600
static String simplifyPinyin(String pinyin) {
601+
int i = pinyin.length;
591602
while (pinyin.contains(_aRegex)) {
603+
i--;
592604
pinyin = pinyin.replaceFirst(_aRegex, 'a');
605+
if (i <= 0) break;
593606
}
607+
i = pinyin.length;
594608
while (pinyin.contains(_eRegex)) {
609+
i--;
595610
pinyin = pinyin.replaceFirst(_eRegex, 'e');
611+
if (i <= 0) break;
596612
}
613+
i = pinyin.length;
597614
while (pinyin.contains(_iRegex)) {
615+
i--;
598616
pinyin = pinyin.replaceFirst(_iRegex, 'i');
617+
if (i <= 0) break;
599618
}
619+
i = pinyin.length;
600620
while (pinyin.contains(_oRegex)) {
621+
i--;
601622
pinyin = pinyin.replaceFirst(_oRegex, 'o');
623+
if (i <= 0) break;
602624
}
625+
i = pinyin.length;
603626
while (pinyin.contains(_uRegex)) {
627+
i--;
604628
pinyin = pinyin.replaceFirst(_uRegex, 'u');
629+
if (i <= 0) break;
605630
}
606631

607632
/// i is just a safeguard from an endless loop
608-
int i = pinyin.length;
633+
i = pinyin.length;
609634
while (pinyin.contains(_uDottedRegex)) {
610635
i--;
611636
pinyin = pinyin.replaceFirst(_uDottedRegex, 'u');
612637
if (i <= 0) break;
613638
}
639+
i = pinyin.length;
614640
while (pinyin.contains(_vRegex)) {
641+
i--;
615642
pinyin = pinyin.replaceFirst(_vRegex, 'v');
643+
if (i <= 0) break;
616644
}
617645
return pinyin;
618646
}
@@ -622,6 +650,7 @@ class PinyinUtils {
622650
/// so it would split more precisely
623651
static const Map<String, String> _splittableExceptions = {
624652
'nine': 'ni ne',
653+
'jini': 'ji ni',
625654
};
626655

627656
static String splitToSyllablesBySeparator(
@@ -648,6 +677,7 @@ class PinyinUtils {
648677
T == String || T == SyllableData,
649678
'T can only be a String or a SyllableData',
650679
);
680+
value = value.replaceAll('\'', '');
651681
var simplified = simplifyPinyin(value);
652682

653683
/// тут надо вставить предопределенные пробелы, чтобы

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.10.0
3+
version: 2.10.1
44
homepage: https://github.com/caseyryan/flutter_multi_formatter
55

66
environment:

0 commit comments

Comments
 (0)