module ProperProperties::Encoding::Separators
Module to escape separators as : or = @see ProperProperties::Encoding
Constants
- DECODE_SEPARATOR_MARKER
Marker for all escaped separators @return [Regexp]
- ENCODE_SEPARATOR_MARKER
Marker for all separators @return [Regexp]
- ESCAPE
Char to use for escaping @return [String]
- ESCAPING_MARKER
Marker for already escaped separators @return [Regexp]
Public Class Methods
decode!(text)
click to toggle source
Removes escapes from escaped separators @param text [text] @return [String] The unescaped text for chaining
# File lib/proper_properties/encoding/separators.rb, line 43 def self.decode!(text) text.gsub!(DECODE_SEPARATOR_MARKER) do $1 end text end
encode!(text)
click to toggle source
Escapes all not already escaped separators @param text [text] @return [String] The escaped text for chaining
# File lib/proper_properties/encoding/separators.rb, line 26 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