Module: JavaProperties::Encoding::Separators
- Defined in:
- lib/java-properties/encoding/separators.rb
Overview
Module to escape separators as : or =
Constant Summary collapse
- ENCODE_SEPARATOR_MARKER =
Marker for all separators
/[ :=]/
- ESCAPING_MARKER =
Marker for already escaped separators
/\\/
- ESCAPE =
Char to use for escaping
"\\"
- DECODE_SEPARATOR_MARKER =
Marker for all escaped separators
/\\([ :=])/
Class Method Summary collapse
-
.decode!(text) ⇒ String
Removes escapes from escaped separators.
-
.encode!(text) ⇒ String
Escapes all not already escaped separators.
Class Method Details
.decode!(text) ⇒ String
Removes escapes from escaped separators
42 43 44 45 46 47 |
# File 'lib/java-properties/encoding/separators.rb', line 42 def self.decode!(text) text.gsub!(DECODE_SEPARATOR_MARKER) do $1 end text end |
.encode!(text) ⇒ String
Escapes all not already escaped separators
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/java-properties/encoding/separators.rb', line 25 def self.encode!(text) buffer = StringIO.new last_token = '' text.each_char do |char| if char =~ ENCODE_SEPARATOR_MARKER && last_token !~ ESCAPING_MARKER buffer << ESCAPE end buffer << char last_token = char end text.replace buffer.string text end |