module JavaProperties::Encoding::SpecialChars
Module to escape and unescape special chars @see JavaProperties::Encoding
Constants
- DESCAPING
Lookup table to remove escaping from special chars @return [Hash]
- DESCAPING_MARKER
Marks a segment which has is an encoding special char @return [Regexp]
- ESCAPING
Lookup table for escaping special chars @return [Hash]
Public Class Methods
decode!(text)
click to toggle source
Decodes the content a text by removing all escaping from special chars @param text [String] @return [String] The unescaped text for chaining
# File lib/java-properties/encoding/special_chars.rb, line 39 def self.decode!(text) text.gsub!(DESCAPING_MARKER) do |match| DESCAPING.fetch(match, match) end text end
encode!(text)
click to toggle source
Encodes the content a text by escaping all special chars @param text [String] @return [String] The escaped text for chaining
# File lib/java-properties/encoding/special_chars.rb, line 27 def self.encode!(text) buffer = StringIO.new text.each_char do |char| buffer << ESCAPING.fetch(char, char) end text.replace buffer.string text end