Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. def ensureCompleteForm(s):
  2. '''문자열 안의 조합형 한글 부분을 완성형으로 바꾸기'''
  3. i = 0
  4. while i+1 < len(s):
  5. b1 = ord(s[i])
  6. b2 = ord(s[i+1])
  7.  
  8. print(str.join('\t', [c for c in s]))
  9. print('\t' * i + '@')
  10.  
  11. is_choseong = (
  12. 0x1100 <= b1 and b1 < 0x1161
  13. )
  14. is_choseong_followed_by_jungseong = (
  15. is_choseong and
  16. 0x1161 <= b2 and b2 < 0x11A8
  17. )
  18.  
  19. if is_choseong_followed_by_jungseong:
  20.  
  21. result = ((b1 - 0x1100) * 21 + b2 - 0x1161) * 28 + 0xAC00
  22. s = s[:i] + chr(result) + s[i+2:]
  23. print("{} followed_by_jungseong {} merged into {}".format(
  24. chr(b1), chr(b2), chr(result)
  25. ))
  26. continue
  27.  
  28. is_eumjeol_without_bachim = (
  29. 0xAC00 <= b1 and b1 <= 0xD7A3 and
  30. b1 % 0x1c == 0x10
  31. )
  32. is_eumjeol_followed_by_jongseong = (
  33. is_eumjeol_without_bachim and
  34. 0x11A8 <= b2 and b2 <= 0x11FF
  35. )
  36.  
  37. if is_eumjeol_followed_by_jongseong:
  38. result = b1 + b2 - 0x11A7
  39. s = s[:i] + chr(result) + s[i+2:]
  40. print("{} followed_by_jongseong {} merged into {}".format(
  41. chr(b1), chr(b2), chr(result)
  42. ))
  43. continue
  44.  
  45. i += 1
  46. return s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement