Skip to content

Commit

Permalink
fix: move cho, jung, jong coefficients back to hangul.offset
Browse files Browse the repository at this point in the history
  • Loading branch information
WieeRd committed Feb 14, 2024
1 parent 57369b6 commit 7cfe1d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 2 additions & 7 deletions ricecake/hangul/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

__all__ = ["compose", "decompose"]

# FEAT: `*_END - *_START + 1` -> `*_COUNT` -> `*_COEF`
CHOSEONG_COEF = 21 * 28
JUNGSEONG_COEF = 28
JONGSEONG_COEF = 1


def compose(cho: str, jung: str, jong: str | None) -> str:
"""Composes Choseong, Jungseong, and an optional Jongseong into a Syllable.
Expand All @@ -17,8 +12,8 @@ def compose(cho: str, jung: str, jong: str | None) -> str:
ValueError: If the characters are not appropriate Hangul Jamos.
"""
return chr(
offset.modern_choseong_offset(cho) * CHOSEONG_COEF
+ offset.modern_jongseong_offset(jung) * JUNGSEONG_COEF
offset.modern_choseong_offset(cho) * offset.CHOSEONG_COEF
+ offset.modern_jongseong_offset(jung) * offset.JUNGSEONG_COEF
+ (offset.modern_jongseong_offset(jong) if jong else 0)
+ offset.SYLLABLE_BASE
)
Expand Down
9 changes: 9 additions & 0 deletions ricecake/hangul/offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@
ARCHAIC_JONGSEONG_END = 0x11FF # 'ᇿ'


CHOSEONG_COUNT = MODERN_CHOSEONG_END - MODERN_CHOSEONG_BASE + 1
JUNGSEONG_COUNT = MODERN_JUNGSEONG_END - MODERN_JUNGSEONG_BASE + 1
JONGSEONG_COUNT = MODERN_JONGSEONG_END - MODERN_JONGSEONG_BASE + 1 + 1

CHOSEONG_COEF = JUNGSEONG_COUNT * JONGSEONG_COUNT
JUNGSEONG_COEF = JONGSEONG_COUNT
JONGSEONG_COEF = 1


# https://en.wikipedia.org/wiki/Hangul_Compatibility_Jamo
COMPAT_JAMO_BASE = 0x3130 # 'ㄱ' - 1 (U+3130 is reserved)
COMPAT_JAMO_END = 0x318F # 'ㆎ' + 1 (U+318F is reserved)
Expand Down

0 comments on commit 7cfe1d2

Please sign in to comment.