mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* encoding.c (enc_check_encoding): returns index now.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
00befb4b3f
commit
3cb10b32bb
2 changed files with 18 additions and 13 deletions
|
@ -1,4 +1,6 @@
|
||||||
Mon Oct 22 10:57:07 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Mon Oct 22 11:03:09 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* encoding.c (enc_check_encoding): returns index now.
|
||||||
|
|
||||||
* encoding.c (rb_enc_compatible): check if two objects have compatible
|
* encoding.c (rb_enc_compatible): check if two objects have compatible
|
||||||
encodings.
|
encodings.
|
||||||
|
|
27
encoding.c
27
encoding.c
|
@ -56,36 +56,39 @@ rb_enc_from_encoding(rb_encoding *encoding)
|
||||||
return enc;
|
return enc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rb_encoding *
|
static int
|
||||||
enc_check_encoding(VALUE obj)
|
enc_check_encoding(VALUE obj)
|
||||||
{
|
{
|
||||||
|
int index;
|
||||||
if (SPECIAL_CONST_P(obj) || BUILTIN_TYPE(obj) != T_DATA ||
|
if (SPECIAL_CONST_P(obj) || BUILTIN_TYPE(obj) != T_DATA ||
|
||||||
RDATA(obj)->dmark != enc_mark) {
|
RDATA(obj)->dmark != enc_mark) {
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
return RDATA(obj)->data;
|
index = rb_enc_get_index(obj);
|
||||||
|
if (rb_enc_from_index(index) != RDATA(obj)->data)
|
||||||
|
return -1;
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rb_encoding *
|
static rb_encoding *
|
||||||
enc_get_encoding(VALUE obj)
|
enc_get_encoding(VALUE obj)
|
||||||
{
|
{
|
||||||
rb_encoding *enc = enc_check_encoding(obj);
|
if (enc_check_encoding(obj) < 0) {
|
||||||
if (!enc) {
|
|
||||||
rb_raise(rb_eTypeError, "wrong argument type %s (expected Encoding)",
|
rb_raise(rb_eTypeError, "wrong argument type %s (expected Encoding)",
|
||||||
rb_obj_classname(obj));
|
rb_obj_classname(obj));
|
||||||
}
|
}
|
||||||
return enc;
|
return RDATA(obj)->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
rb_to_encoding_index(VALUE enc)
|
rb_to_encoding_index(VALUE enc)
|
||||||
{
|
{
|
||||||
rb_encoding *encoding;
|
int idx;
|
||||||
|
|
||||||
if (NIL_P(enc)) return 0;
|
if (NIL_P(enc)) return 0;
|
||||||
encoding = enc_check_encoding(enc);
|
idx = enc_check_encoding(enc);
|
||||||
if (encoding) {
|
if (idx >= 0) {
|
||||||
return rb_enc_to_index(encoding);
|
return index;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return rb_enc_find_index(StringValueCStr(enc));
|
return rb_enc_find_index(StringValueCStr(enc));
|
||||||
|
@ -99,8 +102,8 @@ rb_to_encoding(VALUE enc)
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
if (NIL_P(enc)) return rb_enc_from_index(0);
|
if (NIL_P(enc)) return rb_enc_from_index(0);
|
||||||
encoding = enc_check_encoding(enc);
|
idx = enc_check_encoding(enc);
|
||||||
if (encoding) return encoding;
|
if (idx >= 0) return RDATA(obj)->data;
|
||||||
if ((idx = rb_enc_find_index(StringValueCStr(enc))) < 0) {
|
if ((idx = rb_enc_find_index(StringValueCStr(enc))) < 0) {
|
||||||
rb_raise(rb_eArgError, "unknown encoding name - %s", RSTRING_PTR(enc));
|
rb_raise(rb_eArgError, "unknown encoding name - %s", RSTRING_PTR(enc));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue