update m3tpostprocess

This commit is contained in:
2026-06-07 23:46:56 +08:00
parent 5fd346bb65
commit e4b0e95146

View File

@@ -140,24 +140,31 @@ def process_circus_line(data: str) -> str:
def replace_quote_str(s) -> str:
all_left_quotes = set(CJK_LEFT_QUOTE + NEED_REPLACED_LEFT_QUOTE)
all_right_quotes = set(CJK_RIGHT_QUOTE + NEED_REPLACED_RIGHT_QUOTE)
starts_with_left = len(s) > 0 and s[0] in all_left_quotes
ends_with_right = len(s) > 0 and s[-1] in all_right_quotes
# 引号只出现在头尾时(整个字符串被引号包裹),最外层使用「」;
# 否则最外层使用『』
offset = 0 if (starts_with_left and ends_with_right) else 1
depth = 0
re = ""
result = ""
for c in s:
if c in CJK_LEFT_QUOTE:
re += CJK_LEFT_QUOTE[depth % 2]
result += CJK_LEFT_QUOTE[(depth + offset) % 2]
depth += 1
elif c in CJK_RIGHT_QUOTE:
depth -= 1
re += CJK_RIGHT_QUOTE[depth % 2]
result += CJK_RIGHT_QUOTE[(depth + offset) % 2]
elif c in NEED_REPLACED_LEFT_QUOTE:
re += CJK_LEFT_QUOTE[depth % 2]
result += CJK_LEFT_QUOTE[(depth + offset) % 2]
depth += 1
elif c in NEED_REPLACED_RIGHT_QUOTE:
depth -= 1
re += CJK_RIGHT_QUOTE[depth % 2]
result += CJK_RIGHT_QUOTE[(depth + offset) % 2]
else:
re += c
return re
result += c
return result
def check_dialogue(source: str, target: str) -> str: