aboutsummaryrefslogtreecommitdiffstats
path: root/range.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-15 12:39:56 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-15 12:39:56 +0000
commitf42704ca600a55453fa124946b77ecc7abebc913 (patch)
tree2827e12d1e7e9146c70d281572aa3b40fad7b098 /range.c
parent805d3817b9115276b972cac7a491c1a42a5c36b3 (diff)
downloadruby-f42704ca600a55453fa124946b77ecc7abebc913.tar.gz
range.c: move String specific code
* range.c (range_include): call rb_str_include_range_p on String. * string.c (str_upto_each): extract from rb_str_upto. * string.c (rb_str_include_range_p): move String specific code from Range#include? in range.c. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50502 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c23
1 files changed, 4 insertions, 19 deletions
diff --git a/range.c b/range.c
index cfb8c24fab..8f48cd9089 100644
--- a/range.c
+++ b/range.c
@@ -174,7 +174,7 @@ range_eq(VALUE range, VALUE obj)
/* compares _a_ and _b_ and returns:
* < 0: a < b
* = 0: a = b
- * > 0: a > b or not-comparable
+ * > 0: a > b or non-comparable
*/
static int
r_less(VALUE a, VALUE b)
@@ -1165,24 +1165,9 @@ range_include(VALUE range, VALUE val)
!NIL_P(rb_check_to_integer(end, "to_int"))) {
return r_cover_p(range, beg, end, val);
}
- else if (RB_TYPE_P(beg, T_STRING) && RB_TYPE_P(end, T_STRING) &&
- RSTRING_LEN(beg) == 1 && RSTRING_LEN(end) == 1) {
- if (NIL_P(val)) return Qfalse;
- if (RB_TYPE_P(val, T_STRING)) {
- if (RSTRING_LEN(val) == 0 || RSTRING_LEN(val) > 1)
- return Qfalse;
- else {
- char b = RSTRING_PTR(beg)[0];
- char e = RSTRING_PTR(end)[0];
- char v = RSTRING_PTR(val)[0];
-
- if (ISASCII(b) && ISASCII(e) && ISASCII(v)) {
- if (b <= v && v < e) return Qtrue;
- if (!EXCL(range) && v == e) return Qtrue;
- return Qfalse;
- }
- }
- }
+ else if (RB_TYPE_P(beg, T_STRING) && RB_TYPE_P(end, T_STRING)) {
+ VALUE rb_str_include_range_p(VALUE beg, VALUE end, VALUE val, VALUE exclusive);
+ return rb_str_include_range_p(beg, end, val, RANGE_EXCL(range));
}
/* TODO: ruby_frame->this_func = rb_intern("include?"); */
return rb_call_super(1, &val);