simplifyPinyin static method

String simplifyPinyin(
  1. String pinyin
)

converts all spcial symbols in pinyin to it's normal latin analog like ě -> e or ǔ -> u

Implementation

static String simplifyPinyin(String pinyin) {
  int i = pinyin.length;
  while (pinyin.contains(_aRegex)) {
    i--;
    pinyin = pinyin.replaceFirst(_aRegex, 'a');
    if (i <= 0) break;
  }
  i = pinyin.length;
  while (pinyin.contains(_eRegex)) {
    i--;
    pinyin = pinyin.replaceFirst(_eRegex, 'e');
    if (i <= 0) break;
  }
  i = pinyin.length;
  while (pinyin.contains(_iRegex)) {
    i--;
    pinyin = pinyin.replaceFirst(_iRegex, 'i');
    if (i <= 0) break;
  }
  i = pinyin.length;
  while (pinyin.contains(_oRegex)) {
    i--;
    pinyin = pinyin.replaceFirst(_oRegex, 'o');
    if (i <= 0) break;
  }
  i = pinyin.length;
  while (pinyin.contains(_uRegex)) {
    i--;
    pinyin = pinyin.replaceFirst(_uRegex, 'u');
    if (i <= 0) break;
  }

  /// i is just a safeguard from an endless loop
  i = pinyin.length;
  while (pinyin.contains(_uDottedRegex)) {
    i--;
    pinyin = pinyin.replaceFirst(_uDottedRegex, 'u');
    if (i <= 0) break;
  }
  i = pinyin.length;
  while (pinyin.contains(_vRegex)) {
    i--;
    pinyin = pinyin.replaceFirst(_vRegex, 'v');
    if (i <= 0) break;
  }
  return pinyin;
}