[前][次][番号順一覧][スレッド一覧]

ruby-changes:6929

From: akr <ko1@a...>
Date: Sat, 9 Aug 2008 01:09:14 +0900 (JST)
Subject: [ruby-changes:6929] Ruby:r18447 (trunk): * enc/trans/utf_16_32.erb.c (fun_so_from_utf_32le): implemented.

akr	2008-08-09 01:08:50 +0900 (Sat, 09 Aug 2008)

  New Revision: 18447

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18447

  Log:
    * enc/trans/utf_16_32.erb.c (fun_so_from_utf_32le): implemented.
      (fun_so_to_utf_32le): implemented.
      [ruby-dev:35777]

  Modified files:
    trunk/ChangeLog
    trunk/enc/trans/utf_16_32.erb.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18446)
+++ ChangeLog	(revision 18447)
@@ -1,3 +1,9 @@
+Sat Aug  9 01:07:51 2008  Tanaka Akira  <akr@f...>
+
+	* enc/trans/utf_16_32.erb.c (fun_so_from_utf_32le): implemented.
+	  (fun_so_to_utf_32le): implemented.
+	  [ruby-dev:35777]
+
 Sat Aug  9 00:42:33 2008  Tanaka Akira  <akr@f...>
 
 	* transcode_data.h (rb_transcoder): from_unit_length field added.
Index: enc/trans/utf_16_32.erb.c
===================================================================
--- enc/trans/utf_16_32.erb.c	(revision 18446)
+++ enc/trans/utf_16_32.erb.c	(revision 18447)
@@ -170,12 +170,55 @@
 static int
 fun_so_from_utf_32le(rb_transcoding* t, const unsigned char* s, size_t l, unsigned char* o)
 {
-    return 1;
+    if (!s[2]) {
+        if (s[1]==0 && s[0]<0x80) {
+            o[0] = s[0];
+            return 1;
+        }
+        else if (s[1]<0x08) {
+            o[0] = 0xC0 | (s[1]<<2) | (s[0]>>6);
+            o[1] = 0x80 | (s[0]&0x3F);
+            return 2;
+        }
+        else {
+            o[0] = 0xE0 | (s[1]>>4);
+            o[1] = 0x80 | ((s[1]&0x0F)<<2) | (s[0]>>6);
+            o[2] = 0x80 | (s[0]&0x3F);
+            return 3;
+        }
+    }
+    else {
+        o[0] = 0xF0 | (s[2]>>2);
+        o[1] = 0x80 | ((s[2]&0x03)<<4) | (s[1]>>4);
+        o[2] = 0x80 | ((s[1]&0x0F)<<2) | (s[0]>>6);
+        o[3] = 0x80 | (s[0]&0x3F);
+        return 4;
+    }
 }
 
 static int
 fun_so_to_utf_32le(rb_transcoding* t, const unsigned char* s, size_t l, unsigned char* o)
 {
+    o[3] = 0;
+    if (!(s[0]&0x80)) {
+        o[2] = o[1] = 0x00;
+        o[0] = s[0];
+    }
+    else if ((s[0]&0xE0)==0xC0) {
+        o[2] = 0x00;
+        o[1] = (s[0]>>2)&0x07;
+        o[0] = ((s[0]&0x03)<<6) | (s[1]&0x3F);
+    }
+    else if ((s[0]&0xF0)==0xE0) {
+        o[2] = 0x00;
+        o[1] = (s[0]<<4) | ((s[1]>>2)^0x20);
+        o[0] = (s[1]<<6) | (s[2]^0x80);
+    }
+    else {
+        o[2] = ((s[0]&0x07)<<2) | ((s[1]>>4)&0x03);
+        o[1] = ((s[1]&0x0F)<<4) | ((s[2]>>2)&0x0F);
+        o[0] = ((s[2]&0x03)<<6) | (s[3]&0x3F);
+    }
     return 4;
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]