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 +4 -4
- data/README.md +6 -4
- data/lib/java-properties/encoding.rb +16 -4
- data/lib/java-properties/encoding/separators.rb +3 -2
- data/lib/java-properties/encoding/special_chars.rb +3 -2
- data/lib/java-properties/encoding/unicode.rb +9 -12
- data/lib/java-properties/version.rb +1 -1
- data/spec/fixtures/test_out.properties +1 -1
- data/spec/fixtures/test_out_skip_separators.properties +1 -1
- data/spec/fixtures/test_out_skip_special_chars.properties +1 -1
- data/spec/fixtures/test_out_skip_unicode.properties +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86611b4fa72e76a45066b1099e0a4cb3df53070e
|
4
|
+
data.tar.gz: a5fea3d3c9eb62171d5e5d9118b979ca853877b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 050d08596eb08ca78e63896ed794dfedf4373301759a930b6bf2c2ee7d1005f934d0ee4f60a4a61d00776788fd15b59f35510f03f078b15c36022ac21771a255
|
7
|
+
data.tar.gz: a975fd4dcdc300092de91b0d7f0425d48dec1ab2b7e5802498b166e81dff49f3ce77e1594b00e12fa1f46d25b16387274fd6b674661553c79e4e7e31f46950f8
|
data/README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# JavaProperties
|
2
2
|
|
3
|
-
[](https://travis-ci.org/jnbt/java-properties)
|
4
|
+
[](https://codeclimate.com/github/jnbt/java-properties)
|
5
|
+
[](https://coveralls.io/r/jnbt/java-properties)
|
6
|
+
[](http://rubygems.org/gems/java-properties)
|
7
|
+
[](https://gemnasium.com/jnbt/java-properties)
|
8
|
+
[](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 [
|
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 [
|
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
|
-
|
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
|
-
|
51
|
-
|
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
|
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
|
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:
|
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.
|
62
|
+
rubygems_version: 2.4.6
|
63
63
|
signing_key:
|
64
64
|
specification_version: 4
|
65
65
|
summary: Loader and writer for *.properties files
|