mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
7510468707
commit
f7207fa2fc
3 changed files with 15 additions and 14 deletions
|
@ -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
|
||||
|
|
20
io.c
20
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue