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

ruby-changes:19316

From: nobu <ko1@a...>
Date: Wed, 27 Apr 2011 00:56:03 +0900 (JST)
Subject: [ruby-changes:19316] Ruby:r31356 (trunk): * transcode.c (econv_opts): add newline option.

nobu	2011-04-27 00:55:58 +0900 (Wed, 27 Apr 2011)

  New Revision: 31356

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

  Log:
    * transcode.c (econv_opts): add newline option.

  Modified files:
    trunk/ChangeLog
    trunk/transcode.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31355)
+++ ChangeLog	(revision 31356)
@@ -1,5 +1,7 @@
-Wed Apr 27 00:55:18 2011  Nobuyoshi Nakada  <nobu@r...>
+Wed Apr 27 00:55:56 2011  Nobuyoshi Nakada  <nobu@r...>
 
+	* transcode.c (econv_opts): add newline option.
+
 	* io.c (validate_enc_binmode, rb_io_extract_modeenc): set newline
 	  decorator according to open mode.
 
Index: transcode.c
===================================================================
--- transcode.c	(revision 31355)
+++ transcode.c	(revision 31356)
@@ -26,6 +26,9 @@
 static VALUE sym_universal_newline;
 static VALUE sym_crlf_newline;
 static VALUE sym_cr_newline;
+#ifdef ENABLE_ECONV_NEWLINE_OPTION
+static VALUE sym_newline, sym_universal, sym_crlf, sym_cr, sym_lf;
+#endif
 static VALUE sym_partial_input;
 
 static VALUE sym_invalid_byte_sequence;
@@ -2468,6 +2471,32 @@
         }
     }
 
+#ifdef ENABLE_ECONV_NEWLINE_OPTION
+    v = rb_hash_aref(opt, sym_newline);
+    if (!NIL_P(v)) {
+	ecflags &= ~ECONV_NEWLINE_DECORATOR_MASK;
+	if (v == sym_universal) {
+	    ecflags |= ECONV_UNIVERSAL_NEWLINE_DECORATOR;
+	}
+	else if (v == sym_crlf) {
+	    ecflags |= ECONV_CRLF_NEWLINE_DECORATOR;
+	}
+	else if (v == sym_cr) {
+	    ecflags |= ECONV_CR_NEWLINE_DECORATOR;
+	}
+	else if (v == sym_lf) {
+	    /* ecflags |= ECONV_LF_NEWLINE_DECORATOR; */
+	}
+	else if (SYMBOL_P(v)) {
+	    rb_raise(rb_eArgError, "unexpected value for newline option: %s",
+		     rb_id2name(SYM2ID(v)));
+	}
+	else {
+	    rb_raise(rb_eArgError, "unexpected value for newline option");
+	}
+    }
+    else
+#endif
     {
 	int setflags = 0, newlineflag = 0;
 
@@ -4324,6 +4353,14 @@
     sym_cr_newline = ID2SYM(rb_intern("cr_newline"));
     sym_partial_input = ID2SYM(rb_intern("partial_input"));
 
+#ifdef ENABLE_ECONV_NEWLINE_OPTION
+    sym_newline = ID2SYM(rb_intern("newline"));
+    sym_universal = ID2SYM(rb_intern("universal"));
+    sym_crlf = ID2SYM(rb_intern("crlf"));
+    sym_cr = ID2SYM(rb_intern("cr"));
+    sym_lf = ID2SYM(rb_intern("lf"));
+#endif
+
     rb_define_method(rb_cString, "encode", str_encode, -1);
     rb_define_method(rb_cString, "encode!", str_encode_bang, -1);
 

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

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