i
[chise/ruby.git] / chise / iconv.rb
index 5833f48..a55b6fa 100755 (executable)
@@ -82,9 +82,27 @@ class String
     s = self
     return (s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3])
   end
+
+  def u8to_i
+    u32 = self.u8tou32
+    u32.u32to_i
+  end
+end
+
+module CHISE
+  def i_tou32(n) # convert a integer to UTF-32 String
+    raise unless n.is_a?(Integer)
+    sprintf("%c%c%c%c", (n >> 24)&0xff, (n >> 16)&0xff, (n >> 8)&0xff, n&0xff)
+  end
+
+  def i_tou8(n) # convert a integer to UTF-8 String
+    u32 = CHISE.i_tou32(n)
+    u32.u32tou8
+  end
+  module_function :i_tou32, :i_tou8
 end
 
-class Uconv
+class NuUconv
   def self.u8tou4(s)   s.u8tou32;      end
   def self.u4tou8(s)   s.u32tou8;      end
   def self.u4tou16(s)  s.u32tou16;     end