From 31606749909bd49b7d520978a989e92a40b526fe Mon Sep 17 00:00:00 2001 From: Konstantin Serov Date: Sat, 15 Oct 2022 12:26:58 +0700 Subject: [PATCH] cimplifyPinyin utility method --- CHANGELOG.md | 2 ++ example/pubspec.lock | 2 +- lib/utils/pinyin_utils.dart | 19 +++++++++++++++++++ pubspec.yaml | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cef0a8..15179ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## [2.8.1] +- Added a utility method PinyinUtils.simplifyPinyin(); ## [2.8.0] - Introducing PinyinFormatter for Chinese language ## [2.7.6] diff --git a/example/pubspec.lock b/example/pubspec.lock index 78fef9c..c2f1a9b 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -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 diff --git a/lib/utils/pinyin_utils.dart b/lib/utils/pinyin_utils.dart index 505f051..c5650e3 100644 --- a/lib/utils/pinyin_utils.dart +++ b/lib/utils/pinyin_utils.dart @@ -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 = '\'', diff --git a/pubspec.yaml b/pubspec.yaml index 523086d..28cc5b3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: