Skip to content

Commit 15a51e6

Browse files
committed
支持不区分中日部分,整体处理
1 parent e33e2d0 commit 15a51e6

1 file changed

Lines changed: 41 additions & 29 deletions

File tree

zmsub_utils/proc_space_digits.lua

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ include("unicode.lua")
22
require 'zmsub_utils.general'
33
re = require 'aegisub.re'
44

5-
versions.proc_space_digits = '0.4.2'
5+
versions.proc_space_digits = '0.5.0'
66

77
local exp_sep = re.compile("(.*)(\\\\N(?:\\{\\\\fnSource Han Sans JP Bold.*?\\})?)(.*)")
88
local exp_sp = re.compile("[  ]+")
@@ -27,7 +27,7 @@ end
2727

2828
-- 处理对白中的数字,只有一个数字则全角,出现两个以上数字全部半角
2929
function process_partial_digits(text)
30-
local in_tags = false
30+
local in_tags = false -- 避免处理特效标签内的内容
3131
local res_hw = ""
3232
local res_fw = ""
3333
local cnt = 0
@@ -56,40 +56,52 @@ function process_partial_digits(text)
5656
end
5757

5858
-- 处理对白中的数字、空格,中文和日文分开处理
59-
function process_text(text)
60-
local res = exp_sep:match(text)
61-
if not res or #res ~= 4 then
62-
return ''
63-
end
64-
-- 中文部分
65-
local zhs = res[2]['str']
66-
-- 换行符+特效
67-
local sep = res[3]['str']
68-
-- 日文部分
69-
local jps = res[4]['str']
59+
function process_text(text, is_bilingual)
60+
if is_bilingual then
61+
local res = exp_sep:match(text)
62+
if not res or #res ~= 4 then
63+
return ''
64+
end
65+
-- 中文部分
66+
local zhs = res[2]['str']
67+
-- 换行符+特效
68+
local sep = res[3]['str']
69+
-- 日文部分
70+
local jps = res[4]['str']
7071

71-
zhs = process_space(zhs)
72-
zhs = process_partial_digits(zhs)
73-
jps = process_space(jps)
74-
jps = process_partial_digits(jps)
75-
return zhs..sep..jps
72+
zhs = process_space(zhs)
73+
zhs = process_partial_digits(zhs)
74+
jps = process_space(jps)
75+
jps = process_partial_digits(jps)
76+
return zhs..sep..jps
77+
else
78+
text = process_space(text)
79+
text = process_partial_digits(text)
80+
return text
81+
end
7682
end
7783

7884

7985
function proc_space_digits(line)
8086
-- 对白是否包含单个换行符、可能有jptag日字特效标签
8187
local matches = exp_sep:find(line.text)
82-
if not matches or #matches>1 then
88+
-- 如果无换行符,则不区分中日部分,对整行进行处理
89+
local is_bilingual = true
90+
91+
if not matches then
92+
is_bilingual = false
93+
elseif #matches>1 then
94+
-- 格式错误
8395
return false
84-
else
85-
local nt = process_text(line.text)
86-
-- pcall == try catch
87-
-- succ, nt = pcall(process_digits, nt)
88-
if nt == '' then
89-
return false
90-
elseif nt ~= line.text then
91-
line.text = nt
92-
end
93-
return true
9496
end
97+
98+
local nt = process_text(line.text, is_bilingual)
99+
-- pcall == try catch
100+
-- succ, nt = pcall(process_digits, nt)
101+
if nt == '' then
102+
return false
103+
elseif nt ~= line.text then
104+
line.text = nt
105+
end
106+
return true
95107
end

0 commit comments

Comments
 (0)