java-properties 0.0.2 → 0.1.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: fa01303d1449ae0f74ddd1a56b9da076f232335e
4
- data.tar.gz: 9704efbe011c991ddede20ea11cc5d63da9897d1
3
+ metadata.gz: 86611b4fa72e76a45066b1099e0a4cb3df53070e
4
+ data.tar.gz: a5fea3d3c9eb62171d5e5d9118b979ca853877b6
5
5
  SHA512:
6
- metadata.gz: c4df80543ad68a53c37dd7cc6aea82b256591c11813e30737a2a65ee340ec1c4eb877436f265466f47f93b1ac68c46a0c7b9fa77529cc061cb4965b5ce38f960
7
- data.tar.gz: ea06f6daad8d178218f6bb227f080263c3b7341b1c2d128993b8b9b5734e00f2e9eee85b87a51f240dbd2f4aa35780f6c2e8add55d004fb1affb5c8e40e4a54a
6
+ metadata.gz: 050d08596eb08ca78e63896ed794dfedf4373301759a930b6bf2c2ee7d1005f934d0ee4f60a4a61d00776788fd15b59f35510f03f078b15c36022ac21771a255
7
+ data.tar.gz: a975fd4dcdc300092de91b0d7f0425d48dec1ab2b7e5802498b166e81dff49f3ce77e1594b00e12fa1f46d25b16387274fd6b674661553c79e4e7e31f46950f8
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # JavaProperties
2
2
 
