mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
io.c: simplify rb_io_modestr_fmode
* io.c (io_encname_bom_p): needs len always. * io.c (rb_io_modestr_fmode): check BOM only after a colon. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c6e9425c06
commit
16f37446f7
1 changed files with 3 additions and 7 deletions
10
io.c
10
io.c
|
@ -4893,10 +4893,6 @@ io_encname_bom_p(const char *name, long len)
|
|||
{
|
||||
static const char bom_prefix[] = "bom|utf-";
|
||||
enum {bom_prefix_len = (int)sizeof(bom_prefix) - 1};
|
||||
if (!len) {
|
||||
const char *p = strchr(name, ':');
|
||||
len = p ? (long)(p - name) : (long)strlen(name);
|
||||
}
|
||||
return len > bom_prefix_len && STRNCASECMP(name, bom_prefix, bom_prefix_len) == 0;
|
||||
}
|
||||
|
||||
|
@ -4935,7 +4931,9 @@ rb_io_modestr_fmode(const char *modestr)
|
|||
default:
|
||||
goto error;
|
||||
case ':':
|
||||
p = m;
|
||||
p = strchr(m, ':');
|
||||
if (io_encname_bom_p(m, p ? (long)(p - m) : (long)strlen(m)))
|
||||
fmode |= FMODE_SETENC_BY_BOM;
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
@ -4943,8 +4941,6 @@ rb_io_modestr_fmode(const char *modestr)
|
|||
finished:
|
||||
if ((fmode & FMODE_BINMODE) && (fmode & FMODE_TEXTMODE))
|
||||
goto error;
|
||||
if (p && io_encname_bom_p(p, 0))
|
||||
fmode |= FMODE_SETENC_BY_BOM;
|
||||
|
||||
return fmode;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue