simple_po_parser 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -5
- data/Rakefile +4 -4
- data/lib/simple_po_parser/parser.rb +10 -8
- data/lib/simple_po_parser/version.rb +1 -1
- data/spec/simple_po_parser/fixtures/multiline.po +10 -0
- data/spec/simple_po_parser/parser_spec.rb +10 -0
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b32bc4f19bd4e4967e9395bb2869e377e75f63bac97a0820ced810d03191b73
|
4
|
+
data.tar.gz: 24bb37816cc545d65b2840ad96628bc17b4f7c994eeabe8d0cb43307302c89d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7469e3b963f89d2f35a29cef3d3c7f4fe3bb0e78e9cbbad9fd6e8f9a800a44b804c1193abfefa2685027d773fdf0c86faaa6abab1d0d84df35ca068e6b0eb209
|
7
|
+
data.tar.gz: 1283c455623d2e8c387e8b57d963dffd11a244dfdd4c4049f10444c4cf1fffa3adc5c9c59b83c8c463ac0167c1bd410741a1c17bd06b70f50e7822d8e8fb3bf2
|
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,35 @@
|
|
1
|
-
|
1
|
+
Changelog
|
2
2
|
=============
|
3
3
|
|
4
|
+
## Version 1.1.6
|
5
|
+
* fixes parsing of multiline strings that have content on the first line. Fixes issue #3, added via PR #4 by @mgruner
|
6
|
+
|
7
|
+
## Version 1.1.5
|
8
|
+
* added support for windows CRLF line endings. Fixes issue #2
|
9
|
+
* Note: CRLF support is enabled if the first line ends in a CRLF and reduces performance by about 50%. Performance for files only using \n is not affected. Files not using \r\n in the first line but somewhere else in the file might trigger errors.
|
10
|
+
|
11
|
+
## Version 1.1.4
|
12
|
+
* see 1.1.5. **Shouldn't be used**.
|
13
|
+
|
14
|
+
## Version 1.1.3
|
15
|
+
|
16
|
+
* merged PR#1 from @christopherstat for UTF-8 support of legacy ruby versions
|
17
|
+
|
18
|
+
## Version 1.1.2
|
19
|
+
* Made the parser thread-safe
|
20
|
+
|
21
|
+
## Version 1.1.2
|
22
|
+
* Made the parser thread-safe
|
23
|
+
|
24
|
+
## Version 1.1.0
|
25
|
+
|
4
26
|
* for line types only parsed once the parser returns a string instead of an array with one string
|
5
27
|
|
6
|
-
Version 1.0.1
|
7
|
-
=============
|
28
|
+
## Version 1.0.1
|
8
29
|
|
9
30
|
* added specs
|
10
31
|
* fixed minor parser errors
|
11
32
|
|
12
|
-
Version 1.0.0
|
13
|
-
=============
|
33
|
+
## Version 1.0.0
|
14
34
|
|
15
35
|
* initial release
|
data/Rakefile
CHANGED
@@ -20,15 +20,15 @@ namespace :parser do
|
|
20
20
|
require 'benchmark'
|
21
21
|
require 'simple_po_parser'
|
22
22
|
|
23
|
-
desc "Benchmark of
|
23
|
+
desc "Benchmark of 1000 full PoParser runs of test/benchmark.po"
|
24
24
|
task "benchmark" do
|
25
25
|
pofile = File.expand_path("test/benchmark.po", __dir__)
|
26
26
|
Benchmark.bmbm do |x|
|
27
|
-
x.report("Parser:") {
|
27
|
+
x.report("Parser:") {1000.times { SimplePoParser.parse(pofile) }}
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
desc "Generate 5 random PO files with
|
31
|
+
desc "Generate 5 random PO files with 1000 to 5000 messages and benchmark each full PoParser run"
|
32
32
|
task 'five_random_po_full' do
|
33
33
|
include Benchmark
|
34
34
|
require_relative 'spec/utils/random_pofile_generator'
|
@@ -37,7 +37,7 @@ namespace :parser do
|
|
37
37
|
total = nil
|
38
38
|
total_length = 0
|
39
39
|
for i in 0..5 do
|
40
|
-
length = (Random.new.rand *
|
40
|
+
length = (Random.new.rand * 4000.0 + 1000).to_i
|
41
41
|
total_length += length
|
42
42
|
puts "Benchmarking file of length #{length}"
|
43
43
|
SimplePoParser::RandomPoFileGenerator.generate_file(pofile, length)
|
@@ -109,7 +109,7 @@ module SimplePoParser
|
|
109
109
|
skip_whitespace
|
110
110
|
text = message_line
|
111
111
|
add_result(:msgctxt, text)
|
112
|
-
message_multiline(:msgctxt) if
|
112
|
+
message_multiline(:msgctxt) if @scanner.peek(1) == '"'
|
113
113
|
end
|
114
114
|
msgid
|
115
115
|
rescue PoSyntaxError => pe
|
@@ -127,7 +127,7 @@ module SimplePoParser
|
|
127
127
|
skip_whitespace
|
128
128
|
text = message_line
|
129
129
|
add_result(:msgid, text)
|
130
|
-
message_multiline(:msgid) if
|
130
|
+
message_multiline(:msgid) if @scanner.peek(1) == '"'
|
131
131
|
if msgid_plural
|
132
132
|
msgstr_plural
|
133
133
|
else
|
@@ -155,7 +155,7 @@ module SimplePoParser
|
|
155
155
|
skip_whitespace
|
156
156
|
text = message_line
|
157
157
|
add_result(:msgid_plural, text)
|
158
|
-
message_multiline(:msgid_plural) if
|
158
|
+
message_multiline(:msgid_plural) if @scanner.peek(1) == '"'
|
159
159
|
true
|
160
160
|
else
|
161
161
|
false
|
@@ -174,7 +174,7 @@ module SimplePoParser
|
|
174
174
|
skip_whitespace
|
175
175
|
text = message_line
|
176
176
|
add_result(:msgstr, text)
|
177
|
-
message_multiline(:msgstr) if
|
177
|
+
message_multiline(:msgstr) if @scanner.peek(1) == '"'
|
178
178
|
skip_whitespace
|
179
179
|
raise PoSyntaxError, "Unexpected content after expected message end #{@scanner.peek(10).inspect}" unless @scanner.eos?
|
180
180
|
else
|
@@ -202,7 +202,7 @@ module SimplePoParser
|
|
202
202
|
skip_whitespace
|
203
203
|
text = message_line
|
204
204
|
add_result(msgstr_key, text)
|
205
|
-
message_multiline(msgstr_key) if
|
205
|
+
message_multiline(msgstr_key) if @scanner.peek(1) == '"'
|
206
206
|
msgstr_plural(num+1)
|
207
207
|
elsif num == 0 # and msgstr_key was false
|
208
208
|
raise PoSyntaxError, "Plural message without msgstr[0] is not allowed. Line started unexpectedly with #{@scanner.peek(10).inspect}."
|
@@ -238,7 +238,7 @@ module SimplePoParser
|
|
238
238
|
skip_whitespace
|
239
239
|
text = message_line
|
240
240
|
add_result(key, text)
|
241
|
-
previous_multiline(key) if
|
241
|
+
previous_multiline(key) if @scanner.match?(/#\|\p{Blank}*"/)
|
242
242
|
else
|
243
243
|
raise PoSyntaxError, "Previous comments must start with '#| msg'. #{@scanner.peek(10).inspect} unknown."
|
244
244
|
end
|
@@ -265,8 +265,10 @@ module SimplePoParser
|
|
265
265
|
|
266
266
|
# parses a multiline message
|
267
267
|
#
|
268
|
-
#
|
269
|
-
# starting with the double quote character
|
268
|
+
# Multiline messages are usually indicated by an empty string as the first line,
|
269
|
+
# followed by more lines starting with the double quote character.
|
270
|
+
#
|
271
|
+
# However, according to the PO file standard, the first line can also contain content.
|
270
272
|
def message_multiline(key)
|
271
273
|
begin
|
272
274
|
skip_whitespace
|
@@ -4,6 +4,7 @@ describe SimplePoParser::Parser do
|
|
4
4
|
let (:po_header) { File.read(File.expand_path("fixtures/header.po", __dir__))}
|
5
5
|
let(:po_complex_message) { File.read(File.expand_path("fixtures/complex_entry.po", __dir__))}
|
6
6
|
let(:po_simple_message) { File.read(File.expand_path("fixtures/simple_entry.po", __dir__))}
|
7
|
+
let(:po_multiline_message) { File.read(File.expand_path("fixtures/multiline.po", __dir__))}
|
7
8
|
|
8
9
|
it "parses the PO header" do
|
9
10
|
expected_result = {
|
@@ -27,6 +28,15 @@ describe SimplePoParser::Parser do
|
|
27
28
|
expect(SimplePoParser::Parser.new.parse(po_simple_message)).to eq(expected_result)
|
28
29
|
end
|
29
30
|
|
31
|
+
it "parses the multiline entry as expected" do
|
32
|
+
expected_result = {
|
33
|
+
:msgid => ["", "multiline string ", "with empty first line ", "and trailing spaces"],
|
34
|
+
:msgstr => ["multiline string", "with non-empty first line", "and no trailing spaces"],
|
35
|
+
:previous_msgid => ["multiline\\n", "previous messageid", "with non-empty first line"],
|
36
|
+
}
|
37
|
+
expect(SimplePoParser::Parser.new.parse(po_multiline_message)).to eq(expected_result)
|
38
|
+
end
|
39
|
+
|
30
40
|
it "parses the complex entry as expected" do
|
31
41
|
expected_result = {
|
32
42
|
:translator_comment => ["translator-comment", ""],
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_po_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis-Florian Herr
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- spec/simple_po_parser/fixtures/complex_entry.po
|
66
66
|
- spec/simple_po_parser/fixtures/crlf_encoded.po
|
67
67
|
- spec/simple_po_parser/fixtures/header.po
|
68
|
+
- spec/simple_po_parser/fixtures/multiline.po
|
68
69
|
- spec/simple_po_parser/fixtures/non_ascii_file.po
|
69
70
|
- spec/simple_po_parser/fixtures/simple_entry.po
|
70
71
|
- spec/simple_po_parser/parser_spec.rb
|
@@ -76,7 +77,7 @@ homepage: http://github.com/experteer/simple_po_parser
|
|
76
77
|
licenses:
|
77
78
|
- MIT
|
78
79
|
metadata: {}
|
79
|
-
post_install_message:
|
80
|
+
post_install_message:
|
80
81
|
rdoc_options: []
|
81
82
|
require_paths:
|
82
83
|
- lib
|
@@ -91,9 +92,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
92
|
- !ruby/object:Gem::Version
|
92
93
|
version: '0'
|
93
94
|
requirements: []
|
94
|
-
|
95
|
-
|
96
|
-
signing_key:
|
95
|
+
rubygems_version: 3.2.15
|
96
|
+
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: A simple PO file to ruby hash parser
|
99
99
|
test_files:
|
@@ -101,6 +101,7 @@ test_files:
|
|
101
101
|
- spec/simple_po_parser/fixtures/complex_entry.po
|
102
102
|
- spec/simple_po_parser/fixtures/crlf_encoded.po
|
103
103
|
- spec/simple_po_parser/fixtures/header.po
|
104
|
+
- spec/simple_po_parser/fixtures/multiline.po
|
104
105
|
- spec/simple_po_parser/fixtures/non_ascii_file.po
|
105
106
|
- spec/simple_po_parser/fixtures/simple_entry.po
|
106
107
|
- spec/simple_po_parser/parser_spec.rb
|