Module: Nicos::Unicode
- Defined in:
- lib/classes/converter.rb
Constant Summary collapse
- UNESCAPE_WORKER_ARRAY =
[]
Class Method Summary collapse
Class Method Details
.escape(str) ⇒ Object
58 59 60 61 |
# File 'lib/classes/converter.rb', line 58 def escape(str) ary = str.unpack("U*").map!{|i| "\\u#{i.to_s(16)}"} ary.join end |
.unescape(str) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/classes/converter.rb', line 64 def unescape(str) str.gsub(/\\u([0-9a-f]{4})/) { UNESCAPE_WORKER_ARRAY[0] = $1.hex UNESCAPE_WORKER_ARRAY.pack("U") } end |