summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--string.c12
-rw-r--r--test/ruby/test_string.rb5
3 files changed, 20 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 2da2152a25..790bef05af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Feb 25 02:17:30 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * string.c (rb_str_delete_bang): should recalculate coderange.
+ [ruby-talk:329267]
+
Tue Feb 24 19:01:05 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* common.mk (main): split from exts and makes main program after
diff --git a/string.c b/string.c
index 1a8b182ecc..452bc6ad0f 100644
--- a/string.c
+++ b/string.c
@@ -1240,7 +1240,12 @@ rb_string_value(volatile VALUE *ptr)
{
VALUE s = *ptr;
if (TYPE(s) != T_STRING) {
- s = rb_str_to_str(s);
+ if (SYMBOL_P(s)) {
+ s = rb_sym_to_s(s);
+ }
+ else {
+ s = rb_str_to_str(s);
+ }
*ptr = s;
}
return s;
@@ -4961,7 +4966,7 @@ rb_str_delete_bang(int argc, VALUE *argv, VALUE str)
char *s, *send, *t;
VALUE del = 0, nodel = 0;
int modify = 0;
- int i, ascompat;
+ int i, ascompat, cr;
if (RSTRING_LEN(str) == 0 || !RSTRING_PTR(str)) return Qnil;
if (argc < 1) {
@@ -4979,6 +4984,7 @@ rb_str_delete_bang(int argc, VALUE *argv, VALUE str)
ascompat = rb_enc_asciicompat(enc);
s = t = RSTRING_PTR(str);
send = RSTRING_END(str);
+ cr = ascompat ? ENC_CODERANGE_7BIT : ENC_CODERANGE_VALID;
while (s < send) {
unsigned int c;
int clen;
@@ -5003,12 +5009,14 @@ rb_str_delete_bang(int argc, VALUE *argv, VALUE str)
else {
if (t != s) rb_enc_mbcput(c, t, enc);
t += clen;
+ if (cr == ENC_CODERANGE_7BIT) cr = ENC_CODERANGE_VALID;
}
s += clen;
}
}
*t = '\0';
STR_SET_LEN(str, t - RSTRING_PTR(str));
+ ENC_CODERANGE_SET(str, cr);
if (modify) return str;
return Qnil;
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index 2315a8c560..a7a2bba0b4 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -474,6 +474,11 @@ class TestString < Test::Unit::TestCase
assert_equal(S("he"), S("hello").delete(S("lo")))
assert_equal(S("hell"), S("hello").delete(S("aeiou"), S("^e")))
assert_equal(S("ho"), S("hello").delete(S("ej-m")))
+
+ assert_equal("a".hash, "a\u0101".delete("\u0101").hash, '[ruby-talk:329267]')
+ assert_equal(true, "a\u0101".delete("\u0101").ascii_only?)
+ assert_equal(true, "a\u3041".delete("\u3041").ascii_only?)
+ assert_equal(false, "a\u3041\u3042".tr("\u3041", "a").ascii_only?)
end
def test_delete!