From 86697ca7b47ee826598c30948549651e662f09e3 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 31 May 2012 16:14:11 +0900 Subject: reimplement String#downcase --- src/string.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/string.c') 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(); } -- cgit v1.2.3