3
- [![Build Status](http://img.shields.io/travis/jnbt/java-properties.png)](https://travis-ci.org/jnbt/jnbt/java-properties)
4
- [![Code Climate](http://img.shields.io/codeclimate/github/jnbt/java-properties.png)](https://codeclimate.com/github/jnbt/java-properties)
5
- [![Coveralls](http://img.shields.io/coveralls/jnbt/java-properties.png)](https://coveralls.io/r/jnbt/java-properties)
6
- [![RubyGems](http://img.shields.io/gem/v/java-properties.png)](http://rubygems.org/gems/java-properties)
3
+ [![Build Status](http://img.shields.io/travis/jnbt/java-properties.svg)](https://travis-ci.org/jnbt/java-properties)
4
+ [![Code Climate](http://img.shields.io/codeclimate/github/jnbt/java-properties.svg)](https://codeclimate.com/github/jnbt/java-properties)
5
+ [![Coveralls](http://img.shields.io/coveralls/jnbt/java-properties.svg)](https://coveralls.io/r/jnbt/java-properties)
6
+ [![RubyGems](http://img.shields.io/gem/v/java-properties.svg)](http://rubygems.org/gems/java-properties)
7
+ [![Gemnasium](http://img.shields.io/gemnasium/jnbt/java-properties.svg)](https://gemnasium.com/jnbt/java-properties)
8
+ [![Inline docs](http://inch-ci.org/github/jnbt/java-properties.svg?style=shields)](http://inch-ci.org/github/jnbt/java-properties)
7
9
 
8
10
  A ruby library to read and write [Java properties files](http://en.wikipedia.org/wiki/.properties).
9
11
 
@@ -4,6 +4,18 @@ require 'java-properties/encoding/unicode'
4
4
 
5
5
  module JavaProperties
6
6
  # Module to encode and decode
7
+ #
8
+ # Usage:
9
+ # encoded = Encoding.encode!("Some text to be encoded")
10
+ # decoded = Encoding.decode!("Some text to be decoded")
11
+ #
12
+ # You can disable separate encoding (and decoding) steps,
13
+ # by passing in additional flags:
14
+ #
15
+ # * SKIP_SEPARATORS: Do not code the separators (space,:,=)
16
+ # * SKIP_UNICODE: Do not code unicode chars
17
+ # * SKIP_SPECIAL_CHARS: Do not code newlines, tab stops, ...
18
+ #
7
19
  module Encoding
8
20
 
9
21
  # Flag for skipping separators encodings / decoding
@@ -20,8 +32,8 @@ module JavaProperties
20
32
 
21
33
  # Encode a given text in place
22
34
  # @param text [String]
23
- # @param flags [Symbol] Optional flags to skip encoding steps
24
- # @return [String]
35
+ # @param *flags [Array] Optional flags to skip encoding steps
36
+ # @return [String] The encoded text for chaining
25
37
  def self.encode!(text, *flags)
26
38
  SpecialChars.encode!(text) unless flags.include?(SKIP_SPECIAL_CHARS)
27
39
  Separators.encode!(text) unless flags.include?(SKIP_SEPARATORS)
@@ -31,8 +43,8 @@ module JavaProperties
31
43
 
32
44
  # Decodes a given text in place
33
45
  # @param text [String]
34
- # @param flags [Symbol] Optional flags to skip decoding steps
35
- # @return [String]
46
+ # @param *flags [Array] Optional flags to skip decoding steps
47
+ # @return [String] The decoded text for chaining
36
48
  def self.decode!(text, *flags)
37
49
  Unicode.decode!(text) unless flags.include?(SKIP_UNICODE)
38
50
  Separators.decode!(text) unless flags.include?(SKIP_SEPARATORS)
@@ -1,6 +1,7 @@
1
1
  module JavaProperties
2
2
  module Encoding
3
3
  # Module to escape separators as : or =
4
+ # @see JavaProperties::Encoding
4
5
  module Separators
5
6
 
6
7
  # Marker for all separators
@@ -21,7 +22,7 @@ module JavaProperties
21
22
 
22
23
  # Escapes all not already escaped separators
23
24
  # @param text [text]
24
- # @return [String]
25
+ # @return [String] The escaped text for chaining
25
26
  def self.encode!(text)
26
27
  buffer = StringIO.new
27
28
  last_token = ''
@@ -38,7 +39,7 @@ module JavaProperties
38
39
 
39
40
  # Removes escapes from escaped separators
40
41
  # @param text [text]
41
- # @return [String]
42
+ # @return [String] The unescaped text for chaining
42
43
  def self.decode!(text)
43
44
  text.gsub!(DECODE_SEPARATOR_MARKER) do
44
45
  $1
@@ -1,6 +1,7 @@
1
1
  module JavaProperties
2
2
  module Encoding
3
3
  # Module to escape and unescape special chars
4
+ # @see JavaProperties::Encoding
4
5
  module SpecialChars
5
6
 
6
7
  # Lookup table for escaping special chars
@@ -22,7 +23,7 @@ module JavaProperties
22
23
 
23
24
  # Encodes the content a text by escaping all special chars
24
25
  # @param text [String]
25
- # @return [String]
26
+ # @return [String] The escaped text for chaining
26
27
  def self.encode!(text)
27
28
  buffer = StringIO.new
28
29
  text.each_char do |char|
@@ -34,7 +35,7 @@ module JavaProperties
34
35
 
35
36
  # Decodes the content a text by removing all escaping from special chars
36
37
  # @param text [String]
37
- # @return [String]
38
+ # @return [String] The unescaped text for chaining
38
39
  def self.decode!(text)
39
40
  text.gsub!(DESCAPING_MARKER) do |match|
40
41
  DESCAPING.fetch(match, match)
@@ -1,8 +1,9 @@
1
1
  module JavaProperties
2
2
  module Encoding
3
3
  # Module to encode and decode unicode chars
4
+ # @see JavaProperties::Encoding
4
5
  module Unicode
5
-
6
+
6
7
  # Marker for encoded unicode chars
7
8
  # @return [Regexp]
8
9
  UNICODE_MARKER = /\\[uU]([0-9a-fA-F]{4,5}|10[0-9a-fA-F]{4})/
@@ -13,7 +14,7 @@ module JavaProperties
13
14
 
14
15
  # Decodes all unicode chars from escape sequences in place
15
16
  # @param text [String]
16
- # @return [String]
17
+ # @return [String] The encoded text for chaining
17
18
  def self.decode!(text)
18
19
  text.gsub!(UNICODE_MARKER) do
19
20
  unicode($1.hex)
@@ -23,7 +24,7 @@ module JavaProperties
23
24
 
24
25
  # Decodes all unicode chars into escape sequences in place
25
26
  # @param text [String]
26
- # @return [String]
27
+ # @return [String] The decoded text for chaining
27
28
  def self.encode!(text)
28
29
  buffer = StringIO.new
29
30
  text.each_char do |char|
@@ -41,20 +42,16 @@ module JavaProperties
41
42
  private
42
43
 
43
44
  def self.unicode(code)
44
- [code].pack("U")
45
+ code.chr(::Encoding::UTF_8)
45
46
  end
46
47
 
47
48
  def self.hex(codepoint)
48
49
  hex = codepoint.to_s(16)
49
- size = hex.size
50
- # padding the hex value for uneven digest
51
- if (size % 2) == 1
52
- "0#{hex}"
53
- else
54
- hex
55
- end
50
+ size = [4, hex.size].max
51
+ target_size = size.even? ? size : size+1
52
+ hex.rjust(target_size, '0')
56
53
  end
57
54
 
58
55
  end
59
56
  end
60
- end
57
+ end
@@ -2,6 +2,6 @@ module JavaProperties
2
2
 
3
3
  # Current version
4
4
  # @return [String]
5
- VERSION = "0.0.2".freeze
5
+ VERSION = "0.1.0".freeze
6
6
 
7
7
  end
@@ -8,4 +8,4 @@ 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 = test
11
+ item10=test\n\ttest\u05d4 test\n\ttest test\n\ttest\u00fc = test
@@ -8,4 +8,4 @@ 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 = test
11
+ item10=test\n\ttest\u05d4 test\n\ttest test\n\ttest\u00fc = test
@@ -11,4 +11,4 @@ item9=line 1 line 2 line 3
11
11
  item10=test
12
12
  test\u05d4 test
13
13
  test test
14
- test = test
14
+ test\u00fc = test
@@ -8,4 +8,4 @@ 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
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.0.2
4
+ version: 0.1.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: 2014-02-17 00:00:00.000000000 Z
11
+ date: 2015-10-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Tool for loading and writing Java properties files
14
14
  email:
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  version: 1.3.5
60
60
  requirements: []
61
61
  rubyforge_project:
62
- rubygems_version: 2.2.1
62
+ rubygems_version: 2.4.6
63
63
  signing_key:
64
64
  specification_version: 4
65
65
  summary: Loader and writer for *.properties files