Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

将单个拼音分隔成声母和韵母 #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions lib/src/pinyin_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,53 @@ class PinyinHelper {
static void addMultiPinyinDict(List<String> list) {
multiPinyinMap.addAll(PinyinResource.getResource(list));
}

/// 将单个拼音分隔成声母和韵母
static List<String> splitPinyin(String pinyin) {
List<String> result = [];
String initial = '';
String finalPinyin = '';
for (int i = 0; i < pinyin.length; i++) {
String char = pinyin[i];
if (char == 'a' ||
char == "ǎ" ||
char == "á" ||
char == "à" ||
char == "ā" ||
char == "e" ||
char == "ě" ||
char == "é" ||
char == "è" ||
char == "ē" ||
char == "i" ||
char == "ǐ" ||
char == "í" ||
char == "ì" ||
char == "ī" ||
char == "o" ||
char == "ǒ" ||
char == "ó" ||
char == "ò" ||
char == "ō" ||
char == "u" ||
char == "ǔ" ||
char == "ú" ||
char == "ù" ||
char == "ū" ||
char == "ü" ||
char == "ǘ" ||
char == "ǚ" ||
char == "ǜ" ||
char == "ǖ") {
initial = pinyin.substring(0, i);
finalPinyin = pinyin.substring(i);
break;
}
}
result.add(initial);
result.add(finalPinyin);
return result;
}
}

/// 多音字
Expand Down