summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-05-31 16:14:11 +0900
committerYukihiro Matsumoto <[email protected]>2012-05-31 16:14:11 +0900
commit86697ca7b47ee826598c30948549651e662f09e3 (patch)
treec2f6031c8c432484b114004a2a7688c3aa5b830b
parent1df00298f91774f37800e0f6d15d1c0b8a10fefa (diff)
downloadmruby-86697ca7b47ee826598c30948549651e662f09e3.tar.gz
mruby-86697ca7b47ee826598c30948549651e662f09e3.zip
reimplement String#downcase
-rw-r--r--src/string.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/string.c b/src/string.c
index a9e0fca13..c9fac896d 100644
--- a/src/string.c
+++ b/src/string.c
@@ -927,6 +927,20 @@ mrb_str_chop(mrb_state *mrb, mrb_value self)
static mrb_value
mrb_str_downcase_bang(mrb_state *mrb, mrb_value str)
{
+ char *s, *send;
+ int modify = 0;
+
+ s = RSTRING_PTR(str);
+ send = RSTRING_END(str);
+ while (s < send) {
+ if (ISUPPER(*s)) {
+ *s = tolower(*s);
+ modify = 1;
+ }
+ s++;
+ }
+
+ if (modify) return str;
return mrb_nil_value();
}