Module: JavaProperties::Encoding::Unicode
- Defined in:
- lib/java-properties/encoding/unicode.rb
Overview
Module to encode and decode unicode chars
Constant Summary collapse
- UNICODE_MARKER =
Marker for encoded unicode chars
/\\[uU]([0-9a-fA-F]{4,5}|10[0-9a-fA-F]{4})/
- UNICODE_ESCAPE =
Escape char for unicode chars
"\\u"
Class Method Summary collapse
-
.decode!(text) ⇒ String
Decodes all unicode chars from escape sequences in place.
-
.encode!(text) ⇒ String
Decodes all unicode chars into escape sequences in place.
Class Method Details
.decode!(text) ⇒ String
Decodes all unicode chars from escape sequences in place
17 18 19 20 21 22 |
# File 'lib/java-properties/encoding/unicode.rb', line 17 def self.decode!(text) text.gsub!(UNICODE_MARKER) do unicode($1.hex) end text end |
.encode!(text) ⇒ String
Decodes all unicode chars into escape sequences in place
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/java-properties/encoding/unicode.rb', line 27 def self.encode!(text) buffer = StringIO.new text.each_char do |char| if char.ascii_only? buffer << char else buffer << UNICODE_ESCAPE buffer << hex(char.codepoints.first) end end text.replace buffer.string text end |