OSDN Git Service

add makefile
[rec10/rec10-git.git] / rec10 / trunk / src / zenhan.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
5
6 import recdblist
7 global z_ascii
8 global h_ascii
9 global z_number
10 global h_number
11 z_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !”#$%&’()*+,−./:;<=>?@[¥]^_‘{|}〜 "
12 h_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ "
13 z_number = u"0123456789"
14 h_number = u"0123456789"
15 z_alphabet = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #"
16 h_alphabet = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #"
17 def toHankaku(str):
18     retstr = u""
19     for s in str:
20         i = z_ascii.find(s)
21         if (i != -1):
22             s = h_ascii[i]
23         i = z_number.find(s)
24         if (i != -1):
25             s = h_number[i]
26         retstr = retstr + s
27     return retstr
28 def toHankaku_ABC123(str):
29     retstr = u""
30     for s in str:
31         i = z_alphabet.find(s)
32         if (i != -1):
33             s = h_alphabet[i]
34         i = z_number.find(s)
35         if (i != -1):
36             s = h_number[i]
37         retstr = retstr + s
38     return retstr
39 def check_Character_Type(character):
40     """
41     return code is 1:Alphabet 2:Hiragana 3:Katakana 4:Kanji
42     """
43     #recdblist.printutf8(character)
44     #recdblist.printutf8(type(character))
45     #character=character.encode('UTF-8')
46     #recdblist.printutf8(character)
47     #recdblist.printutf8(type(character))
48     chcode=ord(character)
49     #recdblist.printutf8(ord(chcode))
50     if chcode>=0x0000 and chcode<=0x007F:
51         return 1
52     elif chcode>=0x3040 and chcode<=0x309F:
53         return 2
54     elif chcode>=0x30A0 and chcode<=0x30FF:
55         return 3
56     elif chcode>=0x4E00 and chcode<=0x9FFF:
57         return 4