rvpacker-txt 1.11.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 -62
- data/lib/extensions.rb +195 -199
- data/lib/read.rb +342 -362
- data/lib/write.rb +247 -187
- 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
|
|
@@ -127,110 +130,103 @@ def self.shuffle_words(array)
|
|
|
127
130
|
end
|
|
128
131
|
end
|
|
129
132
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
# @return [IndexSet<String>] Set of extracted strings
|
|
133
|
-
def extract_quoted_strings(string, mode)
|
|
134
|
-
if mode == :read
|
|
135
|
-
result = IndexSet.new
|
|
136
|
-
|
|
137
|
-
skip_block = false
|
|
138
|
-
in_quotes = false
|
|
139
|
-
quote_type = nil
|
|
140
|
-
buffer = []
|
|
141
|
-
|
|
142
|
-
string.each_line do |line|
|
|
143
|
-
stripped = line.strip
|
|
144
|
-
|
|
145
|
-
next if stripped[0] == '#' ||
|
|
146
|
-
(!in_quotes && !stripped.match?(/["']/)) ||
|
|
147
|
-
stripped.start_with?(/(Win|Lose)|_Fanfare/) ||
|
|
148
|
-
stripped.match?(/eval\(/)
|
|
149
|
-
|
|
150
|
-
skip_block = true if stripped.start_with?('=begin')
|
|
151
|
-
skip_block = false if stripped.start_with?('=end')
|
|
152
|
-
|
|
153
|
-
next if skip_block
|
|
154
|
-
|
|
155
|
-
line.each_char do |char|
|
|
156
|
-
if %w[' "].include?(char)
|
|
157
|
-
unless quote_type.nil? || char == quote_type
|
|
158
|
-
buffer.push(char)
|
|
159
|
-
next
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
quote_type = char
|
|
163
|
-
in_quotes = !in_quotes
|
|
164
|
-
result.add(buffer.join)
|
|
165
|
-
buffer.clear
|
|
166
|
-
next
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
next unless in_quotes
|
|
170
|
-
|
|
171
|
-
if char == "\r"
|
|
172
|
-
next
|
|
173
|
-
elsif char == "\n"
|
|
174
|
-
buffer.push('\#')
|
|
175
|
-
next
|
|
176
|
-
end
|
|
133
|
+
def escaped?(line, index)
|
|
134
|
+
backslash_count = 0
|
|
177
135
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
result
|
|
183
|
-
else
|
|
184
|
-
strings_array = []
|
|
185
|
-
indices_array = []
|
|
186
|
-
|
|
187
|
-
skip_block = false
|
|
188
|
-
in_quotes = false
|
|
189
|
-
quote_type = nil
|
|
190
|
-
buffer = []
|
|
136
|
+
(0..index).reverse_each do |i|
|
|
137
|
+
break if line[i] != '\\'
|
|
138
|
+
backslash_count += 1
|
|
139
|
+
end
|
|
191
140
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
stripped = line.strip
|
|
141
|
+
backslash_count.even?
|
|
142
|
+
end
|
|
195
143
|
|
|
196
|
-
|
|
197
|
-
|
|
144
|
+
# @param [String] ruby_code
|
|
145
|
+
def extract_strings(ruby_code, mode: false)
|
|
146
|
+
strings = mode ? [] : Set.new
|
|
147
|
+
indices = []
|
|
148
|
+
inside_string = false
|
|
149
|
+
inside_multiline_comment = false
|
|
150
|
+
string_start_index = 0
|
|
151
|
+
current_quote_type = ''
|
|
152
|
+
|
|
153
|
+
global_index = 0
|
|
154
|
+
ruby_code.each_line do |line|
|
|
155
|
+
stripped = line.strip
|
|
156
|
+
|
|
157
|
+
unless inside_string
|
|
158
|
+
if stripped[0] == '#'
|
|
159
|
+
global_index += line.length
|
|
198
160
|
next
|
|
199
161
|
end
|
|
200
162
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
current_string_index += line.length
|
|
206
|
-
next
|
|
163
|
+
if stripped.start_with?('=begin')
|
|
164
|
+
inside_multiline_comment = true
|
|
165
|
+
elsif stripped.start_with?('=end')
|
|
166
|
+
inside_multiline_comment = false
|
|
207
167
|
end
|
|
168
|
+
end
|
|
208
169
|
|
|
209
|
-
|
|
170
|
+
if inside_multiline_comment
|
|
171
|
+
global_index += line.length
|
|
172
|
+
next
|
|
173
|
+
end
|
|
210
174
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
buffer.push(char)
|
|
215
|
-
next
|
|
216
|
-
end
|
|
175
|
+
i = 0
|
|
176
|
+
while i < line.length
|
|
177
|
+
char = line[i]
|
|
217
178
|
|
|
218
|
-
|
|
219
|
-
in_quotes = !in_quotes
|
|
179
|
+
break if !inside_string && char == '#'
|
|
220
180
|
|
|
221
|
-
|
|
222
|
-
|
|
181
|
+
if !inside_string && %w[" '].include?(char)
|
|
182
|
+
inside_string = true
|
|
183
|
+
string_start_index = global_index + i
|
|
184
|
+
current_quote_type = char
|
|
185
|
+
elsif inside_string && char == current_quote_type && escaped?(line, i - 1)
|
|
186
|
+
extracted_string = ruby_code[string_start_index + 1...global_index + i].gsub(/\r?\n/, '\#')
|
|
223
187
|
|
|
224
|
-
|
|
225
|
-
|
|
188
|
+
if mode
|
|
189
|
+
strings << extracted_string
|
|
190
|
+
indices << string_start_index + 1
|
|
191
|
+
else
|
|
192
|
+
strings.add(extracted_string)
|
|
226
193
|
end
|
|
227
194
|
|
|
228
|
-
|
|
195
|
+
inside_string = false
|
|
196
|
+
current_quote_type = ''
|
|
229
197
|
end
|
|
230
198
|
|
|
231
|
-
|
|
199
|
+
i += 1
|
|
232
200
|
end
|
|
233
201
|
|
|
234
|
-
|
|
202
|
+
global_index += line.length
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
mode ? [strings, indices] : strings.to_a
|
|
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
|
|
235
229
|
end
|
|
236
|
-
|
|
230
|
+
|
|
231
|
+
raise EncodingError("Cannot convert string #{input_string} to UTF-8")
|
|
232
|
+
end
|