Skip to content

Commit

Permalink
cimplifyPinyin utility method
Browse files Browse the repository at this point in the history
  • Loading branch information
caseyryan committed Oct 15, 2022
1 parent 8b8171e commit 3160674
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## [2.8.1]
- Added a utility method PinyinUtils.simplifyPinyin();
## [2.8.0]
- Introducing PinyinFormatter for Chinese language
## [2.7.6]
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.8.0"
version: "2.8.1"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down
19 changes: 19 additions & 0 deletions lib/utils/pinyin_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ class PinyinUtils {
return value.replaceAll(_punctuationRegex, '');
}

static final RegExp _aRegex = RegExp(r'[āáǎăà]+');
static final RegExp _eRegex = RegExp(r'[ēéěĕè]+');
static final RegExp _iRegex = RegExp(r'[īíǐĭì]+');
static final RegExp _oRegex = RegExp(r'[ōóǒŏò]+');
static final RegExp _uRegex = RegExp(r'[ūúǔŭùüǖǘǚǚü̆ǜ]+');
static final RegExp _vRegex = RegExp(r'[v̄v́v̆v̌v̀]+');

/// converts all spcial symbols in pinyin to it's
/// normal latin analog like ě -> e or ǔ -> u
static String simplifyPinyin(String pinyin) {
return pinyin
.replaceAll(_aRegex, 'a')
.replaceAll(_eRegex, 'e')
.replaceAll(_iRegex, 'i')
.replaceAll(_oRegex, 'o')
.replaceAll(_uRegex, 'u')
.replaceAll(_vRegex, 'v');
}

static String splitToSyllablesBySeparator(
String value, [
String separator = '\'',
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_multi_formatter
description: A package of formatters for international phone numbers, credit / debit cards and a masked formatter
version: 2.8.0
version: 2.8.1
homepage: https://github.com/caseyryan/flutter_multi_formatter

environment:
Expand Down

0 comments on commit 3160674

Please sign in to comment.