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

ruby-changes:7693

From: akr <ko1@a...>
Date: Sun, 7 Sep 2008 18:13:31 +0900 (JST)
Subject: [ruby-changes:7693] Ruby:r19214 (trunk): * transcode_data.h (STR1): defined for a string up to 255 bytes.

akr	2008-09-07 18:13:16 +0900 (Sun, 07 Sep 2008)

  New Revision: 19214

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

  Log:
    * transcode_data.h (STR1): defined for a string up to 255 bytes.
      (STR1_BYTEINDEX): defined.
      (makeSTR1): defined.
    
    * tool/transcode-tblgen.rb: generate STR1.
    
    * transcode.c (transcode_restartable0): interpret STR1.
    
    * enc/trans/escape.trans (fun_so_escape_xml_chref): removed.  STR1 is
      used instead.

  Modified files:
    trunk/ChangeLog
    trunk/enc/trans/escape.trans
    trunk/tool/transcode-tblgen.rb
    trunk/transcode.c
    trunk/transcode_data.h

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19213)
+++ ChangeLog	(revision 19214)
@@ -1,3 +1,16 @@
+Sun Sep  7 18:10:28 2008  Tanaka Akira  <akr@f...>
+
+	* transcode_data.h (STR1): defined for a string up to 255 bytes.
+	  (STR1_BYTEINDEX): defined.
+	  (makeSTR1): defined.
+
+	* tool/transcode-tblgen.rb: generate STR1.
+
+	* transcode.c (transcode_restartable0): interpret STR1.
+
+	* enc/trans/escape.trans (fun_so_escape_xml_chref): removed.  STR1 is
+	  used instead.
+
 Sun Sep  7 17:54:45 2008  Kazuhiro NISHIYAMA  <zn@m...>
 
 	* configure.in: Mac OS X's crypt(2) is broken with invalid salt.
Index: enc/trans/escape.trans
===================================================================
--- enc/trans/escape.trans	(revision 19213)
+++ enc/trans/escape.trans	(revision 19214)
@@ -1,69 +1,33 @@
 #include "transcode_data.h"
 
-static int
-fun_so_escape_xml_chref(void *statep, const unsigned char *s, size_t l, unsigned char *o)
-{
-    switch (*s) {
-      case '&':
-        o[0] = '&';
-        o[1] = 'a';
-        o[2] = 'm';
-        o[3] = 'p';
-        o[4] = ';';
-        return 5;
-
-      case '<':
-        o[0] = '&';
-        o[1] = 'l';
-        o[2] = 't';
-        o[3] = ';';
-        return 4;
-
-      case '>':
-        o[0] = '&';
-        o[1] = 'g';
-        o[2] = 't';
-        o[3] = ';';
-        return 4;
-
-      case '"':
-        o[0] = '&';
-        o[1] = 'q';
-        o[2] = 'u';
-        o[3] = 'o';
-        o[4] = 't';
-        o[5] = ';';
-        return 6;
-
-      default:
-        rb_bug("unexpected char");
-    }
-} 
 <%
+  def str1(str)
+    str.unpack("H*")[0]
+  end
+
   map_amp = {}
   map_amp["{00-25,27-FF}"] = :nomap
-  map_amp["26"] = :func_so
+  map_amp["26"] = str1("&amp;")
   transcode_generate_node(ActionMap.parse(map_amp), "escape_amp_as_chref")
 
   map_xml_text = {}
   map_xml_text["{00-25,27-3B,3D,3F-FF}"] = :nomap
-  map_xml_text["26"] = :func_so
-  map_xml_text["3C"] = :func_so
-  map_xml_text["3E"] = :func_so
+  map_xml_text["26"] = str1("&amp;")
+  map_xml_text["3C"] = str1("&lt;")
+  map_xml_text["3E"] = str1("&gt;")
   transcode_generate_node(ActionMap.parse(map_xml_text), "escape_xml_text")
 
   map_xml_attr_content = {}
   map_xml_attr_content["{00-21,23-25,27-3B,3D,3F-FF}"] = :nomap
-  map_xml_attr_content["22"] = :func_so
-  map_xml_attr_content["26"] = :func_so
-  map_xml_attr_content["3C"] = :func_so
-  map_xml_attr_content["3E"] = :func_so
+  map_xml_attr_content["22"] = str1("&quot;")
+  map_xml_attr_content["26"] = str1("&amp;")
+  map_xml_attr_content["3C"] = str1("&lt;")
+  map_xml_attr_content["3E"] = str1("&gt;")
   transcode_generate_node(ActionMap.parse(map_xml_attr_content), "escape_xml_attr_content")
 
   map_xml_attr_quote = {}
   map_xml_attr_quote["{00-FF}"] = :func_so
   transcode_generate_node(ActionMap.parse(map_xml_attr_quote), "escape_xml_attr_quote")
