rvpacker-txt 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +20 -24
- data/bin/rvpacker-txt +184 -126
- data/lib/classes.rb +23 -25
- data/lib/extensions.rb +143 -116
- data/lib/read.rb +328 -321
- data/lib/write.rb +245 -178
- data/rvpacker-txt.gemspec +12 -2
- metadata +4 -4
- /data/{LICENSE → LICENSE.md} +0 -0
data/lib/extensions.rb
CHANGED
|
@@ -1,120 +1,123 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# @param [String]
|
|
3
|
+
# @param [String] input_string
|
|
4
4
|
# @return [String]
|
|
5
|
-
def self.romanize_string(
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
5
|
+
def self.romanize_string(input_string)
|
|
6
|
+
# @type [Array<String>]
|
|
7
|
+
result = []
|
|
8
|
+
|
|
9
|
+
input_string.each_char do |char|
|
|
10
|
+
result << case char
|
|
11
|
+
when '。'
|
|
12
|
+
'.'
|
|
13
|
+
when '、', ','
|
|
14
|
+
','
|
|
15
|
+
when '・'
|
|
16
|
+
'·'
|
|
17
|
+
when '゠'
|
|
18
|
+
'–'
|
|
19
|
+
when '=', 'ー'
|
|
20
|
+
'—'
|
|
21
|
+
when '…', '‥'
|
|
22
|
+
'...'
|
|
23
|
+
when '「', '」', '〈', '〉'
|
|
24
|
+
"'"
|
|
25
|
+
when '『', '』', '《', '》'
|
|
26
|
+
'"'
|
|
27
|
+
when '(', '〔', '⦅', '〘'
|
|
28
|
+
'('
|
|
29
|
+
when ')', '〕', '⦆', '〙'
|
|
30
|
+
')'
|
|
31
|
+
when '{'
|
|
32
|
+
'{'
|
|
33
|
+
when '}'
|
|
34
|
+
'}'
|
|
35
|
+
when '[', '【', '〖', '〚'
|
|
36
|
+
'['
|
|
37
|
+
when ']', '】', '〗', '〛'
|
|
38
|
+
']'
|
|
39
|
+
when '〜'
|
|
40
|
+
'~'
|
|
41
|
+
when '?'
|
|
42
|
+
'?'
|
|
43
|
+
when ':'
|
|
44
|
+
':'
|
|
45
|
+
when '!'
|
|
46
|
+
'!'
|
|
47
|
+
when '※'
|
|
48
|
+
'*'
|
|
49
|
+
when ' '
|
|
50
|
+
' '
|
|
51
|
+
when 'Ⅰ'
|
|
52
|
+
'I'
|
|
53
|
+
when 'ⅰ'
|
|
54
|
+
'i'
|
|
55
|
+
when 'Ⅱ'
|
|
56
|
+
'II'
|
|
57
|
+
when 'ⅱ'
|
|
58
|
+
'ii'
|
|
59
|
+
when 'Ⅲ'
|
|
60
|
+
'III'
|
|
61
|
+
when 'ⅲ'
|
|
62
|
+
'iii'
|
|
63
|
+
when 'Ⅳ'
|
|
64
|
+
'IV'
|
|
65
|
+
when 'ⅳ'
|
|
66
|
+
'iv'
|
|
67
|
+
when 'Ⅴ'
|
|
68
|
+
'V'
|
|
69
|
+
when 'ⅴ'
|
|
70
|
+
'v'
|
|
71
|
+
when 'Ⅵ'
|
|
72
|
+
'VI'
|
|
73
|
+
when 'ⅵ'
|
|
74
|
+
'vi'
|
|
75
|
+
when 'Ⅶ'
|
|
76
|
+
'VII'
|
|
77
|
+
when 'ⅶ'
|
|
78
|
+
'vii'
|
|
79
|
+
when 'Ⅷ'
|
|
80
|
+
'VIII'
|
|
81
|
+
when 'ⅷ'
|
|
82
|
+
'viii'
|
|
83
|
+
when 'Ⅸ'
|
|
84
|
+
'IX'
|
|
85
|
+
when 'ⅸ'
|
|
86
|
+
'ix'
|
|
87
|
+
when 'Ⅹ'
|
|
88
|
+
'X'
|
|
89
|
+
when 'ⅹ'
|
|
90
|
+
'x'
|
|
91
|
+
when 'Ⅺ'
|
|
92
|
+
'XI'
|
|
93
|
+
when 'ⅺ'
|
|
94
|
+
'xi'
|
|
95
|
+
when 'Ⅻ'
|
|
96
|
+
'XII'
|
|
97
|
+
when 'ⅻ'
|
|
98
|
+
'xii'
|
|
99
|
+
when 'Ⅼ'
|
|
100
|
+
'L'
|
|
101
|
+
when 'ⅼ'
|
|
102
|
+
'l'
|
|
103
|
+
when 'Ⅽ'
|
|
104
|
+
'C'
|
|
105
|
+
when 'ⅽ'
|
|
106
|
+
'c'
|
|
107
|
+
when 'Ⅾ'
|
|
108
|
+
'D'
|
|
109
|
+
when 'ⅾ'
|
|
110
|
+
'd'
|
|
111
|
+
when 'Ⅿ'
|
|
112
|
+
'M'
|
|
113
|
+
when 'ⅿ'
|
|
114
|
+
'm'
|
|
115
|
+
else
|
|
116
|
+
char
|
|
114
117
|
end
|
|
115
118
|
end
|
|
116
119
|
|
|
117
|
-
|
|
120
|
+
result.join
|
|
118
121
|
end
|
|
119
122
|
|
|
120
123
|
# @param [Array<String>] array Array of strings
|
|
@@ -139,7 +142,7 @@ def escaped?(line, index)
|
|
|
139
142
|
end
|
|
140
143
|
|
|
141
144
|
# @param [String] ruby_code
|
|
142
|
-
def extract_strings(ruby_code, mode
|
|
145
|
+
def extract_strings(ruby_code, mode: false)
|
|
143
146
|
strings = mode ? [] : Set.new
|
|
144
147
|
indices = []
|
|
145
148
|
inside_string = false
|
|
@@ -173,11 +176,9 @@ def extract_strings(ruby_code, mode = false)
|
|
|
173
176
|
while i < line.length
|
|
174
177
|
char = line[i]
|
|
175
178
|
|
|
176
|
-
if !inside_string && char == '#'
|
|
177
|
-
break
|
|
178
|
-
end
|
|
179
|
+
break if !inside_string && char == '#'
|
|
179
180
|
|
|
180
|
-
if !inside_string && [
|
|
181
|
+
if !inside_string && %w[" '].include?(char)
|
|
181
182
|
inside_string = true
|
|
182
183
|
string_start_index = global_index + i
|
|
183
184
|
current_quote_type = char
|
|
@@ -203,3 +204,29 @@ def extract_strings(ruby_code, mode = false)
|
|
|
203
204
|
|
|
204
205
|
mode ? [strings, indices] : strings.to_a
|
|
205
206
|
end
|
|
207
|
+
|
|
208
|
+
ENCODINGS = %w[
|
|
209
|
+
ISO-8859-1
|
|
210
|
+
Windows-1252
|
|
211
|
+
Shift_JIS
|
|
212
|
+
GB18030
|
|
213
|
+
EUC-JP
|
|
214
|
+
ISO-2022-JP
|
|
215
|
+
BIG5
|
|
216
|
+
EUC-KR
|
|
217
|
+
Windows-1251
|
|
218
|
+
KOI8-R
|
|
219
|
+
UTF-8
|
|
220
|
+
].freeze
|
|
221
|
+
|
|
222
|
+
# @param [String] input_string
|
|
223
|
+
# @return [String]
|
|
224
|
+
def convert_to_utf8(input_string)
|
|
225
|
+
ENCODINGS.each do |encoding|
|
|
226
|
+
return input_string.encode('UTF-8', encoding)
|
|
227
|
+
rescue Encoding::InvalidByteSequenceError, Encoding::UndefinedConversionError
|
|
228
|
+
next
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
raise EncodingError("Cannot convert string #{input_string} to UTF-8")
|
|
232
|
+
end
|