Module: JavaProperties::Encoding::Delimiters

Defined in:
lib/java_properties/delimiters.rb

Overview

Modules for encoding and decoding delimiters characters for Java properties files when those delimiters are found in the property keys.

Class Method Summary collapse

Class Method Details

.decode(string) ⇒ Object

No decoding is necessary, but this method has been provided for consistency with other encoding modules.



34
35
36
# File 'lib/java_properties/delimiters.rb', line 34

def self.decode string
  string
end

.encode(string) ⇒ Object

Encodes any delimiter characters found in the property keys by prepending a \



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/java_properties/delimiters.rb', line 14

def self.encode string
  s = ''
  prev = ''
  chars = string.split( // )
  while(chars.size > 0) do
    char = chars.shift
    if char =~ /[ :=]/ && prev !~ /\\/ then
      s << "\\" << char
    else
      s << char
    end
    prev = char
  end
  s
end