-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfullwidth-to-halfwidth.lua
72 lines (63 loc) · 2.49 KB
/
fullwidth-to-halfwidth.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-- Fullwidth to halfwidth - 全角转半角
-- 把全角的字母、数字转为半角字符,符号也转为常见的符号
-- Copyright (c) 2019, mixj93 <[email protected]>
local tr = aegisub.gettext
script_name = tr("Fullwidth to halfwidth - 全角转半角")
script_description = tr("把全角的字母、数字转为半角字符,符号也转为常见的符号")
script_author = "mixj93"
script_version = "1"
include("unicode.lua")
lookup = {
['1'] = '1', ['2'] = '2', ['3'] = '3', ['4'] = '4',
['5'] = '5', ['6'] = '6', ['7'] = '7', ['8'] = '8',
['9'] = '9', ['0'] = '0',
['A'] = 'A', ['B'] = 'B', ['C'] = 'C', ['D'] = 'D',
['E'] = 'E', ['F'] = 'F', ['G'] = 'G', ['H'] = 'H',
['I'] = 'I', ['J'] = 'J', ['K'] = 'K', ['L'] = 'L',
['M'] = 'M', ['N'] = 'N', ['O'] = 'O', ['P'] = 'P',
['Q'] = 'Q', ['R'] = 'R', ['S'] = 'S', ['T'] = 'T',
['U'] = 'U', ['V'] = 'V', ['W'] = 'W', ['X'] = 'X',
['Y'] = 'Y', ['Z'] = 'Z',
['a'] = 'a', ['b'] = 'b', ['c'] = 'c', ['d'] = 'd',
['e'] = 'e', ['f'] = 'f', ['g'] = 'g', ['h'] = 'h',
['i'] = 'i', ['j'] = 'j', ['k'] = 'k', ['l'] = 'l',
['m'] = 'm', ['n'] = 'n', ['o'] = 'o', ['p'] = 'p',
['q'] = 'q', ['r'] = 'r', ['s'] = 's', ['t'] = 't',
['u'] = 'u', ['v'] = 'v', ['w'] = 'w', ['x'] = 'x',
['y'] = 'y', ['z'] = 'z',
['-'] = '-', ['‥'] = '…', ['"'] = '"'
}
function transform(subtitles, selected_lines, active_line)
for z, i in ipairs(selected_lines) do
local l = subtitles[i]
aegisub.debug.out(string.format('Processing line %d: "%s"\n', i, l.text))
aegisub.debug.out("Chars: \n")
local in_tags = false
local newtext = ""
for c in unicode.chars(l.text) do
aegisub.debug.out(5, c .. ' -> ')
if c == "{" then
in_tags = true
end
if in_tags then
aegisub.debug.out(5, c .. " (ignored, in tags)\n")
newtext = newtext .. c
else
if lookup[c] then
aegisub.debug.out(5, lookup[c] .. " (converted)\n")
newtext = newtext .. lookup[c]
else
aegisub.debug.out(5, c .. " (not found in lookup)\n")
newtext = newtext .. c
end
end
if c == "}" then
in_tags = false
end
end
l.text = newtext
subtitles[i] = l
end
aegisub.set_undo_point(tr"Fullwidth to halfwidth - 全角转半角")
end
aegisub.register_macro(tr"Fullwidth to halfwidth - 全角转半角", tr"把全角的字母、数字转为半角字符,符号也转为常见的符号", transform)