Skip to main content

[Flutter] 플러터에서 종성에 따라 은/는, 이/가 처리하는 함수

Published 1 min readMarkdown

name의 종성의 받침 여부에 따라

'$name은' 이라 띄울지, '$name는' 이라 띄울지 결정해주는 함수이다.

나중에도 쓸 일이 있을 것 같아 여기에 기록해둔다!

(이 함수는 은/는에만 해당되는 거고, 조금만 고치면 이/가도 처리 가능하다)

    String addCorrectEnd(String name) {
      String lastChar = name.characters.last;
      int code = lastChar.codeUnitAt(0);

      const int HANGUL_START = 0xAC00;
      const int HANGUL_END = 0xD7A3;

      if (code >= HANGUL_START && code <= HANGUL_END) {
        int index = code - HANGUL_START;

        const int NUM_FINALS = 28;

        if ((index % NUM_FINALS) > 0) {
          return "$name은"; 
        }
      }
      return "$name는"; 
    }

No comments yet. Be the first to comment.

More from this blog