summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-29 16:44:24 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-29 16:44:24 +0000
commitf27e4c045f752e09176a3c4ef0dd4ba20266fa29 (patch)
tree1c0861a421095871233ae66be9a32de1f1aa890c /string.c
parent86ade651044cc606584e11a5b2e8d02f315d3fa9 (diff)
* 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/trunk@20046 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);