rubustrings 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubustrings/action.rb +47 -7
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bbbadb6f88015382d88dbce31f356de8db8f8730
4
- data.tar.gz: 8b3bd9483ee694595ad3c047e66a2890d468d95c
3
+ metadata.gz: fa19cca952b74543bed45a486114d63af4233bcc
4
+ data.tar.gz: 23d3c792e54fb1b3876dc532ff5a665c6ff5023c
5
5
  SHA512:
6
- metadata.gz: 6d8eeac3b005bfaf6d7133aed1c574fd97cb652bd51619b37a48663e330a53aeb92804cec8955fce07b48b3817788e0d8ee691c4a21532391df5d9eef2d154f9
7
- data.tar.gz: d76e61a91ea79bba6924838422b7ebfcce9c1f120d072ddde0a1db048f9eb7298b18cab34bd959157b1a304aa6bb6cc1fa78d1ea2907bf795f0ce22c05f16cf3
6
+ metadata.gz: 969982b6ac0dc93ac4b7093d0de9d823765ae828b66e48cb508363c40fbf5c3a24bcdfd77dd26a1deba87a1bb7cd6e0d498003d8694dc61b096547f24ea7729d
7
+ data.tar.gz: 9b9ef14a267ca556cfb6e157287e9f63ccbe8bb740690dd8f8b9fd357d7ebd550f43eb0cd3524c063f89445031ee6c9834cc8ff5fdee6eb9acddb99adbb06661
@@ -12,10 +12,8 @@ module Rubustrings
12
12
 
13
13
  if result
14
14
  log_output(:result_success, file_name, 0, 'Strings file validated succesfully')
15
- exit 0
16
15
  else
17
16
  log_output(:result_error, file_name, 0, 'Some errors detected')
18
- exit 1
19
17
  end
20
18
  end
21
19
  end
@@ -84,11 +82,43 @@ module Rubustrings
84
82
  end
85
83
 
86
84
  def validate_special_characters(translation_key, translation_value)
87
- variables_regex = /%[hlqLztj]?[@%dDuUxXoOfeEgGcCsSpaAF]/
88
- key_variables = translation_key.scan(variables_regex)
89
- value_variables = translation_value.scan(variables_regex)
85
+ # Remove %% to avoid ambiguous scenarios with adjacent formats like "%s%%s"
86
+ translation_key = translation_key.gsub("%%", " ")
87
+ translation_value = translation_value.gsub("%%", " ")
88
+
89
+ variables_regex = /\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?(hh|ll|[hlLzjt])?([b-fiosuxX@])/
90
+ position_index = 0
91
+ length_index = 7
92
+ format_index = 8
93
+
94
+ # sort by according to parameter field, if specified
95
+ key_variables = translation_key.scan(variables_regex).stable_sort_by{ |r| r[position_index].to_i }
96
+ value_variables = translation_value.scan(variables_regex).stable_sort_by{ |r| r[position_index].to_i }
97
+
98
+ return true unless key_variables.any? || value_variables.any?
99
+ return false unless key_variables.count == value_variables.count
100
+
101
+ # we should not have any parameter fields in the keys
102
+ return false unless key_variables.last[position_index] == nil
103
+
104
+ # if we do have parameter fields, we need to include all of them
105
+ if value_variables[0][position_index] != nil
106
+ return false unless value_variables.last[position_index] != nil
107
+ validation_result = true
108
+ value_variables.each_with_index { |v, idx|
109
+ if v[position_index].to_i != idx + 1
110
+ validation_result = false
111
+ end
112
+ }
113
+ return false unless validation_result
114
+ else
115
+ return false unless value_variables.last[position_index] == nil
116
+ end
90
117
 
91
- key_variables.sort == value_variables.sort
118
+ # remove parameter field
119
+ key_variables = key_variables.map{ |v| [v[length_index], v[format_index]] }
120
+ value_variables = value_variables.map{ |v| [v[length_index], v[format_index]] }
121
+ key_variables == value_variables
92
122
  end
93
123
 
94
124
  def validate_special_beginning(translation_key, translation_value)
@@ -133,7 +163,7 @@ module Rubustrings
133
163
  log_output(:warning, file_name, line_number, "translation significantly large: #{line}") unless check_translation_length match_key, match_value
134
164
 
135
165
  validation_special_characters = validate_special_characters match_key, match_value
136
- log_output(:error, file_name, line_number, "number of variables mismatch: #{line}") unless validation_special_characters
166
+ log_output(:error, file_name, line_number, "variables mismatch: #{line}") unless validation_special_characters
137
167
 
138
168
  validation_special_beginning = validate_special_beginning match_key, match_value
139
169
  log_output(:error, file_name, line_number, "beginning mismatch: #{line}") unless validation_special_beginning
@@ -145,3 +175,13 @@ module Rubustrings
145
175
  end
146
176
  end
147
177
  end
178
+
179
+ module Enumerable
180
+ def stable_sort
181
+ sort_by.with_index { |x, idx| [x, idx] }
182
+ end
183
+
184
+ def stable_sort_by
185
+ sort_by.with_index { |x, idx| [yield(x), idx] }
186
+ end
187
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubustrings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cordero