tryParse static method

Pinyin? tryParse(
  1. String text
)

Implementation

static Pinyin? tryParse(String text) {
  // TODO: 2022/11/8 ipcjs 处理搜索英文首字母...
  if (text.isEmpty || !ChineseHelper.containsChinese(text)) {
    return null;
  }
  final pinyin = PinyinHelper.getPinyinE(text, separator: ' ', defPinyin: '?')
      .split(' ');

  return Pinyin._(
    pinyin,
    pinyin.join(''),
    pinyin.map((e) => e[0]).join(''),
  );
}