"""앞말의 끝소리에 맞춰 조사를 고른다(과/와 · 을/를 · 은/는 · 이/가 · 으로/로). 설정 이름과 게시판 칸 이름처럼 바뀌는 말 뒤에 조사를 고정하면 "글 수은"처럼 틀린다. 숫자는 읽는 소리로 본다(0 영 · 1 일 · 3 삼 · 6 육 · 7 칠 · 8 팔은 받침 있음). 끝의 괄호와 따옴표는 건너뛴다. 앱(Korean.kt)과 웹(korean.js)도 같은 규칙이다. """ WITH_BATCHIM = "013678" RIEUL = "178" def josa(word, with_batchim, without): text = str(word) last = text.rstrip(" )]}\"'.」』")[-1:] batchim = rieul = False if last and "가" <= last <= "힣": tail = (ord(last) - 0xAC00) % 28 batchim, rieul = tail != 0, tail == 8 elif last and last.isdigit() and last.isascii(): batchim, rieul = last in WITH_BATCHIM, last in RIEUL if with_batchim == "으로": return text + ("으로" if batchim and not rieul else "로") return text + (with_batchim if batchim else without)