[KoCo-CVS] [Commit] KoreanCodecs/korean/python hangul.py
Brought to you by:
perky
From: Chang <pe...@us...> - 2002-05-01 11:10:48
|
perky 02/05/01 04:10:44 Modified: korean/python hangul.py Log: - Test long unicode string for ishangul, isJaeum, isMoeum Suggested by: Lee Gang-Seong <gs...@gw...> Revision Changes Path 1.10 +36 -7 KoreanCodecs/korean/python/hangul.py Index: hangul.py =================================================================== RCS file: /cvsroot/koco/KoreanCodecs/korean/python/hangul.py,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- hangul.py 29 Apr 2002 14:24:25 -0000 1.9 +++ hangul.py 1 May 2002 11:10:44 -0000 1.10 @@ -15,7 +15,7 @@ # Conjoining Jamo Behavior: # http://www.unicode.org/unicode/uni2book/ch03.pdf (section 3.11) # -# $Id: hangul.py,v 1.9 2002/04/29 14:24:25 perky Exp $ +# $Id: hangul.py,v 1.10 2002/05/01 11:10:44 perky Exp $ # class UnicodeHangulError(Exception): @@ -29,6 +29,11 @@ __str__ = __repr__ Null = u'' +try: + True +except: + True = 1 + False = 0 class Jaeum: @@ -85,9 +90,6 @@ exec "%s = %s" % (name, repr(code)) del name, code -isJaeum = lambda c: c in Jaeum.Codes -isMoeum = lambda c: c in Moeum.Codes - # Unicode Hangul Syllables Characteristics ZONE = (u'\uAC00', u'\uD7A3') NCHOSUNG = len(Chosung) @@ -99,7 +101,7 @@ CHOSUNG_FILLER = u'\u115F' JUNGSUNG_FILLER = u'\u1160' -ishangul = ( +_ishangul = ( lambda code: ZONE[0] <= code <= ZONE[1] or code in Jaeum.Codes or @@ -125,6 +127,33 @@ u'(\uc778)': (4, u'\uc778'), # (in)- } +def isJaeum(u): + if u: + for c in u: + if c not in Jaeum.Codes: + break + else: + return True + return False + +def isMoeum(u): + if u: + for c in u: + if c not in Moeum.Codes: + break + else: + return True + return False + +def ishangul(u): + if u: + for c in u: + if not _ishangul(c): + break + else: + return True + return False + def join(codes): """ Join function which makes hangul syllable from jamos """ if len(codes) is not 3: @@ -141,7 +170,7 @@ def split(code): """ Split function which splits hangul syllable into jamos """ - if len(code) != 1 or not ishangul(code): + if len(code) != 1 or not _ishangul(code): raise UnicodeHangulError("needs 1 hangul letter") if code in Jaeum.Codes: return (code, Null, Null) @@ -185,7 +214,7 @@ def disjoint(s): obuff = [] for c in s: - if ishangul(c): + if _ishangul(c): cho, jung, jong = split(c) if cho: obuff.append( unichr(ord(JBASE_CHOSUNG) + Chosung.index(cho)) ) |