From 5a2465db313df5f50cf7e4945afa70cc93322718 Mon Sep 17 00:00:00 2001 From: eban Date: Sat, 20 Nov 2004 14:04:10 +0000 Subject: * test/ruby/test_stringchar.rb (test_bang): added. * string.c (rb_str_upcase_bang, rb_str_capitalize_bang) (rb_str_swapcase_bang): missing rb_str_modify(). git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@7340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ string.c | 3 +++ test/ruby/test_stringchar.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/ChangeLog b/ChangeLog index 752ffe293..6627f10c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Nov 18 18:41:08 2004 Kazuhiro NISHIYAMA + + * test/ruby/test_stringchar.rb (test_bang): added. + + * string.c (rb_str_upcase_bang, rb_str_capitalize_bang) + (rb_str_swapcase_bang): missing rb_str_modify(). + Tue Nov 20 13:26:03 2004 NARUSE, Yui * ext/nkf/nkf-utf8/utf8tbl.c: original revision 1.7 diff --git a/string.c b/string.c index 1d7ba3aa6..e02fb504b 100644 --- a/string.c +++ b/string.c @@ -2725,6 +2725,7 @@ rb_str_upcase_bang(str) char *s, *send; int modify = 0; + rb_str_modify(str); s = RSTRING(str)->ptr; send = s + RSTRING(str)->len; while (s < send) { if (ismbchar(*s)) { @@ -2838,6 +2839,7 @@ rb_str_capitalize_bang(str) char *s, *send; int modify = 0; + rb_str_modify(str); if (RSTRING(str)->len == 0 || !RSTRING(str)->ptr) return Qnil; s = RSTRING(str)->ptr; send = s + RSTRING(str)->len; if (ISLOWER(*s)) { @@ -2895,6 +2897,7 @@ rb_str_swapcase_bang(str) char *s, *send; int modify = 0; + rb_str_modify(str); s = RSTRING(str)->ptr; send = s + RSTRING(str)->len; while (s < send) { if (ismbchar(*s)) { diff --git a/test/ruby/test_stringchar.rb b/test/ruby/test_stringchar.rb index 943b65651..34934e87b 100644 --- a/test/ruby/test_stringchar.rb +++ b/test/ruby/test_stringchar.rb @@ -113,4 +113,54 @@ EOS } assert_equal(0, a.size) end + + def test_bang + s = "aBc" + s.upcase + assert_equal("aBc", s) + s.upcase! + assert_equal("ABC", s) + + s = "aBc" + s.downcase + assert_equal("aBc", s) + s.downcase! + assert_equal("abc", s) + + s = "aBc" + s.swapcase + assert_equal("aBc", s) + s.swapcase! + assert_equal("AbC", s) + + s = "aBc" + s.capitalize + assert_equal("aBc", s) + s.capitalize! + assert_equal("Abc", s) + + s = "aBc" + s.tr("a-z", "A-Z") + assert_equal("aBc", s) + s.tr!("a-z", "A-Z") + assert_equal("ABC", s) + + s = "aaBBcc" + s.tr_s("a-z", "A-Z") + assert_equal("aaBBcc", s) + s.tr_s!("a-z", "A-Z") + assert_equal("ABBC", s) + + s = "aaBBcc" + s.squeeze("a-z") + assert_equal("aaBBcc", s) + s.squeeze!("a-z") + assert_equal("aBBc", s) + + s = "aaBBcc" + s.delete("a-z") + assert_equal("aaBBcc", s) + s.delete!("a-z") + assert_equal("BB", s) + end end -- cgit