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 +4 -4
- data/README.md +1 -0
- data/java-properties.gemspec +2 -1
- data/lib/java-properties/encoding/unicode.rb +67 -19
- data/lib/java-properties/version.rb +1 -1
- data/spec/fixtures/test.properties +6 -5
- data/spec/fixtures/test_normalized.properties +2 -1
- data/spec/fixtures/test_out.properties +2 -1
- data/spec/fixtures/test_out_skip_separators.properties +2 -1
- data/spec/fixtures/test_out_skip_special_chars.properties +2 -1
- data/spec/fixtures/test_out_skip_unicode.properties +2 -1
- metadata +6 -6
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d4f07c15c1f58cb3478fab7debf52316d9649cc3
         | 
| 4 | 
            +
              data.tar.gz: 7b340371a2ea3b0420fb2e0ee532e926fd8bc006
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: c9c763b44183f8e3175326d1d699af24386cdc6abe95b6de3df9fa5514ed6ade61470be36a84403e032238403ac8eca5bf1dd036d5fb59e4db5ed6b7b8581491
         | 
| 7 | 
            +
              data.tar.gz: 08865b814f74ab2fb98381843a0550b25b107a825ecc985813db0580c2f24d3aefab9f1914b50b787c05819d1a3c242bb595d5bb1e787e5d7d412b75cb487492
         | 
    
        data/README.md
    CHANGED
    
    
    
        data/java-properties.gemspec
    CHANGED
    
    
| @@ -1,24 +1,63 @@ | |
| 1 1 | 
             
            module JavaProperties
         | 
| 2 2 | 
             
              module Encoding
         | 
| 3 3 | 
             
                # Module to encode and decode unicode chars
         | 
| 4 | 
            -
                #  | 
| 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 | 
            -
                  #  | 
| 8 | 
            -
                   | 
| 9 | 
            -
             | 
| 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 | 
            -
                  #  | 
| 12 | 
            -
                   | 
| 13 | 
            -
                   | 
| 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. | 
| 20 | 
            -
             | 
| 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 | 
            -
                     | 
| 30 | 
            -
                     | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
                       | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 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 |  | 
| @@ -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
         | 
    
        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. | 
| 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:  | 
| 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. | 
| 63 | 
            +
            rubygems_version: 2.5.1
         | 
| 64 64 | 
             
            signing_key: 
         | 
| 65 65 | 
             
            specification_version: 4
         | 
| 66 66 | 
             
            summary: Loader and writer for *.properties files
         |