java-properties 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a3e467287d2328e09893d5975725e9d0bfde497
4
- data.tar.gz: a775715d414e13dd7afa7bb36cc603013c334e84
3
+ metadata.gz: d4f07c15c1f58cb3478fab7debf52316d9649cc3
4
+ data.tar.gz: 7b340371a2ea3b0420fb2e0ee532e926fd8bc006
5
5
  SHA512:
6
- metadata.gz: 33dba5e873cb1a2bf16e7d74561a043e5770c313346e958cc0c6b7c4947b1e7f70a3079899a7b4e7902236316ee0c96ae62aa1168c817663ad151fe75cf53c58
7
- data.tar.gz: da4f1c8dcdc65b8c730777be9777e7ea9d999f68762b6dc7e847d2341563cfd49c2cea0587822b5dabd3a3e4ed8b63e39271e2a51e64942ec06f4529ad2c483d
6
+ metadata.gz: c9c763b44183f8e3175326d1d699af24386cdc6abe95b6de3df9fa5514ed6ade61470be36a84403e032238403ac8eca5bf1dd036d5fb59e4db5ed6b7b8581491
7
+ data.tar.gz: 08865b814f74ab2fb98381843a0550b25b107a825ecc985813db0580c2f24d3aefab9f1914b50b787c05819d1a3c242bb595d5bb1e787e5d7d412b75cb487492
data/README.md CHANGED
@@ -61,6 +61,7 @@ As Java properties files normally hold UTF-8 chars in their escaped representati
61
61
 
62
62
  ```
63
63
  "ה" <=> "\u05d4"
64
+ "𪀯" <=> "\ud868\udc2f"
64
65
  ```
65
66
 
66
67
  The tool also escaped every '=', ' ' and ':' in the name part of a property line:
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
  spec.test_files = Dir.glob("spec/fixtures/**/*.properties")
21
21
 
22
22
  spec.required_rubygems_version = '>= 1.3.5'
23
- end
23
+ spec.required_ruby_version = '~> 2.0'
24
+ end
@@ -1,24 +1,63 @@
1
1
  module JavaProperties
2
2
  module Encoding
3
3
  # Module to encode and decode unicode chars
4
- # @see JavaProperties::Encoding
4
+ # This code is highly influced by Florian Frank's JSON gem
5
+ # @see https://github.com/flori/json/
5
6
  module Unicode
6
7
 
7
- # Marker for encoded unicode chars
8
- # @return [Regexp]
9
- UNICODE_MARKER = /\\[uU]([0-9a-fA-F]{4,5}|10[0-9a-fA-F]{4})/
8
+ # @private
9
+ MAP = {
10
+ "\x0" => '\u0000',
11
+ "\x1" => '\u0001',
12
+ "\x2" => '\u0002',
13
+ "\x3" => '\u0003',
14
+ "\x4" => '\u0004',
15
+ "\x5" => '\u0005',
16
+ "\x6" => '\u0006',
17
+ "\x7" => '\u0007',
18
+ "\xb" => '\u000b',
19
+ "\xe" => '\u000e',
20
+ "\xf" => '\u000f',
21
+ "\x10" => '\u0010',
22
+ "\x11" => '\u0011',
23
+ "\x12" => '\u0012',
24
+ "\x13" => '\u0013',
25
+ "\x14" => '\u0014',
26
+ "\x15" => '\u0015',
27
+ "\x16" => '\u0016',
28
+ "\x17" => '\u0017',
29
+ "\x18" => '\u0018',
30
+ "\x19" => '\u0019',
31
+ "\x1a" => '\u001a',
32
+ "\x1b" => '\u001b',
33
+ "\x1c" => '\u001c',
34
+ "\x1d" => '\u001d',
35
+ "\x1e" => '\u001e',
36
+ "\x1f" => '\u001f',
37
+ }
10
38
 
11
- # Escape char for unicode chars
12
- # @return [String]
13
- UNICODE_ESCAPE = "\\u"
39
+ # @private
40
+ EMPTY_8BIT_STRING = ''
41
+ EMPTY_8BIT_STRING.force_encoding(::Encoding::ASCII_8BIT)
14
42
 
15
43
  # Decodes all unicode chars from escape sequences in place
16
44
  # @param text [String]
17
45
  # @return [String] The encoded text for chaining
18
46
  def self.decode!(text)
19
- text.gsub!(UNICODE_MARKER) do
20
- unicode($1.hex)
47
+ string = text.dup
48
+ string = string.gsub(%r((?:\\[uU](?:[A-Fa-f\d]{4}))+)) do |c|
49
+ c.downcase!
50
+ bytes = EMPTY_8BIT_STRING.dup
51
+ i = 0
52
+ while c[6 * i] == ?\\ && c[6 * i + 1] == ?u
53
+ bytes << c[6 * i + 2, 2].to_i(16) << c[6 * i + 4, 2].to_i(16)
54
+ i += 1
55
+ end
56
+ bytes.encode("utf-8", "utf-16be")
21
57
  end
58
+ string.force_encoding(::Encoding::UTF_8)
59
+
60
+ text.replace string
22
61
  text
23
62
  end
24
63
 
@@ -26,16 +65,25 @@ module JavaProperties
26
65
  # @param text [String]
27
66
  # @return [String] The decoded text for chaining
