Skip to content

Instantly share code, notes, and snippets.

@spikeekips
Created September 2, 2016 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spikeekips/82d43281b448e6255ee9beea29c0b7ab to your computer and use it in GitHub Desktop.
Save spikeekips/82d43281b448e6255ee9beea29c0b7ab to your computer and use it in GitHub Desktop.
Splitting Hangul Jongsung Code
# -*- coding: utf-8 -*-
"""
Copyright 2005 Spike^ekipS <spikeekips@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
chosung = ( \
0x3131, # ㄱ
0x3132, # ㄲ
0x3134, # ㄴ
0x3137, # ㄷ
0x3138, # ㄸ
0x3139, # ㄹ
0x3141, # ㅁ
0x3142, # ㅂ
0x3143, # ㅃ
0x3145, # ㅅ
0x3146, # ㅆ
0x3147, # ㅇ
0x3148, # ㅈ
0x3149, # ㅉ
0x314a, # ㅊ
0x314b, # ㅋ
0x314c, # ㅌ
0x314d, # ㅍ
0x314e, # ㅎ
)
jungsung = ( \
0x314f, # ㅏ
0x3150, # ㅐ
0x3151, # ㅑ
0x3152, # ㅒ
0x3153, # ㅓ
0x3154, # ㅔ
0x3155, # ㅕ
0x3156, # ㅖ
0x3157, # ㅗ
0x3158, # ㅘ
0x3159, # ㅙ
0x315a, # ㅚ
0x315b, # ㅛ
0x315c, # ㅜ
0x315d, # ㅝ
0x315e, # ㅞ
0x315f, # ㅟ
0x3160, # ㅠ
0x3161, # ㅡ
0x3162, # ㅢ
0x3163, # ㅣ
)
jongsung = ( \
0, #
0x3131, # ㄱ
0x3132, # ㄲ
0x3133, # ㄳ
0x3134, # ㄴ
0x3135, # ㄵ
0x3136, # ㄶ
0x3137, # ㄷ
0x3139, # ㄹ
0x313a, # ㄺ
0x313b, # ㄻ
0x313c, # ㄼ
0x313d, # ㄽ
0x313e, # ㄾ
0x313f, # ㄿ
0x3140, # ㅀ
0x3141, # ㅁ
0x3142, # ㅂ
0x3144, # ㅄ
0x3145, # ㅅ
0x3146, # ㅆ
0x3147, # ㅇ
0x3148, # ㅈ
0x314a, # ㅊ
0x314b, # ㅋ
0x314c, # ㅌ
0x314d, # ㅍ
0x314e, # ㅎ
)
def split (c) :
__c = ord(c) - ord(u"가")
__a = __c / (21 * 28)
__c = __c % (21 * 28)
__b = __c / 28
__c = __c % 28
return (unichr(chosung[__a]), unichr(jungsung[__b]), unichr(jongsung[__c]), )
if __name__ == "__main__" :
import sys
a = u"나봒"
__o = split(a[-1])
if __o[2] == u"\x00" :
pass
else :
__diff = ord(__o[2]) - ord(u"ㄱ") + 1
print unichr(ord(a[-1]) - __diff)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment