-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e7d662
commit 3f43d3e
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
import re | ||
import sys | ||
|
||
re_obj = re.compile(r'/\*\(.+\)\*/') | ||
# re_obj = re.compile(r'[\u4e00-\u9fa5]') | ||
word_set = set() | ||
result = "" # 存放返回的结果 | ||
|
||
|
||
def searchWordByRe(file_name): | ||
global re_obj | ||
global word_set | ||
global result | ||
|
||
file_obj = open(file_name, 'r', encoding='utf-8') | ||
|
||
try: | ||
text_list = file_obj.readlines() | ||
|
||
for line in text_list: | ||
dict_list = re_obj.findall(line) | ||
|
||
for font in dict_list: | ||
word = font[3:-3] | ||
if word not in word_set: | ||
# 去重 | ||
word_set.add(word) | ||
result = result + word | ||
|
||
finally: | ||
file_obj.close() | ||
|
||
print(result) | ||
|
||
|
||
def searchWordByEocode(file_name): | ||
global re_obj | ||
global word_set | ||
global result | ||
|
||
file_obj = open(file_name, 'r', encoding='utf-8') | ||
|
||
try: | ||
text_list = file_obj.readlines() | ||
for line in text_list: | ||
for word in line: | ||
if u'\u4e00' <= word <= u'\u9fff': | ||
if word not in word_set: | ||
# 去重 | ||
word_set.add(word) | ||
result = result + word | ||
|
||
finally: | ||
file_obj.close() | ||
|
||
print(result) | ||
|
||
|
||
if __name__ == "__main__": | ||
""" | ||
用法:python get_font.py 字模.c文件的路径 | ||
""" | ||
|
||
file_name = sys.argv[1] | ||
print(file_name) | ||
|
||
searchWordByRe(file_name) | ||
# searchWordByEocode() |