summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-30 12:09:36 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-30 12:09:36 +0000
commitc00233f7072034404ad43948fd4df92f291af6cb (patch)
tree6329859a38f4b72fb1d4daa7df6ef824f6e369bb /string.c
parent58b6ac5f67329330e34c09f6612ea90e1598a5ae (diff)
merges r20046 from trunk into ruby_1_9_1.
* 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: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@20059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/string.c b/string.c
index ea7b04f335..eb4625f495 100644
--- a/string.c
+++ b/string.c
@@ -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);