* encoding.c (rb_enc_associate_index, rb_enc_get_index): check if
object is encoding capable. [ruby-dev:31780] * string.c (rb_str_subpat_set): check for if the argument is a String. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1b56bcce22
commit
26adfc185f
@ -1,3 +1,10 @@
|
|||||||
|
Sat Sep 15 17:04:08 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* encoding.c (rb_enc_associate_index, rb_enc_get_index): check if
|
||||||
|
object is encoding capable. [ruby-dev:31780]
|
||||||
|
|
||||||
|
* string.c (rb_str_subpat_set): check for if the argument is a String.
|
||||||
|
|
||||||
Sat Sep 15 13:31:21 2007 Kouhei Sutou <kou@cozmixng.org>
|
Sat Sep 15 13:31:21 2007 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
* lib/rss.rb, lib/rss/, test/rss/:
|
* lib/rss.rb, lib/rss/, test/rss/:
|
||||||
|
44
encoding.c
44
encoding.c
@ -79,9 +79,49 @@ rb_enc_find(const char *name)
|
|||||||
return ONIG_ENCODING_ASCII;
|
return ONIG_ENCODING_ASCII;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
enc_capable(VALUE obj)
|
||||||
|
{
|
||||||
|
if (IMMEDIATE_P(obj)) return Qfalse;
|
||||||
|
switch (BUILTIN_TYPE(obj)) {
|
||||||
|
case T_STRING:
|
||||||
|
case T_REGEXP:
|
||||||
|
case T_FILE:
|
||||||
|
return Qtrue;
|
||||||
|
default:
|
||||||
|
return Qfalse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
enc_check_capable(VALUE x)
|
||||||
|
{
|
||||||
|
if (!enc_capable(x)) {
|
||||||
|
const char *etype;
|
||||||
|
|
||||||
|
if (NIL_P(x)) {
|
||||||
|
etype = "nil";
|
||||||
|
}
|
||||||
|
else if (FIXNUM_P(x)) {
|
||||||
|
etype = "Fixnum";
|
||||||
|
}
|
||||||
|
else if (SYMBOL_P(x)) {
|
||||||
|
etype = "Symbol";
|
||||||
|
}
|
||||||
|
else if (rb_special_const_p(x)) {
|
||||||
|
etype = RSTRING_PTR(rb_obj_as_string(x));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
etype = rb_obj_classname(x);
|
||||||
|
}
|
||||||
|
rb_raise(rb_eTypeError, "wrong argument type %s (not encode capable)", etype);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_enc_associate_index(VALUE obj, int idx)
|
rb_enc_associate_index(VALUE obj, int idx)
|
||||||
{
|
{
|
||||||
|
enc_check_capable(obj);
|
||||||
if (idx < ENCODING_INLINE_MAX) {
|
if (idx < ENCODING_INLINE_MAX) {
|
||||||
ENCODING_SET(obj, idx);
|
ENCODING_SET(obj, idx);
|
||||||
return;
|
return;
|
||||||
@ -117,8 +157,10 @@ rb_enc_associate(VALUE obj, rb_encoding *enc)
|
|||||||
int
|
int
|
||||||
rb_enc_get_index(VALUE obj)
|
rb_enc_get_index(VALUE obj)
|
||||||
{
|
{
|
||||||
int i = ENCODING_GET(obj);
|
int i;
|
||||||
|
|
||||||
|
enc_check_capable(obj);
|
||||||
|
i = ENCODING_GET(obj);
|
||||||
if (i == ENCODING_INLINE_MAX) {
|
if (i == ENCODING_INLINE_MAX) {
|
||||||
VALUE iv;
|
VALUE iv;
|
||||||
|
|
||||||
|
1
string.c
1
string.c
@ -1996,6 +1996,7 @@ rb_str_subpat_set(VALUE str, VALUE re, int nth, VALUE val)
|
|||||||
}
|
}
|
||||||
end = RMATCH(match)->END(nth);
|
end = RMATCH(match)->END(nth);
|
||||||
len = end - start;
|
len = end - start;
|
||||||
|
StringValue(val);
|
||||||
rb_enc_check(str, val);
|
rb_enc_check(str, val);
|
||||||
rb_str_splice_0(str, start, len, val);
|
rb_str_splice_0(str, start, len, val);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user