зеркало из https://github.com/github/ruby.git
Extract range type check functions
This commit is contained in:
Родитель
8286eed20b
Коммит
1a149aab77
55
range.c
55
range.c
|
@ -1769,6 +1769,35 @@ range_include(VALUE range, VALUE val)
|
|||
return rb_call_super(1, &val);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
range_integer_edge_p(VALUE beg, VALUE end)
|
||||
{
|
||||
return (!NIL_P(rb_check_to_integer(beg, "to_int")) ||
|
||||
!NIL_P(rb_check_to_integer(end, "to_int")));
|
||||
}
|
||||
|
||||
static inline bool
|
||||
range_string_edge_p(VALUE beg, VALUE end)
|
||||
{
|
||||
return RB_TYPE_P(beg, T_STRING) || RB_TYPE_P(end, T_STRING);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
range_string_range_p(VALUE beg, VALUE end)
|
||||
{
|
||||
return RB_TYPE_P(beg, T_STRING) && RB_TYPE_P(end, T_STRING);
|
||||
}
|
||||
|
||||
static inline VALUE
|
||||
range_include_fallback(VALUE beg, VALUE end)
|
||||
{
|
||||
if (NIL_P(beg) || NIL_P(end)) {
|
||||
rb_raise(rb_eTypeError, "cannot determine inclusion in beginless/endless ranges");
|
||||
}
|
||||
|
||||
return Qundef;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
range_string_cover_internal(VALUE range, VALUE val)
|
||||
{
|
||||
|
@ -1777,13 +1806,11 @@ range_string_cover_internal(VALUE range, VALUE val)
|
|||
int nv = FIXNUM_P(beg) || FIXNUM_P(end) ||
|
||||
linear_object_p(beg) || linear_object_p(end);
|
||||
|
||||
if (nv ||
|
||||
!NIL_P(rb_check_to_integer(beg, "to_int")) ||
|
||||
!NIL_P(rb_check_to_integer(end, "to_int"))) {
|
||||
if (nv || range_integer_edge_p(beg, end)) {
|
||||
return r_cover_p(range, beg, end, val);
|
||||
}
|
||||
else if (RB_TYPE_P(beg, T_STRING) || RB_TYPE_P(end, T_STRING)) {
|
||||
if (RB_TYPE_P(beg, T_STRING) && RB_TYPE_P(end, T_STRING)) {
|
||||
else if (range_string_edge_p(beg, end)) {
|
||||
if (range_string_range_p(beg, end)) {
|
||||
return r_cover_p(range, beg, end, val);
|
||||
}
|
||||
if (NIL_P(beg)) {
|
||||
|
@ -1801,11 +1828,7 @@ range_string_cover_internal(VALUE range, VALUE val)
|
|||
}
|
||||
}
|
||||
|
||||
if (NIL_P(beg) || NIL_P(end)) {
|
||||
rb_raise(rb_eTypeError, "cannot determine inclusion in beginless/endless ranges");
|
||||
}
|
||||
|
||||
return Qundef;
|
||||
return range_include_fallback(beg, end);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -1816,20 +1839,14 @@ range_include_internal(VALUE range, VALUE val)
|
|||
int nv = FIXNUM_P(beg) || FIXNUM_P(end) ||
|
||||
linear_object_p(beg) || linear_object_p(end);
|
||||
|
||||
if (nv ||
|
||||
!NIL_P(rb_check_to_integer(beg, "to_int")) ||
|
||||
!NIL_P(rb_check_to_integer(end, "to_int"))) {
|
||||
if (nv || range_integer_edge_p(beg, end)) {
|
||||
return r_cover_p(range, beg, end, val);
|
||||
}
|
||||
else if (RB_TYPE_P(beg, T_STRING) && RB_TYPE_P(end, T_STRING)) {
|
||||
else if (range_string_range_p(beg, end)) {
|
||||
return rb_str_include_range_p(beg, end, val, RANGE_EXCL(range));
|
||||
}
|
||||
|
||||
if (NIL_P(beg) || NIL_P(end)) {
|
||||
rb_raise(rb_eTypeError, "cannot determine inclusion in beginless/endless ranges");
|
||||
}
|
||||
|
||||
return Qundef;
|
||||
return range_include_fallback(beg, end);
|
||||
}
|
||||
|
||||
static int r_cover_range_p(VALUE range, VALUE beg, VALUE end, VALUE val);
|
||||
|
|
Загрузка…
Ссылка в новой задаче