source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/rexml/encodings/UTF-16.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

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