зеркало из https://github.com/github/ruby.git
* encoding.c (rb_to_encoding_index, rb_to_encoding): check if the name
is ascii compatible as well as Encoding.find. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
29732ed8f2
Коммит
c97a842391
|
@ -1,4 +1,7 @@
|
|||
Wed Aug 6 05:26:42 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
Wed Aug 6 05:31:54 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* encoding.c (rb_to_encoding_index, rb_to_encoding): check if the name
|
||||
is ascii compatible as well as Encoding.find.
|
||||
|
||||
* transcode.c (str_encode): no need to duplicate first.
|
||||
|
||||
|
|
43
encoding.c
43
encoding.c
|
@ -121,22 +121,33 @@ rb_to_encoding_index(VALUE enc)
|
|||
else if (NIL_P(enc = rb_check_string_type(enc))) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return rb_enc_find_index(StringValueCStr(enc));
|
||||
if (!rb_enc_asciicompat(rb_enc_get(enc))) {
|
||||
return -1;
|
||||
}
|
||||
return rb_enc_find_index(StringValueCStr(enc));
|
||||
}
|
||||
|
||||
static rb_encoding *
|
||||
to_encoding(VALUE enc)
|
||||
{
|
||||
int idx;
|
||||
|
||||
StringValue(enc);
|
||||
if (!rb_enc_asciicompat(rb_enc_get(enc))) {
|
||||
rb_raise(rb_eArgError, "invalid name encoding (non ASCII)");
|
||||
}
|
||||
idx = rb_enc_find_index(StringValueCStr(enc));
|
||||
if (idx < 0) {
|
||||
rb_raise(rb_eArgError, "unknown encoding name - %s", RSTRING_PTR(enc));
|
||||
}
|
||||
return rb_enc_from_index(idx);
|
||||
}
|
||||
|
||||
rb_encoding *
|
||||
rb_to_encoding(VALUE enc)
|
||||
{
|
||||
int idx;
|
||||
|
||||
idx = enc_check_encoding(enc);
|
||||
if (idx >= 0) return RDATA(enc)->data;
|
||||
if ((idx = rb_enc_find_index(StringValueCStr(enc))) < 0) {
|
||||
rb_raise(rb_eArgError, "unknown encoding name - %s", RSTRING_PTR(enc));
|
||||
}
|
||||
return rb_enc_from_index(idx);
|
||||
if (enc_check_encoding(enc) >= 0) return RDATA(enc)->data;
|
||||
return to_encoding(enc);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -838,17 +849,7 @@ enc_list(VALUE klass)
|
|||
static VALUE
|
||||
enc_find(VALUE klass, VALUE enc)
|
||||
{
|
||||
int idx;
|
||||
|
||||
StringValue(enc);
|
||||
if (!rb_enc_asciicompat(rb_enc_get(enc))) {
|
||||
rb_raise(rb_eArgError, "invalid name encoding (non ASCII)");
|
||||
}
|
||||
idx = rb_enc_find_index(StringValueCStr(enc));
|
||||
if (idx < 0) {
|
||||
rb_raise(rb_eArgError, "unknown encoding name - %s", RSTRING_PTR(enc));
|
||||
}
|
||||
return rb_enc_from_encoding(rb_enc_from_index(idx));
|
||||
return rb_enc_from_encoding(to_encoding(enc));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Загрузка…
Ссылка в новой задаче