dotstrings 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fc37db8d1dfc887f3bba22642ab731ca37e2ea3963a7e4998fa843f8b08a1d5
4
- data.tar.gz: a8e82e134a26188fb4ac299cf5b5d02a437f90706844e72cdfe2d6b329681eb8
3
+ metadata.gz: 605ff8ed35fcfcbd91f2fc33a4b53e69b614aab962de1c32c1d616f957ee1916
4
+ data.tar.gz: dddf00d461a893a4ff4e97c04fcc87617241e42189d0284b22e4ab98313ed25a
5
5
  SHA512:
6
- metadata.gz: c21229aef0c1188c8338b4478898d45e31e11a7413d71bb6a9e7200240bc15d15c69f500b9ae031636369c98a0ba912918c706a7f4b45f03eb35c6b30f5426b3
7
- data.tar.gz: 5a1ef97552447cdf70cac24bf943af085fcf0ffd264435180764247f9cde38e8745e42d50254082db13402088a5d11930ca043a487e66bfb9155e7164236e5e0
6
+ metadata.gz: a47fbb334a228e6642d7d6b3250b81ab7c7e239be8fb6ca92ba7877dfe9eb6ac0d3ba2bebe4176477afa9b825e4ce61af4a8d555b83e2a29ed6c176a6d392c90
7
+ data.tar.gz: fa824b2c3c59bee05bb64d59508a6bff112a551d37d6bbc198913433fc8b332a75a17af84a5524a944126fd6e38df8bef008615df303565e729556169eb21bc8
@@ -16,6 +16,7 @@ jobs:
16
16
  - "2.6"
17
17
  - "2.7"
18
18
  - "3.0"
19
+ - "3.1"
19
20
 
20
21
  steps:
21
22
  - uses: actions/checkout@v2
data/.rubocop.yml CHANGED
@@ -14,6 +14,10 @@ Layout/FirstHashElementIndentation:
14
14
  Enabled: true
15
15
  EnforcedStyle: consistent
16
16
 
17
+ Layout/FirstArrayElementIndentation:
18
+ Enabled: true
19
+ EnforcedStyle: consistent
20
+
17
21
  Metrics/ClassLength:
18
22
  Enabled: true
