Line | |
---|
1 | module REXML
|
---|
2 | module Encoding
|
---|
3 | # Convert from UTF-8
|
---|
4 | def encode_ascii content
|
---|
5 | array_utf8 = content.unpack('U*')
|
---|
6 | array_enc = []
|
---|
7 | array_utf8.each do |num|
|
---|
8 | if num <= 0x7F
|
---|
9 | array_enc << num
|
---|
10 | else
|
---|
11 | # Numeric entity (&#nnnn;); shard by Stefan Scholl
|
---|
12 | array_enc.concat "&\##{num};".unpack('C*')
|
---|
13 | end
|
---|
14 | end
|
---|
15 | array_enc.pack('C*')
|
---|
16 | end
|
---|
17 |
|
---|
18 | # Convert to UTF-8
|
---|
19 | def decode_ascii(str)
|
---|
20 | str.unpack('C*').pack('U*')
|
---|
21 | end
|
---|
22 |
|
---|
23 | register("US-ASCII") do |obj|
|
---|
24 | class << obj
|
---|
25 | alias decode decode_ascii
|
---|
26 | alias encode encode_ascii
|
---|
27 | end
|
---|
28 | end
|
---|
29 | end
|
---|
30 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.