28
67
  def self.encode!(text)
29
- buffer = StringIO.new
30
- text.each_char do |char|
31
- if char.ascii_only?
32
- buffer << char
33
- else
34
- buffer << UNICODE_ESCAPE
35
- buffer << hex(char.codepoints.first)
36
- end
37
- end
38
- text.replace buffer.string
68
+ string = text.dup
69
+ string.force_encoding(::Encoding::ASCII_8BIT)
70
+ string.gsub!(/["\\\x0-\x1f]/n) { |c| MAP[c] || c }
71
+ string.gsub!(/(
72
+ (?:
73
+ [\xc2-\xdf][\x80-\xbf] |
74
+ [\xe0-\xef][\x80-\xbf]{2} |
75
+ [\xf0-\xf4][\x80-\xbf]{3}
76
+ )+ |
77
+ [\x80-\xc1\xf5-\xff] # invalid
78
+ )/nx) { |c|
79
+ c.size == 1 and raise "Invalid utf8 byte: '#{c}'"
80
+ s = c.encode("utf-16be", "utf-8").unpack('H*')[0]
81
+ s.force_encoding(::Encoding::ASCII_8BIT)
82
+ s.gsub!(/.{4}/n, '\\\\u\&')
83
+ s.force_encoding(::Encoding::UTF_8)
84
+ }
85
+ string.force_encoding(::Encoding::UTF_8)
86
+ text.replace string
39
87
  text
40
88
  end
41
89
 
@@ -2,6 +2,6 @@ module JavaProperties
2
2
 
3
3
  # Current version
4
4
  # @return [String]
5
- VERSION = "0.1.1".freeze
5
+ VERSION = "0.2.0".freeze
6
6
 
7
7
  end
@@ -1,16 +1,16 @@
1
1
  # Comment 1
2
2
  ! Comment 2
3
3
  item0
4
- item1 = item1
5
- item2 : item2
4
+ item1 = item1
5
+ item2 : item2
6
6
  item3 item3
7
7
 
8
8
  #Comment 3
9
9
  ! Comment 4
10
-
10
+
11
11
  it\ em4=item4
12
- it\=em5:item5
13
- item6 item6
12
+ it\=em5:item5
13
+ item6 item6
14
14
 
15
15
  !Comment 4
16
16
  # Comment 5
@@ -31,3 +31,4 @@ item10=test\n\ttest\u0050 \
31
31
  test\n\ttest \
32
32
  test\n\ttest = test
33
33
 
34
+ item11=a\u00e4b \ud868\udc2f
@@ -8,4 +8,5 @@ item6=item6
8
8
  item7=line 1 line 2 line 3
9
9
  item8=line 1 line 2 line 3
10
10
  item9=line 1 line 2 line 3
11
- item10=test\n\ttest\u0050 test\n\ttest test\n\ttest = test
11
+ item10=test\n\ttest\u0050 test\n\ttest test\n\ttest = test
12
+ item11=a\u00e4b \ud868\udc2f
@@ -8,4 +8,5 @@ it\:em6=item6
8
8
  item7=line 1 line 2 line 3
9
9
  item8=line 1 line 2 line 3
10
10
  item9=line 1 line 2 line 3
11
- item10=test\n\ttest\u05d4 test\n\ttest test\n\ttest\u00fc = test
11
+ item10=test\n\ttest\u05d4 test\n\ttest test\n\ttest\u00fc = test
12
+ item11=a\u00e4b \ud868\udc2f
@@ -8,4 +8,5 @@ it:em6=item6
8
8
  item7=line 1 line 2 line 3
9
9
  item8=line 1 line 2 line 3
10
10
  item9=line 1 line 2 line 3
11
- item10=test\n\ttest\u05d4 test\n\ttest test\n\ttest\u00fc = test
11
+ item10=test\n\ttest\u05d4 test\n\ttest test\n\ttest\u00fc = test
12
+ item11=a\u00e4b \ud868\udc2f
@@ -11,4 +11,5 @@ item9=line 1 line 2 line 3
11
11
  item10=test
12
12
  test\u05d4 test
13
13
  test test
14
- test\u00fc = test
14
+ test\u00fc = test
15
+ item11=a\u00e4b \ud868\udc2f
@@ -8,4 +8,5 @@ it\:em6=item6
8
8
  item7=line 1 line 2 line 3
9
9
  item8=line 1 line 2 line 3
10
10
  item9=line 1 line 2 line 3
11
- item10=test\n\ttestה test\n\ttest test\n\ttestü = test
11
+ item10=test\n\ttestה test\n\ttest test\n\ttestü = test
12
+ item11=aäb 𪀯
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: java-properties
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
  - Jonas Thiel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-21 00:00:00.000000000 Z
11
+ date: 2016-09-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Tool for loading and writing Java properties files
14
14
  email:
@@ -50,17 +50,17 @@ require_paths:
50
50
  - lib
51
51
  required_ruby_version: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '>='
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: '2.0'
56
56
  required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - '>='
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: 1.3.5
61
61
  requirements: []
62
62
  rubyforge_project:
63
- rubygems_version: 2.4.6
63
+ rubygems_version: 2.5.1
64
64
  signing_key:
65
65
  specification_version: 4
66
66
  summary: Loader and writer for *.properties files