summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-21 06:16:53 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-21 06:16:53 +0000
commitf7207fa2fcbbe7aebeed9a08f6092ea59d05cdcf (patch)
treefa33c6ae2a83171400f7c4d110352b95490e9a3a
parent7510468707b8e2f05258afb4147210162a812444 (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24605 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--io.c20
-rw-r--r--test/ruby/test_io_m17n.rb2
3 files changed, 15 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 87119c9381..d5fa990494 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Aug 20 01:24:55 2009 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* ext/readline/readline.c (readline_readline): use rb_prep_terminal
diff --git a/io.c b/io.c
index 901cde930e..fe2a6cd1f6 100644
--- a/io.c
+++ b/io.c
@@ -3938,17 +3938,11 @@ rb_io_fmode_modestr(int fmode)
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 @@ parse_mode_enc(const char *estr, rb_encoding **enc_p, rb_encoding **enc2_p)
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 @@ parse_mode_enc(const char *estr, rb_encoding **enc_p, rb_encoding **enc2_p)
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 @@ check_pipe_command(VALUE filename_or_command)
* 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
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index aed688e591..6f5e686c42 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -1699,7 +1699,7 @@ EOT
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