Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

入力ソースコードファイルの文字コードを指定できるように #8

Merged
merged 1 commit into from
Jan 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions c2aenum/enum_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import re

class C2aEnum:
def __init__(self, c2a_src_path):
def __init__(self, c2a_src_path, encoding):
self.path = c2a_src_path
self.encoding = encoding

self._load_bc()
self._load_tlm_code()
Expand Down Expand Up @@ -74,7 +75,7 @@ def _load_enum_from_file(self, path, prefix):
p_with_id = re.compile(r"^ ({}\w+) += +(\w+)".format(prefix))
p_without_id = re.compile(r"^ ({}\w+)".format(prefix))

with open(path, encoding="shift_jis") as f:
with open(path, encoding=self.encoding) as f:
last_enum_id = -1
for line in f.readlines():
m_with_id = p_with_id.match(line)
Expand All @@ -98,11 +99,11 @@ def _load_enum_from_file(self, path, prefix):
last_enum_id = enum_id


def load_enum(c2a_src_path) -> C2aEnum:
c2a_enum = C2aEnum(c2a_src_path)
def load_enum(c2a_src_path, encoding) -> C2aEnum:
c2a_enum = C2aEnum(c2a_src_path, encoding)
return c2a_enum


if __name__ == "__main__":
# 単なる動作確認用
c2a_enum = load_enum(os.path.dirname(__file__) + "/../../..")
c2a_enum = load_enum(os.path.dirname(__file__) + "/../../..", "utf-8")