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

ruby-changes:2786

From: ko1@a...
Date: 18 Dec 2007 01:21:36 +0900
Subject: [ruby-changes:2786] nobu - Ruby:r14277 (trunk): * parse.y (parser_encode_length): chomp eol style modifiers.

nobu	2007-12-18 01:21:21 +0900 (Tue, 18 Dec 2007)

  New Revision: 14277

  Modified files:
    trunk/ChangeLog
    trunk/parse.y

  Log:
    * parse.y (parser_encode_length): chomp eol style modifiers.
    
    * parse.y (parser_magic_comment): ditto.
    
    * parse.y (set_file_encoding): ditto.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/parse.y?r1=14277&r2=14276
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14277&r2=14276

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14276)
+++ ChangeLog	(revision 14277)
@@ -1,3 +1,11 @@
+Tue Dec 18 01:21:19 2007  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (parser_encode_length): chomp eol style modifiers.
+
+	* parse.y (parser_magic_comment): ditto.
+
+	* parse.y (set_file_encoding): ditto.
+
 Tue Dec 18 01:15:44 2007  Nobuyoshi Nakada  <nobu@r...>
 
 	* common.mk (encs): added dependencies.
Index: parse.y
===================================================================
--- parse.y	(revision 14276)
+++ parse.y	(revision 14277)
@@ -5704,6 +5704,24 @@
 }
 
 /* emacsen -*- hack */
+static int
+parser_encode_length(struct parser_params *parser, const char *name, int len)
+{
+    int nlen;
+
+    if (len > 5 && name[nlen = len - 5] == '-') {
+	if (rb_memcicmp(name + nlen + 1, "unix", 4) == 0)
+	    return nlen;
+    }
+    if (len > 4 && name[nlen = len - 5] == '-') {
+	if (rb_memcicmp(name + nlen + 1, "dos", 3) == 0)
+	    return nlen;
+	if (rb_memcicmp(name + nlen + 1, "mac", 3) == 0)
+	    return nlen;
+    }
+    return len;
+}
+
 static void
 parser_set_encode(struct parser_params *parser, const char *name)
 {
@@ -5715,6 +5733,7 @@
 }
 
 #ifndef RIPPER
+typedef int (*rb_magic_comment_length_t)(struct parser_params *parser, const char *name, int len);
 typedef void (*rb_magic_comment_setter_t)(struct parser_params *parser, const char *name, const char *val);
 
 static void
@@ -5728,11 +5747,12 @@
 struct magic_comment {
     const char *name;
     rb_magic_comment_setter_t func;
+    rb_magic_comment_length_t length;
 };
 
 static const struct magic_comment magic_comments[] = {
-    {"coding", magic_comment_encoding},
-    {"encoding", magic_comment_encoding},
+    {"coding", magic_comment_encoding, parser_encode_length},
+    {"encoding", magic_comment_encoding, parser_encode_length},
 };
 #endif
 
@@ -5839,7 +5859,11 @@
 #ifndef RIPPER
 	do {
 	    if (strncasecmp(p->name, RSTRING_PTR(name), n) == 0) {
-		str_copy(val, vbeg, vend - vbeg);
+		n = vend - vbeg;
+		if (p->length) {
+		    n = (*p->length)(parser, vbeg, n);
+		}
+		str_copy(val, vbeg, n);
 		(*p->func)(parser, RSTRING_PTR(name), RSTRING_PTR(val));
 		break;
 	    }
@@ -5890,7 +5914,7 @@
     }
     beg = str;
     while ((*str == '-' || *str == '_' || ISALNUM(*str)) && ++str < send);
-    s = rb_str_new(beg, str - beg);
+    s = rb_str_new(beg, parser_encode_length(parser, beg, str - beg));
     parser_set_encode(parser, RSTRING_PTR(s));
     rb_str_resize(s, 0);
 }

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

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