[KoCo-CVS] [Commit] KoreanCodecs/korean/python hangul.py
Brought to you by:
perky
From: Chang <pe...@us...> - 2002-04-24 05:00:05
|
perky 02/04/23 22:00:03 Modified: korean/python hangul.py Log: - Simpilify join, split function implementation. Revision Changes Path 1.2 +16 -16 KoreanCodecs/korean/python/hangul.py Index: hangul.py =================================================================== RCS file: /cvsroot/koco/KoreanCodecs/korean/python/hangul.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- hangul.py 24 Apr 2002 03:36:01 -0000 1.1 +++ hangul.py 24 Apr 2002 05:00:03 -0000 1.2 @@ -15,7 +15,7 @@ # Conjoining Jamo Behavior: # http://www.unicode.org/unicode/uni2book/ch03.pdf (section 3.11) # -# $Id: hangul.py,v 1.1 2002/04/24 03:36:01 perky Exp $ +# $Id: hangul.py,v 1.2 2002/04/24 05:00:03 perky Exp $ # class UnicodeHangulError(Exception): @@ -90,9 +90,9 @@ # Unicode Hangul Syllables Characteristics zone = (u'\uAC00', u'\uD7A3') -splitters = [ ( len(Jongsung)*len(Jungsung), Chosung ), - ( len(Jongsung), Jungsung ), - ( 1, Jongsung ) ] +NCHOSUNG = len(Chosung) +NJUNGSUNG = len(Jungsung) +NJONGSUNG = len(Jongsung) ishangul = ( lambda code: @@ -127,12 +127,12 @@ if not codes[0] or not codes[1]: # single jamo return codes[0] or codes[1] - r = ord(zone[0]) - codes = codes[:] # simple copy :D - for multiplier, codeset in splitters: - r = r + multiplier*codeset.index(codes.pop(0)) - - return unichr(r) + return unichr( + 0xac00 + ( + Chosung.index(codes[0])*NJUNGSUNG + + Jungsung.index(codes[1]) + )*NJONGSUNG + Jongsung.index(codes[2]) + ) def split(code): """ Split function which splits hangul syllable into jamos """ @@ -143,12 +143,12 @@ if code in Moeum.Codes: return [Null, code, Null] - code = ord(code) - ord(zone[0]) - r = [] - for divider, codeset in splitters: - value, code = code / divider, code % divider - r.append(codeset[value]) - return r + code = ord(code) - 0xac00 + return [ + Chosung[int(code / (NJUNGSUNG*NJONGSUNG))], # Python3000 safe + Jungsung[int(code / NJONGSUNG) % NJUNGSUNG], + Jongsung[code % NJONGSUNG] + ] def dividestring(str, intoelements=0): if type(str) is not type(u''): |