splitJASO method Null safety

List<String> splitJASO(
  1. String input
)

한글 자소 분리하기 https://velog.io/@gunwng123/Flutter-%ED%95%9C%EA%B8%80-%EC%A2%85%EC%84%B1-%ED%8C%90%EB%B3%84

Implementation

List<String> splitJASO(String input) {
  final regExp = RegExp(r'[ㄱ-ㅎ|가-힣|a-z|A-Z|0-9|]');
  input = regExp.allMatches(input).map((m) => m[0]).toList().join('').toString();

  List<String> jasos = [];
  if (isKorean(input)) {
    for (int rune in input.runes) {
      try {
        // 유니코드 값 = ((초성 21) + 중성) 28 + 종성 + 0xAC00
        // int as = (rune - 0xAC00) ~/ 28;
        // unicode = ((초 * 21) + 중) * 28 + 종 + 0xAC00
        double chosung = ((rune - 0xAC00) / 28) / 21;
        double jungsung = ((rune - 0xAC00) / 28) % 21;
        double jongsung = (rune - 0xAC00) % 28;
        jasos.add(chos19[chosung.toInt()]);
        jasos.add(jungs21[jungsung.toInt()]);
        jasos.add(jong28[jongsung.toInt()]);
      } catch (e) {
        if (input.length == 1) jasos.add(input);
      }
    }
  }
  jasos.removeWhere((element) => element == '');
  return jasos;
}