mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* transcode.c (str_encode): no need to duplicate first.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18379 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f1ff09fbf6
commit
29732ed8f2
2 changed files with 29 additions and 14 deletions
|
@ -1,3 +1,7 @@
|
|||
Wed Aug 6 05:26:42 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* transcode.c (str_encode): no need to duplicate first.
|
||||
|
||||
Wed Aug 6 05:08:30 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* array.c (rb_ary_sort_bang): reset to real class.
|
||||
|
|
39
transcode.c
39
transcode.c
|
@ -469,6 +469,24 @@ str_transcode(int argc, VALUE *argv, VALUE *self)
|
|||
return to_encidx;
|
||||
}
|
||||
|
||||
static inline VALUE
|
||||
str_encode_associate(VALUE str, int encidx)
|
||||
{
|
||||
int cr = 0;
|
||||
|
||||
rb_enc_associate_index(str, encidx);
|
||||
|
||||
/* transcoded string never be broken. */
|
||||
if (rb_enc_asciicompat(rb_enc_from_index(encidx))) {
|
||||
rb_str_coderange_scan_restartable(RSTRING_PTR(str), RSTRING_END(str), 0, &cr);
|
||||
}
|
||||
else {
|
||||
cr = ENC_CODERANGE_VALID;
|
||||
}
|
||||
ENC_CODERANGE_SET(str, cr);
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* str.encode!(encoding [, options] ) => str
|
||||
|
@ -488,21 +506,10 @@ str_encode_bang(int argc, VALUE *argv, VALUE str)
|
|||
{
|
||||
VALUE newstr = str;
|
||||
int encidx = str_transcode(argc, argv, &newstr);
|
||||
int cr = 0;
|
||||
|
||||
if (encidx < 0) return str;
|
||||
rb_str_shared_replace(str, newstr);
|
||||
rb_enc_associate_index(str, encidx);
|
||||
|
||||
/* transcoded string never be broken. */
|
||||
if (rb_enc_asciicompat(rb_enc_from_index(encidx))) {
|
||||
rb_str_coderange_scan_restartable(RSTRING_PTR(str), RSTRING_END(str), 0, &cr);
|
||||
}
|
||||
else {
|
||||
cr = ENC_CODERANGE_VALID;
|
||||
}
|
||||
ENC_CODERANGE_SET(str, cr);
|
||||
return str;
|
||||
return str_encode_associate(str, encidx);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -521,8 +528,12 @@ str_encode_bang(int argc, VALUE *argv, VALUE str)
|
|||
static VALUE
|
||||
str_encode(int argc, VALUE *argv, VALUE str)
|
||||
{
|
||||
str = rb_str_dup(str);
|
||||
return str_encode_bang(argc, argv, str);
|
||||
VALUE newstr = str;
|
||||
int encidx = str_transcode(argc, argv, &newstr);
|
||||
|
||||
if (encidx < 0) return rb_str_dup(str);
|
||||
RBASIC(newstr)->klass = rb_obj_class(str);
|
||||
return str_encode_associate(newstr, encidx);
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
|
Loading…
Reference in a new issue