diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-29 16:44:24 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-29 16:44:24 +0000 |
| commit | 798d33ed72d966aeada6e926f46a015e3551eed9 (patch) | |
| tree | 1c0861a421095871233ae66be9a32de1f1aa890c | |
| parent | 4310b5d9ce709225c594ba1e04b2cfe13b105d25 (diff) | |
| download | ruby-798d33ed72d966aeada6e926f46a015e3551eed9.tar.gz ruby-798d33ed72d966aeada6e926f46a015e3551eed9.tar.xz ruby-798d33ed72d966aeada6e926f46a015e3551eed9.zip | |
* string.c (rb_str_check_dummy_enc): new function to check dummy
encoding.
* string.c (rb_str_upcase_bang): case conversion functions should
not be applicable to strings in dummy encoding. [ruby-dev:36985]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@20046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 8 | ||||
| -rw-r--r-- | string.c | 17 |
2 files changed, 22 insertions, 3 deletions
@@ -12,6 +12,14 @@ Thu Oct 30 01:10:32 2008 Yusuke Endoh <mame@tsg.ne.jp> * test/ruby/test_array (test_permutation): add a test that replaces array during permutation. +Wed Oct 29 23:31:34 2008 Yukihiro Matsumoto <matz@ruby-lang.org> + + * string.c (rb_str_check_dummy_enc): new function to check dummy + encoding. + + * string.c (rb_str_upcase_bang): case conversion functions should + not be applicable to strings in dummy encoding. [ruby-dev:36985] + Wed Oct 29 23:57:29 2008 Yusuke Endoh <mame@tsg.ne.jp> * array.c (rb_ary_sort_bang): replacing array during sort broke @@ -4220,6 +4220,15 @@ rb_str_dump(VALUE str) } +static void +rb_str_check_dummy_enc(rb_encoding *enc) +{ + if (rb_enc_dummy_p(enc)) { + rb_raise(rb_eEncCompatError, "incompatible encoding with this operation: %s", + rb_enc_name(enc)); + } +} + /* * call-seq: * str.upcase! => str or nil @@ -4238,6 +4247,7 @@ rb_str_upcase_bang(VALUE str) str_modify_keep_cr(str); enc = STR_ENC_GET(str); + rb_str_check_dummy_enc(enc); s = RSTRING_PTR(str); send = RSTRING_END(str); if (single_byte_optimizable(str)) { while (s < send) { @@ -4319,6 +4329,7 @@ rb_str_downcase_bang(VALUE str) str_modify_keep_cr(str); enc = STR_ENC_GET(str); + rb_str_check_dummy_enc(enc); s = RSTRING_PTR(str); send = RSTRING_END(str); if (single_byte_optimizable(str)) { while (s < send) { @@ -4406,6 +4417,7 @@ rb_str_capitalize_bang(VALUE str) str_modify_keep_cr(str); enc = STR_ENC_GET(str); + rb_str_check_dummy_enc(enc); if (RSTRING_LEN(str) == 0 || !RSTRING_PTR(str)) return Qnil; s = RSTRING_PTR(str); send = RSTRING_END(str); @@ -4469,6 +4481,7 @@ rb_str_swapcase_bang(VALUE str) str_modify_keep_cr(str); enc = STR_ENC_GET(str); + rb_str_check_dummy_enc(enc); s = RSTRING_PTR(str); send = RSTRING_END(str); while (s < send) { unsigned int c = rb_enc_codepoint(s, send, enc); @@ -5996,9 +6009,7 @@ rb_str_rstrip_bang(VALUE str) char *s, *t, *e; enc = STR_ENC_GET(str); - if (rb_enc_dummy_p(enc)) { - rb_raise(rb_eEncCompatError, "incompatible encoding with this operation: %s", rb_enc_name(enc)); - } + rb_str_check_dummy_enc(enc); s = RSTRING_PTR(str); if (!s || RSTRING_LEN(str) == 0) return Qnil; t = e = RSTRING_END(str); |
