2003-06-09 21:31:01 -04:00
|
|
|
module REXML
|
2003-12-08 21:41:33 -05:00
|
|
|
module Encoding
|
2004-02-13 17:40:14 -05:00
|
|
|
@@__REXML_encoding_methods = %q~
|
2003-12-08 21:41:33 -05:00
|
|
|
# Convert from UTF-8
|
|
|
|
def encode content
|
|
|
|
array_utf8 = content.unpack('U*')
|
|
|
|
array_enc = []
|
|
|
|
array_utf8.each do |num|
|
|
|
|
if num <= 0xFF
|
|
|
|
array_enc << num
|
|
|
|
else
|
|
|
|
# Numeric entity (&#nnnn;); shard by Stefan Scholl
|
|
|
|
array_enc.concat "&\##{num};".unpack('C*')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
array_enc.pack('C*')
|
|
|
|
end
|
2003-06-09 21:31:01 -04:00
|
|
|
|
2003-12-08 21:41:33 -05:00
|
|
|
# Convert to UTF-8
|
|
|
|
def decode(str)
|
2003-12-23 05:07:45 -05:00
|
|
|
str.unpack('C*').pack('U*')
|
2003-12-08 21:41:33 -05:00
|
|
|
end
|
2004-02-13 17:40:14 -05:00
|
|
|
~
|
2003-12-08 21:41:33 -05:00
|
|
|
end
|
2003-06-09 21:31:01 -04:00
|
|
|
end
|