Line | |
---|
1 | module REXML
|
---|
2 | module Encoding
|
---|
3 | def encode_unile content
|
---|
4 | array_utf8 = content.unpack("U*")
|
---|
5 | array_enc = []
|
---|
6 | array_utf8.each do |num|
|
---|
7 | if ((num>>16) > 0)
|
---|
8 | array_enc << ??
|
---|
9 | array_enc << 0
|
---|
10 | else
|
---|
11 | array_enc << (num & 0xFF)
|
---|
12 | array_enc << (num >> 8)
|
---|
13 | end
|
---|
14 | end
|
---|
15 | array_enc.pack('C*')
|
---|
16 | end
|
---|
17 |
|
---|
18 | def decode_unile(str)
|
---|
19 | array_enc=str.unpack('C*')
|
---|
20 | array_utf8 = []
|
---|
21 | 0.step(array_enc.size-1, 2){|i|
|
---|
22 | array_utf8 << (array_enc.at(i) + array_enc.at(i+1)*0x100)
|
---|
23 | }
|
---|
24 | array_utf8.pack('U*')
|
---|
25 | end
|
---|
26 |
|
---|
27 | register(UNILE) do |obj|
|
---|
28 | class << obj
|
---|
29 | alias decode decode_unile
|
---|
30 | alias encode encode_unile
|
---|
31 | end
|
---|
32 | end
|
---|
33 | end
|
---|
34 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.