19
23
  Max: 150
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ ## [v0.2.0] - 2022-07-17
4
+ ### Changed
5
+ * Made some state transitions more strict.
6
+ * Added option to ignore comments when serializing.
7
+
8
+ ## [v0.1.1] - 2022-07-12
9
+ ### Changed
10
+ * Escaping single quotes is now optional.
11
+
12
+ ## [v0.1.0] - 2022-07-06
13
+ ### Added
14
+ * Initial release.
15
+
16
+ [v0.2.0]: https://github.com/raymondjavaxx/dotstrings/releases/tag/v0.2.0
17
+ [v0.1.1]: https://github.com/raymondjavaxx/dotstrings/releases/tag/v0.1.1
18
+ [v0.1.0]: https://github.com/raymondjavaxx/dotstrings/releases/tag/v0.1.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dotstrings (0.1.1)
4
+ dotstrings (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -48,11 +48,15 @@ module DotStrings
48
48
  @items.delete_if { |item| item.key == key }
49
49
  end
50
50
 
51
- def to_s(escape_single_quotes: false)
51
+ def to_s(escape_single_quotes: false, comments: true)
52
52
  result = []
53
53
 
54
54
  @items.each do |item|
55
- result << item.to_s(escape_single_quotes: escape_single_quotes)
55
+ result << item.to_s(
56
+ escape_single_quotes: escape_single_quotes,
57
+ include_comment: comments
58
+ )
59
+
56
60
  result << ''
57
61
  end
58
62
 
@@ -10,10 +10,10 @@ module DotStrings
10
10
  @value = value
11
11
  end
12
12
 
13
- def to_s(escape_single_quotes: false)
13
+ def to_s(escape_single_quotes: false, include_comment: true)
14
14
  result = []
15
15
 
16
- result << "/* #{comment} */" unless comment.nil?
16
+ result << "/* #{comment} */" unless comment.nil? || !include_comment
17
17
  result << format('"%<key>s" = "%<value>s";', {
18
18
  key: serialize_string(key, escape_single_quotes: escape_single_quotes),
19
19
  value: serialize_string(value, escape_single_quotes: escape_single_quotes)
@@ -95,19 +95,27 @@ module DotStrings
95
95
  @buffer << ch
96
96
  end
97
97
  when STATE_COMMENT_END
98
- @state = STATE_KEY if ch == TOK_QUOTE
98
+ if ch == TOK_QUOTE
99
+ @state = STATE_KEY
100
+ else
101
+ raise_error("Unexpected character '#{ch}'") unless whitespace?(ch)
102
+ end
99
103
  when STATE_KEY
100
104
  parse_string(ch) do |key|
101
105
  @current_key = key
102
106
  @state = STATE_KEY_END
103
107
  end
104
108
  when STATE_KEY_END
105
- @state = STATE_VALUE_SEPARATOR if ch == TOK_EQUALS
109
+ if ch == TOK_EQUALS
110
+ @state = STATE_VALUE_SEPARATOR
111
+ else
112
+ raise_error("Unexpected character '#{ch}', expecting '#{TOK_EQUALS}'") unless whitespace?(ch)
113
+ end
106
114
  when STATE_VALUE_SEPARATOR
107
115
  if ch == TOK_QUOTE
108
116
  @state = STATE_VALUE
109
117
  else
110
- raise_error("Unexpected character '#{ch}'") unless ch.strip.empty?
118
+ raise_error("Unexpected character '#{ch}'") unless whitespace?(ch)
111
119
  end
112
120
  when STATE_VALUE
113
121
  parse_string(ch) do |value|
@@ -121,7 +129,11 @@ module DotStrings
121
129
  ))
122
130
  end
123
131
  when STATE_VALUE_END
124
- @state = STATE_START if ch == TOK_SEMICOLON
132
+ if ch == TOK_SEMICOLON
133
+ @state = STATE_START
134
+ else
135
+ raise_error("Unexpected character '#{ch}', expecting '#{TOK_SEMICOLON}'") unless whitespace?(ch)
136
+ end
125
137
  when STATE_UNICODE
126
138
  parse_unicode(ch) do |unicode_ch|
127
139
  @buffer << unicode_ch
@@ -236,7 +248,7 @@ module DotStrings
236
248
  @state = STATE_KEY
237
249
  reset_state
238
250
  else
239
- raise_error("Unexpected character '#{ch}'") unless ch.strip.empty?
251
+ raise_error("Unexpected character '#{ch}'") unless whitespace?(ch)
240
252
  end
241
253
  end
242
254
 
@@ -245,6 +257,10 @@ module DotStrings
245
257
  @current_key = nil
246
258
  @current_value = nil
247
259
  end
260
+
261
+ def whitespace?(ch)
262
+ ch.strip.empty?
263
+ end
248
264
  end
249
265
  # rubocop:enable Metrics/ClassLength
250
266
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DotStrings
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
  end
data/test/test_file.rb CHANGED
@@ -38,14 +38,12 @@ class TestFile < MiniTest::Test
38
38
  end
39
39
 
40
40
  def test_to_string
41
- items = [
41
+ file = DotStrings::File.new([
42
42
  DotStrings::Item.new(comment: 'Comment 1', key: 'key 1', value: 'value 1'),
43
43
  DotStrings::Item.new(comment: 'Comment 2', key: 'key 2', value: 'value 2'),
44
44
  DotStrings::Item.new(comment: 'Comment 3', key: 'key 3', value: '👻'),
45
45
  DotStrings::Item.new(comment: 'Comment 4', key: "\"'\t\n\r\0", value: "\"'\t\n\r\0")
46
- ]
47
-
48
- file = DotStrings::File.new(items)
46
+ ])
49
47
 
50
48
  expected = <<~'END_OF_DOCUMENT'
51
49
  /* Comment 1 */
@@ -64,6 +62,21 @@ class TestFile < MiniTest::Test
64
62
  assert_equal expected, file.to_s
65
63
  end
66
64
 
65
+ def test_to_string_no_comments
66
+ file = DotStrings::File.new([
67
+ DotStrings::Item.new(comment: 'Comment 1', key: 'key 1', value: 'value 1'),
68
+ DotStrings::Item.new(comment: 'Comment 2', key: 'key 2', value: 'value 2')
69
+ ])
70
+
71
+ expected = <<~'END_OF_DOCUMENT'
72
+ "key 1" = "value 1";
73
+
74
+ "key 2" = "value 2";
75
+ END_OF_DOCUMENT
76
+
77
+ assert_equal expected, file.to_s(comments: false)
78
+ end
79
+
67
80
  def test_to_string_can_escape_single_quotes
68
81
  items = [
69
82
  DotStrings::Item.new(comment: 'Comment', key: "key'", value: "value'")
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.1
4
+ version: 0.2.0
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-12 00:00:00.000000000 Z
11
+ date: 2022-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,6 +106,7 @@ files:
106
106
  - ".github/workflows/ci.yml"
107
107
  - ".gitignore"
108
108
  - ".rubocop.yml"
109
+ - CHANGELOG.md
109
110
  - Gemfile
110
111
  - Gemfile.lock
111
112
  - LICENSE
@@ -154,8 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
155
  - !ruby/object:Gem::Version
155
156
  version: '0'
156
157
  requirements: []
157
- rubyforge_project:
158
- rubygems_version: 2.7.6
158
+ rubygems_version: 3.0.1
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: Parse and create .strings files used in localization of iOS and macOS apps.