dotstrings 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/Gemfile.lock +1 -1
- data/lib/dotstrings/file.rb +2 -2
- data/lib/dotstrings/item.rb +8 -4
- data/lib/dotstrings/version.rb +1 -1
- data/test/test_file.rb +16 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fc37db8d1dfc887f3bba22642ab731ca37e2ea3963a7e4998fa843f8b08a1d5
|
4
|
+
data.tar.gz: a8e82e134a26188fb4ac299cf5b5d02a437f90706844e72cdfe2d6b329681eb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c21229aef0c1188c8338b4478898d45e31e11a7413d71bb6a9e7200240bc15d15c69f500b9ae031636369c98a0ba912918c706a7f4b45f03eb35c6b30f5426b3
|
7
|
+
data.tar.gz: 5a1ef97552447cdf70cac24bf943af085fcf0ffd264435180764247f9cde38e8745e42d50254082db13402088a5d11930ca043a487e66bfb9155e7164236e5e0
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/lib/dotstrings/file.rb
CHANGED
@@ -48,11 +48,11 @@ module DotStrings
|
|
48
48
|
@items.delete_if { |item| item.key == key }
|
49
49
|
end
|
50
50
|
|
51
|
-
def to_s
|
51
|
+
def to_s(escape_single_quotes: false)
|
52
52
|
result = []
|
53
53
|
|
54
54
|
@items.each do |item|
|
55
|
-
result << item.to_s
|
55
|
+
result << item.to_s(escape_single_quotes: escape_single_quotes)
|
56
56
|
result << ''
|
57
57
|
end
|
58
58
|
|
data/lib/dotstrings/item.rb
CHANGED
@@ -10,27 +10,31 @@ module DotStrings
|
|
10
10
|
@value = value
|
11
11
|
end
|
12
12
|
|
13
|
-
def to_s
|
13
|
+
def to_s(escape_single_quotes: false)
|
14
14
|
result = []
|
15
15
|
|
16
16
|
result << "/* #{comment} */" unless comment.nil?
|
17
|
-
result << "
|
17
|
+
result << format('"%<key>s" = "%<value>s";', {
|
18
|
+
key: serialize_string(key, escape_single_quotes: escape_single_quotes),
|
19
|
+
value: serialize_string(value, escape_single_quotes: escape_single_quotes)
|
20
|
+
})
|
18
21
|
|
19
22
|
result.join("\n")
|
20
23
|
end
|
21
24
|
|
22
25
|
private
|
23
26
|
|
24
|
-
def serialize_string(string)
|
27
|
+
def serialize_string(string, escape_single_quotes:)
|
25
28
|
replacements = [
|
26
29
|
['"', '\\"'],
|
27
|
-
["'", "\\'"],
|
28
30
|
["\t", '\t'],
|
29
31
|
["\n", '\n'],
|
30
32
|
["\r", '\r'],
|
31
33
|
["\0", '\\0']
|
32
34
|
]
|
33
35
|
|
36
|
+
replacements << ["'", "\\'"] if escape_single_quotes
|
37
|
+
|
34
38
|
replacements.each do |replacement|
|
35
39
|
string = string.gsub(replacement[0]) { replacement[1] }
|
36
40
|
end
|
data/lib/dotstrings/version.rb
CHANGED
data/test/test_file.rb
CHANGED
@@ -58,9 +58,24 @@ class TestFile < MiniTest::Test
|
|
58
58
|
"key 3" = "👻";
|
59
59
|
|
60
60
|
/* Comment 4 */
|
61
|
-
"\"
|
61
|
+
"\"'\t\n\r\0" = "\"'\t\n\r\0";
|
62
62
|
END_OF_DOCUMENT
|
63
63
|
|
64
64
|
assert_equal expected, file.to_s
|
65
65
|
end
|
66
|
+
|
67
|
+
def test_to_string_can_escape_single_quotes
|
68
|
+
items = [
|
69
|
+
DotStrings::Item.new(comment: 'Comment', key: "key'", value: "value'")
|
70
|
+
]
|
71
|
+
|
72
|
+
file = DotStrings::File.new(items)
|
73
|
+
|
74
|
+
expected = <<~'END_OF_DOCUMENT'
|
75
|
+
/* Comment */
|
76
|
+
"key\'" = "value\'";
|
77
|
+
END_OF_DOCUMENT
|
78
|
+
|
79
|
+
assert_equal expected, file.to_s(escape_single_quotes: true)
|
80
|
+
end
|
66
81
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotstrings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ramon Torres
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -154,7 +154,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
154
|
- !ruby/object:Gem::Version
|
155
155
|
version: '0'
|
156
156
|
requirements: []
|
157
|
-
|
157
|
+
rubyforge_project:
|
158
|
+
rubygems_version: 2.7.6
|
158
159
|
signing_key:
|
159
160
|
specification_version: 4
|
160
161
|
summary: Parse and create .strings files used in localization of iOS and macOS apps.
|