summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-15 09:05:57 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-15 09:05:57 (GMT)
commitbad0560661b04dc11178732666efa647b4ec9e57 (patch)
tree704f79b79dd653aba899d042797c289884cb4cc6 /range.c
parent228cfd02d5d7035480556cb65476ca89996922c7 (diff)
range.c: r_cover_p
* range.c (r_cover_p): extract from range_cover and share with range_include. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/range.c b/range.c
index 54c7d88..42d361c 100644
--- a/range.c
+++ b/range.c
@@ -22,6 +22,8 @@ static ID id_beg, id_end, id_excl, id_integer_p, id_div;
#define id_cmp idCmp
#define id_succ idSucc
+static VALUE r_cover_p(VALUE, VALUE, VALUE, VALUE);
+
#define RANGE_BEG(r) (RSTRUCT(r)->as.ary[0])
#define RANGE_END(r) (RSTRUCT(r)->as.ary[1])
#define RANGE_EXCL(r) (RSTRUCT(r)->as.ary[2])
@@ -1176,17 +1178,7 @@ range_include(VALUE range, VALUE val)
if (nv ||
!NIL_P(rb_check_to_integer(beg, "to_int")) ||
!NIL_P(rb_check_to_integer(end, "to_int"))) {
- if (r_le(beg, val)) {
- if (EXCL(range)) {
- if (r_lt(val, end))
- return Qtrue;
- }
- else {
- if (r_le(val, end))
- return Qtrue;
- }
- }
- return Qfalse;
+ 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) {
@@ -1234,6 +1226,12 @@ range_cover(VALUE range, VALUE val)
beg = RANGE_BEG(range);
end = RANGE_END(range);
+ return r_cover_p(range, beg, end, val);
+}
+
+static VALUE
+r_cover_p(VALUE range, VALUE beg, VALUE end, VALUE val)
+{
if (r_le(beg, val)) {
if (EXCL(range)) {
if (r_lt(val, end))