ruby-changes:12872
From: naruse <ko1@a...>
Date: Fri, 21 Aug 2009 15:17:14 +0900 (JST)
Subject: [ruby-changes:12872] Ruby:r24605 (trunk): Change modestr syntax for BOM to "BOM|UTF-*".
naruse 2009-08-21 15:16:53 +0900 (Fri, 21 Aug 2009) New Revision: 24605 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24605 Log: Change modestr syntax for BOM to "BOM|UTF-*". * io .c (rb_io_fmode_modestr): change modestr syntax for BOM to "BOM|UTF-*". * io.c (parse_mode_enc): ditto. Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io_m17n.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 24604) +++ ChangeLog (revision 24605) @@ -1,3 +1,10 @@ +Thu Aug 20 01:24:55 2009 NARUSE, Yui <naruse@r...> + + * io.c (rb_io_fmode_modestr): change modestr syntax for BOM + to "BOM|UTF-*". [ruby-dev:39106] + + * io.c (parse_mode_enc): ditto. + Fri Aug 21 15:01:35 2009 NARUSE, Yui <naruse@r...> * ext/readline/readline.c (readline_readline): use rb_prep_terminal Index: io.c =================================================================== --- io.c (revision 24604) +++ io.c (revision 24605) @@ -3938,17 +3938,11 @@ static int io_encname_bom_p(const char *name, long len) { - if (len) { - if (len > 4 && STRNCASECMP(name + len - 4, "-bom", 4) == 0) - return 1; - } - else { + if (!len) { const char *p = strchr(name, ':'); - if (!p) p = name + strlen(name); - if (p - name > 4 && STRNCASECMP(p - 4, "-bom", 4) == 0) - return 1; + len = p ? p - name : strlen(name); } - return 0; + return len > 8 && STRNCASECMP(name, "bom|utf-", 8) == 0; } int @@ -4147,7 +4141,7 @@ idx = -1; else { if (io_encname_bom_p(estr, len)) - len -= 4; + estr += 4; memcpy(encname, estr, len); encname[len] = '\0'; estr = encname; @@ -4157,7 +4151,7 @@ else { long len = strlen(estr); if (io_encname_bom_p(estr, len)) { - len -= 4; + estr += 4; memcpy(encname, estr, len); encname[len] = '\0'; estr = encname; @@ -5481,9 +5475,9 @@ * read string will be tagged by the encoding in reading, * and output string will be converted * to the specified encoding in writing. - * If ext_enc ends with '-bom', check whether the input has a BOM. If + * If ext_enc starts with 'BOM|', check whether the input has a BOM. If * there is a BOM, strip it and set external encoding as - * what the BOM tells. If there is no BOM, use ext_enc without '-bom'. + * what the BOM tells. If there is no BOM, use ext_enc without 'BOM|'. * If two encoding names, * ext_enc and int_enc (external encoding and internal encoding), * are specified, the read string is converted from ext_enc Index: test/ruby/test_io_m17n.rb =================================================================== --- test/ruby/test_io_m17n.rb (revision 24604) +++ test/ruby/test_io_m17n.rb (revision 24605) @@ -1699,7 +1699,7 @@ path = '%s-bom.txt' % name content = text.encode(name) generate_file(path, content) - result = File.read(path, mode: 'rb:utf-7-bom') + result = File.read(path, mode: 'rb:BOM|UTF-8') assert_equal(content[1].force_encoding("ascii-8bit"), result.force_encoding("ascii-8bit")) end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/