mirror of
https://github.com/1j01/textual-paint.git
synced 2024-12-30 18:23:03 +03:00
Complete type checking of file I'm not even using
This commit is contained in:
parent
625324e66b
commit
11f3319ced
@ -7,10 +7,12 @@ def parse_rc_file(rc_file_text: str) -> list[str]:
|
||||
"""
|
||||
Parses a Windows RC file and returns a list of strings.
|
||||
"""
|
||||
strings = []
|
||||
menu = dialog = stringtable = False
|
||||
strings: list[str] = []
|
||||
menu = dialog = False
|
||||
# stringtable = False
|
||||
block_level = 0
|
||||
id_str = dialog_id = hint = orig_str = None
|
||||
id_str = dialog_id = orig_str = None
|
||||
# hint = None
|
||||
|
||||
for line in rc_file_text.splitlines():
|
||||
norm_line = re.sub(r'[\t ]+', ' ', line.strip())
|
||||
@ -24,8 +26,8 @@ def parse_rc_file(rc_file_text: str) -> list[str]:
|
||||
dialog_id = dialog_match.group(1)
|
||||
dialog = True
|
||||
|
||||
if norm_line == 'STRINGTABLE':
|
||||
stringtable = True
|
||||
# if norm_line == 'STRINGTABLE':
|
||||
# stringtable = True
|
||||
|
||||
if norm_line == 'BEGIN':
|
||||
block_level += 1
|
||||
@ -33,20 +35,21 @@ def parse_rc_file(rc_file_text: str) -> list[str]:
|
||||
if norm_line == 'END':
|
||||
block_level -= 1
|
||||
if block_level == 0:
|
||||
menu = dialog = dialog_id = stringtable = None
|
||||
menu = dialog = dialog_id = None
|
||||
# stringtable = False
|
||||
|
||||
if dialog and not block_level:
|
||||
match = re.match(r'^[\t ]*(CAPTION)[\t ]+(L?"(.*?("")*)*?")', line)
|
||||
if match:
|
||||
id_str = f"{dialog_id}:{match.group(1)}"
|
||||
hint = f"{dialog_id} {match.group(1)}"
|
||||
# hint = f"{dialog_id} {match.group(1)}"
|
||||
orig_str = match.group(2)
|
||||
|
||||
elif (menu or dialog) and block_level:
|
||||
match = re.match(r'^[\t ]*(\w+)[\t ]+(L?"([^"]*?("")*)*?")(,[\t ]*(\w+)){0,1}', line)
|
||||
if match:
|
||||
id_str = match.group(6)
|
||||
hint = f"{match.group(1)} {match.group(6)}" if match.group(6) else match.group(1)
|
||||
# hint = f"{match.group(1)} {match.group(6)}" if match.group(6) else match.group(1)
|
||||
orig_str = match.group(2)
|
||||
|
||||
else:
|
||||
@ -60,22 +63,23 @@ def parse_rc_file(rc_file_text: str) -> list[str]:
|
||||
else:
|
||||
match = re.match(r'^[\t ]*(L?"(.*)")', line)
|
||||
if id_str and match:
|
||||
hint = id_str
|
||||
# hint = id_str
|
||||
orig_str = match.group(1)
|
||||
else:
|
||||
id_str = None
|
||||
|
||||
if orig_str:
|
||||
str = orig_str
|
||||
new_str = orig_str
|
||||
|
||||
wide = str.startswith('L')
|
||||
str = re.sub(r'^L?"(.*)"$', r'\1', str)
|
||||
str = str.replace(r'\r', '\r').replace(r'\n', '\n').replace(r'\t', '\t').replace(r'\\"', '"')
|
||||
wide = new_str.startswith('L')
|
||||
new_str = re.sub(r'^L?"(.*)"$', r'\1', new_str)
|
||||
new_str = new_str.replace(r'\r', '\r').replace(r'\n', '\n').replace(r'\t', '\t').replace(r'\\"', '"')
|
||||
if wide:
|
||||
str = re.sub(r'\\x([0-9a-fA-F]{4})', lambda match: chr(int(match.group(1), 16)), str)
|
||||
new_str = re.sub(r'\\x([0-9a-fA-F]{4})', lambda match: chr(int(match.group(1), 16)), new_str)
|
||||
|
||||
strings.append(str)
|
||||
strings.append(new_str)
|
||||
|
||||
id_str = hint = orig_str = None
|
||||
id_str = orig_str = None
|
||||
# hint = None
|
||||
|
||||
return strings
|
||||
|
Loading…
Reference in New Issue
Block a user