-
 %>
 
 <%= transcode_generated_code %>
@@ -77,7 +41,7 @@
     5, /* max_output */
     stateless_converter, /* stateful_type */
     0, NULL, NULL,
-    NULL, NULL, NULL, &fun_so_escape_xml_chref
+    NULL, NULL, NULL, NULL
 };
 
 static const rb_transcoder
@@ -89,7 +53,7 @@
     5, /* max_output */
     stateless_converter, /* stateful_type */
     0, NULL, NULL,
-    NULL, NULL, NULL, &fun_so_escape_xml_chref
+    NULL, NULL, NULL, NULL
 };
 
 static const rb_transcoder
@@ -101,7 +65,7 @@
     6, /* max_output */
     stateless_converter, /* stateful_type */
     0, NULL, NULL,
-    NULL, NULL, NULL, &fun_so_escape_xml_chref
+    NULL, NULL, NULL, NULL
 };
 
 #define END 0
Index: transcode_data.h
===================================================================
--- transcode_data.h	(revision 19213)
+++ transcode_data.h	(revision 19214)
@@ -34,7 +34,11 @@
 #define FUNsi	(PType 0x0D)	/* function from start to info */
 #define FUNio	(PType 0x0E)	/* function from info to output */
 #define FUNso	(PType 0x0F)	/* function from start to output */
+#define STR1	(PType 0x11)	/* string up to 255 bytes: 1byte length + content */
 
+#define STR1_BYTEINDEX(w) ((w) >> 6)
+#define makeSTR1(bi) (((bi) << 6) | STR1)
+
 #define o1(b1)		(PType((((unsigned char)(b1))<<8)|ONEbt))
 #define o2(b1,b2)	(PType((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|TWObt))
 #define o3(b1,b2,b3)	(PType(((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|(((unsigned char)(b3))<<24)|THREEbt)&0xffffffffU))
Index: tool/transcode-tblgen.rb
===================================================================
--- tool/transcode-tblgen.rb	(revision 19213)
+++ tool/transcode-tblgen.rb	(revision 19214)
@@ -301,6 +301,14 @@
       "o3(0x#$1,0x#$2,0x#$3)"
     when /\A(f[0-7])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])\z/i
       "o4(0x#$1,0x#$2,0x#$3,0x#$4)"
+    when /\A([0-9a-f][0-9a-f]){0,255}\z/i
+      bytes = info
+      len = info.length/2
+      size = @bytes_code.length
+      @bytes_code.insert_at_last(1 + len,
+        "\#define str1_#{size} makeSTR1(#{size})\n" +
+        "    #{len}," + info.gsub(/../, ' 0x\&,') + "\n")
+      "str1_#{size}"
     when /\A\/\*BYTE_LOOKUP\*\// # pointer to BYTE_LOOKUP structure
       $'.to_s
     else
@@ -414,7 +422,11 @@
   end
 
   def gennode(bytes_code, words_code, name_hint=nil, valid_encoding=nil)
+    @bytes_code = bytes_code
+    @words_code = words_code
     name = generate_node(bytes_code, words_code, name_hint, valid_encoding)
+    @bytes_code = nil
+    @words_code = nil
     return name
   end
 end
Index: transcode.c
===================================================================
--- transcode.c	(revision 19213)
+++ transcode.c	(revision 19214)
@@ -534,6 +534,7 @@
       case 25: goto resume_label25;
       case 26: goto resume_label26;
       case 27: goto resume_label27;
+      case 28: goto resume_label28;
     }
 
     while (1) {
@@ -602,6 +603,13 @@
             SUSPEND_OBUF(18); *out_p++ = getBT2(next_info);
             SUSPEND_OBUF(19); *out_p++ = getBT3(next_info);
 	    continue;
+          case STR1:
+            next_byte = 0; /* index */
+            while (next_byte < BYTE_ADDR(STR1_BYTEINDEX(next_info))[0]) {
+                SUSPEND_OBUF(28); *out_p++ = BYTE_ADDR(STR1_BYTEINDEX(next_info))[1+next_byte];
+                next_byte++;
+            }
+            continue;
 	  case FUNii:
 	    next_info = (VALUE)(*tr->func_ii)(TRANSCODING_STATE(tc), next_info);
 	    goto follow_info;

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

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