Module: JavaProperties::Encoding

Defined in:
lib/java_properties/encoding.rb,
lib/java_properties/utf8.rb,
lib/java_properties/delimiters.rb,
lib/java_properties/specialchars.rb

Overview

Classes for encoding and decoding strings for Java properties files.

Defined Under Namespace

Modules: Delimiters, SpecialChars, Utf8

Class Method Summary collapse

Class Method Details

.decode(string) ⇒ Object

Decodes a string by unescaping UTF-8 and special characters



29
30
31
32
33
34
35
# File 'lib/java_properties/encoding.rb', line 29

def self.decode string
  # Replace \uXXXX escaped chars with proper UTF-8 bytes
  string = Utf8.decode(string)
  
  # Replace \n escaped chars with proper characters
  string = SpecialChars.decode(string)
end

.encode(string) ⇒ Object

Encodes a string by escaping special characters (n, t, etc.), delimiters ( =, :) and UTF-8 characters.



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

def self.encode string
  # Replace special chars with proper \n escaped characters
  string = SpecialChars.encode(string)
  
  # Replace unescaped delimiters with proper \n escaped characters
  string = Delimiters.encode(string)
  
  # Replace UTF-8 bytes with \uXXXX encoding
  string = Utf8.encode(string)
  
  string
end