summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-12-14 15:06:39 +0800
committerPeng Wu <alexepico@gmail.com>2011-12-14 15:06:39 +0800
commitcd8659a2748c8afe04e3c8e0964845a84ed739df (patch)
tree21532594c2867aa66863640c954bb3ccb8eb3bf9
parent8fe06a2c0f4f299bb2fa1610769814913fee5d6f (diff)
downloadlibpinyin-cd8659a2748c8afe04e3c8e0964845a84ed739df.zip
libpinyin-cd8659a2748c8afe04e3c8e0964845a84ed739df.tar.gz
libpinyin-cd8659a2748c8afe04e3c8e0964845a84ed739df.tar.xz
refactor expand_file
-rw-r--r--scripts/genbopomofoheader.py18
-rw-r--r--scripts/gendoublepinyinheader.py18
-rw-r--r--scripts/genpinyinheader.py18
3 files changed, 7 insertions, 47 deletions
diff --git a/scripts/genbopomofoheader.py b/scripts/genbopomofoheader.py
index 9d617b6..cb4024f 100644
--- a/scripts/genbopomofoheader.py
+++ b/scripts/genbopomofoheader.py
@@ -21,8 +21,8 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-import os
from operator import itemgetter
+from utils import expand_file
bopomofo = [
'ㄅ', 'ㄆ', 'ㄇ', 'ㄈ', 'ㄉ', 'ㄊ', 'ㄋ', 'ㄌ', 'ㄍ', 'ㄎ',
@@ -118,18 +118,6 @@ def get_table_content(tablename):
return gen_chewing_tones(scheme);
-def expand_file(filename):
- infile = open(filename, "r")
- for line in infile.readlines():
- line = line.rstrip(os.linesep)
- if len(line) < 3 :
- print(line)
- continue
- if line[0] == '@' and line[-1] == '@':
- tablename = line[1:-1]
- print(get_table_content(tablename))
- else:
- print(line)
-
+### main function ###
if __name__ == "__main__":
- expand_file("chewing_table.h.in")
+ expand_file("chewing_table.h.in", get_table_content)
diff --git a/scripts/gendoublepinyinheader.py b/scripts/gendoublepinyinheader.py
index 96a363e..15de35e 100644
--- a/scripts/gendoublepinyinheader.py
+++ b/scripts/gendoublepinyinheader.py
@@ -20,9 +20,8 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-import os
import pinyin
-
+from utils import expand_file
def gen_shengmu_table(scheme):
entries = []
@@ -64,20 +63,7 @@ def get_table_content(tablename):
if part == "YUN":
return gen_yunmu_table(scheme)
-def expand_file(filename):
- infile = open(filename, "r")
- for line in infile.readlines():
- line = line.rstrip(os.linesep)
- if len(line) < 3 :
- print(line)
- continue
- if line[0] == '@' and line[-1] == '@':
- tablename = line[1:-1]
- print(get_table_content(tablename))
- else:
- print(line)
-
### main function ###
if __name__ == "__main__":
- expand_file("double_pinyin_table.h.in")
+ expand_file("double_pinyin_table.h.in", get_table_content)
diff --git a/scripts/genpinyinheader.py b/scripts/genpinyinheader.py
index 8a0a8fd..7d07a24 100644
--- a/scripts/genpinyinheader.py
+++ b/scripts/genpinyinheader.py
@@ -20,7 +20,7 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-import os
+from utils import expand_file
from genpinyintable import gen_content_table, \
gen_pinyin_index, gen_bopomofo_index, \
gen_chewing_key_table
@@ -41,20 +41,6 @@ def get_table_content(tablename):
return gen_chewing_key_table()
-def expand_file(filename):
- infile = open(filename, "r")
- for line in infile.readlines():
- line = line.rstrip(os.linesep)
- if len(line) < 3 :
- print(line)
- continue
- if line[0] == '@' and line[-1] == '@':
- tablename = line[1:-1]
- print(get_table_content(tablename))
- else:
- print(line)
-
-
### main function ###
if __name__ == "__main__":
- expand_file("pinyin_parser_table.h.in")
+ expand_file("pinyin_parser_table.h.in", get_table_content)