Skip to content

Commit 4933d75

Browse files
committed
complie Regex
1 parent fd483c8 commit 4933d75

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

ASFMKV_dev.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,16 @@ def eventTagsSplit(assInfo: dict, changeOnly: bool = True) -> dict:
378378
reVector2 = re.compile(r'\{.*?\\p[1-9]\d*.*?\}')
379379
reEffect = re.compile(r'\{.*?(?:\\b[1-9]00|\\b[0-1]|\\i[0-1]|\\fn|\\r).*?\}')
380380
reIBon = re.compile(r'\\b[1-9]00|\\b[0-1]|\\i[0-1]|\\fn|\\r')
381+
allTags = re.compile(r'\{.*?\}')
382+
effectDel = re.compile(r'\{.*?\}|\\[nNhs]|\n')
383+
findR = re.compile(r'\\r.*?[\\\}]')
384+
findB = re.compile(r'\\b[7-9]00|\\b1')
385+
findFn = re.compile(r'\\fn.*?[\\\}]')
381386

382387
for i in range(0, len(events)):
383388
if events[i]['Event'] != 'Dialogue':
384389
continue
385390
eventftext = events[i]['Text']
386-
effectDel = r'\{.*?\}|\\[nNhs]|\n'
387391
textremain = ''
388392
# 矢量绘图处理,如果发现有矢量表达,从字符串中删除这一部分
389393
# 这一部分的工作未经详细验证,作用也不大
@@ -417,7 +421,7 @@ def eventTagsSplit(assInfo: dict, changeOnly: bool = True) -> dict:
417421
# 首先查找蕴含有启用粗体/斜体标记的特效标签
418422
if re.search(reEffect, eventftext) is not None:
419423
lastfind = 0
420-
allfind = re.findall(r'\{.*?\}', eventftext)
424+
allfind = re.findall(allTags, eventftext)
421425
eventftext2 = eventftext
422426
# 在所有特效标签中寻找
423427
# 然后分别确认该特效标签的适用范围,以准确将字体子集化b
@@ -429,7 +433,7 @@ def eventTagsSplit(assInfo: dict, changeOnly: bool = True) -> dict:
429433
addbold = lfb
430434
additalic = lfi
431435
# 不管有没有 \r 标签,先获取了再说
432-
rstylel = re.findall(r'\\r.*?[\\\}]', st)
436+
rstylel = re.findall(findR, st)
433437
rfn = lfn
434438
rfb = lfb
435439
rfi = lfi
@@ -451,7 +455,7 @@ def eventTagsSplit(assInfo: dict, changeOnly: bool = True) -> dict:
451455

452456
# 统一获取标签位置
453457
pos_b1 = -1
454-
fbopen = re.findall(r'\\b[7-9]00|\\b1', st)
458+
fbopen = re.findall(findB, st)
455459
if len(fbopen) > 0:
456460
pos_b1 = st.rfind(fbopen[-1])
457461
pos_b0 = max([st.rfind('\\b0'), st.rfind('\\b\\'), st.rfind('\\b}')])
@@ -479,7 +483,7 @@ def eventTagsSplit(assInfo: dict, changeOnly: bool = True) -> dict:
479483

480484
# 处理 \fn 标签 和 \r 标签
481485
if pos_fn > -1:
482-
fnf = re.findall(r'\\fn.*?[\\\}]', st)
486+
fnf = re.findall(findFn, st)
483487
if len(fnf) > 0 and pos_fn > pos_r:
484488
fnn = fnf[-1].split('\\')[1].rstrip('}')[2:].lstrip('@')
485489
if len(fnn) == 0:

0 commit comments

Comments
 (0)