Skip to content

Instantly share code, notes, and snippets.

@j-min j-min/hangul.py forked from allieus/hangul.py
Created Dec 20, 2016

Embed
What would you like to do?
# -*- coding: utf-8 -*-
class Hangul:
BASE_CODE = 44032
CHOSUNG = 588
JUNGSUNG = 28
# 초성 리스트. 00 ~ 18
CHOSUNG_LIST = [
'', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '']
# 중성 리스트. 00 ~ 20
JUNGSUNG_LIST = [
'', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '']
# 종성 리스트. 00 ~ 27 + 1(1개 없음)
JONGSUNG_LIST = [
None, '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '']
def split(self, ch):
base_code = ord(ch) - self.BASE_CODE
c1 = base_code // self.CHOSUNG
c2 = (base_code - (self.CHOSUNG * c1)) // self.JUNGSUNG
c3 = (base_code - (self.CHOSUNG * c1) - (self.JUNGSUNG * c2))
try:
return (self.CHOSUNG_LIST[c1], self.JUNGSUNG_LIST[c2], self.JONGSUNG_LIST[c3])
except IndexError:
return (None, None, None)
hangul = Hangul()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.