Ruby
2.7.2p137(2020-10-01revision5445e0435260b449decf2ac16f9d09bae3cafe72)
|
Go to the documentation of this file.
22 static ID id_beg, id_end, id_excl;
24 #define id_succ idSucc
30 #define RANGE_SET_BEG(r, v) (RSTRUCT_SET(r, 0, v))
31 #define RANGE_SET_END(r, v) (RSTRUCT_SET(r, 1, v))
32 #define RANGE_SET_EXCL(r, v) (RSTRUCT_SET(r, 2, v))
33 #define RBOOL(v) ((v) ? Qtrue : Qfalse)
35 #define EXCL(r) RTEST(RANGE_EXCL(r))
58 range_init(
range, beg, end,
RBOOL(exclude_end));
84 VALUE beg, end, flags;
247 while (r_less(
v, e) < 0) {
248 if ((*func)(
v,
arg))
break;
253 while ((c = r_less(
v, e)) <= 0) {
254 if ((*func)(
v,
arg))
break;
320 check_step_domain(
VALUE step)
395 VALUE b, e, step, tmp;
404 if ((b_num_p && (
NIL_P(e) || e_num_p)) || (
NIL_P(b) && e_num_p)) {
406 range_step_size, b, e, step,
EXCL(
range));
412 step = check_step_domain(step);
434 if (
i + unit <
i)
break;
488 if (!discrete_object_p(b)) {
503 return range_step(1, &step,
range);
506 #if SIZEOF_DOUBLE == 8 && defined(HAVE_INT64_T)
515 union int64_double convert;
527 double_as_int64(
double d)
529 union int64_double convert;
531 return d < 0 ? -convert.i : convert.i;
546 bsearch_integer_range(
VALUE beg,
VALUE end,
int excl)
551 #define BSEARCH_CHECK(expr) \
553 VALUE val = (expr); \
554 VALUE v = rb_yield(val); \
556 if (v == INT2FIX(0)) return val; \
557 smaller = (SIGNED_VALUE)v < 0; \
559 else if (v == Qtrue) { \
563 else if (v == Qfalse || v == Qnil) { \
566 else if (rb_obj_is_kind_of(v, rb_cNumeric)) { \
567 int cmp = rb_cmpint(rb_funcall(v, id_cmp, 1, INT2FIX(0)), v, INT2FIX(0)); \
568 if (!cmp) return val; \
572 rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE \
573 " (must be numeric, true, false or nil)", \
599 if (!smaller)
return Qnil;
676 #define BSEARCH(conv) \
678 RETURN_ENUMERATOR(range, 0, 0); \
679 if (EXCL(range)) high--; \
681 while (low < high) { \
682 mid = ((high < 0) == (low < 0)) ? low + ((high - low) / 2) \
683 : (low < -high) ? -((-1 - low - high)/2 + 1) : (low + high) / 2; \
684 BSEARCH_CHECK(conv(mid)); \
692 if (low == org_high) { \
693 BSEARCH_CHECK(conv(low)); \
694 if (!smaller) return Qnil; \
709 #if SIZEOF_DOUBLE == 8 && defined(HAVE_INT64_T)
714 BSEARCH(int64_as_double_to_num);
717 else if (is_integer_p(beg) && is_integer_p(end)) {
719 return bsearch_integer_range(beg, end,
EXCL(
range));
721 else if (is_integer_p(beg) &&
NIL_P(end)) {
728 return bsearch_integer_range(beg, mid, 0);
733 else if (
NIL_P(beg) && is_integer_p(end)) {
740 return bsearch_integer_range(mid, end, 0);
819 return range_size(
range);
881 if (
NIL_P(end))
goto fixnum_endless;
882 if (
FIXNUM_P(end))
goto fixnum_loop;
885 if (
NIL_P(end))
goto bignum_endless;
937 if (!discrete_object_p(beg)) {
942 range_each_func(
range, each_i, 0);
1151 else if (
argc != 0) {
1210 if (c == 0)
return Qnil;
1280 long beg, end, origbeg, origend;
1288 if (
NIL_P(e)) excl = 0;
1300 if (
err == 0 ||
err == 2) {
1317 origbeg, excl ?
"." :
"", origend);
1413 VALUE ret = range_include_internal(
range, val, 1);
1414 if (ret !=
Qundef)
return ret;
1443 VALUE ret = range_include_internal(
range, val, 0);
1444 if (ret !=
Qundef)
return ret;
1454 linear_object_p(beg) || linear_object_p(end);
1459 return r_cover_p(
range, beg, end, val);
1463 if (string_use_cover) {
1464 return r_cover_p(
range, beg, end, val);
1471 else if (
NIL_P(beg)) {
1477 else if (
NIL_P(end)) {
1530 return RBOOL(r_cover_range_p(
range, beg, end, val));
1532 return r_cover_p(
range, beg, end, val);
1544 VALUE val_beg, val_end, val_max;
1552 if (!
NIL_P(val_beg) && !
NIL_P(val_end) && r_less(val_beg, val_end) > -
EXCL(val))
return FALSE;
1553 if (!
NIL_P(val_beg) && !r_cover_p(
range, beg, end, val_beg))
return FALSE;
1555 cmp_end = r_less(end, val_end);
1558 return cmp_end >= 0;
1563 else if (cmp_end >= 0) {
1570 return r_less(end, val_max) >= 0;
1576 if (
NIL_P(beg) || r_less(beg, val) <= 0) {
1578 if (
NIL_P(end) || r_less(val, end) <= -excl)
1601 VALUE beg, end, excl;
1607 range_modify(
range);
1758 #define rb_intern(str) rb_intern_const(str)
1766 "begin",
"end",
"excl",
NULL);
VALUE rb_ary_new_capa(long capa)
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
#define RANGE_SET_EXCL(r, v)
void rb_include_module(VALUE klass, VALUE module)
VALUE rb_assoc_new(VALUE car, VALUE cdr)
VALUE rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
#define range(low, item, hi)
VALUE rb_arith_seq_new(VALUE obj, VALUE meth, int argc, VALUE const *argv, rb_enumerator_size_func *size_fn, VALUE beg, VALUE end, VALUE step, int excl)
int rb_block_given_p(void)
Determines if the current method is given a block.
#define RBIGNUM_POSITIVE_P(b)
RUBY_EXTERN VALUE rb_cNumeric
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
VALUE rb_equal(VALUE, VALUE)
Same as Object#===, case equality.
VALUE rb_obj_as_string(VALUE)
#define RB_TYPE_P(obj, type)
RUBY_EXTERN VALUE rb_cTime
#define FIXNUM_ZERO_P(num)
int rb_num_negative_p(VALUE)
VALUE rb_call_super(int, const VALUE *)
VALUE rb_inspect(VALUE)
Convenient wrapper of Object::inspect.
VALUE rb_check_string_type(VALUE)
VALUE rb_Float(VALUE)
Equivalent to Kernel#Float in Ruby.
VALUE rb_str_include_range_p(VALUE beg, VALUE end, VALUE val, VALUE exclusive)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
#define SPECIAL_CONST_P(x)
#define rb_cmpint(cmp, a, b)
VALUE rb_struct_alloc_noinit(VALUE)
int rb_respond_to(VALUE, ID)
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
int rb_eql(VALUE, VALUE)
Determines if obj1 and obj2 are equal in terms of Object::eql?.
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_ivar_get(VALUE, ID)
#define BSEARCH_CHECK(expr)
VALUE rb_str_upto_endless_each(VALUE, int(*each)(VALUE, VALUE), VALUE)
#define rb_check_frozen(obj)
VALUE rb_str_intern(VALUE)
VALUE rb_Array(VALUE)
Equivalent to Kernel#Array in Ruby.
VALUE rb_big_cmp(VALUE x, VALUE y)
ID rb_frame_this_func(void)
The original name of the current method.
VALUE rb_check_to_integer(VALUE, const char *)
Tries to convert val into Integer.
VALUE rb_ary_last(int argc, const VALUE *argv, VALUE ary)
VALUE rb_ary_push(VALUE ary, VALUE item)
st_index_t rb_hash_start(st_index_t)
#define RARRAY_AREF(a, i)
VALUE rb_struct_define_without_accessor(const char *, VALUE, rb_alloc_func_t,...)
#define RETURN_ENUMERATOR(obj, argc, argv)
VALUE rb_struct_init_copy(VALUE copy, VALUE s)
VALUE rb_to_int(VALUE)
Converts val into Integer.
#define CONST_ID(var, str)
RUBY_EXTERN VALUE rb_cObject
VALUE ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl)
VALUE rb_str_append(VALUE, VALUE)
#define OPTIMIZED_CMP(a, b, data)
#define rb_hash_uint(h, i)
VALUE rb_obj_alloc(VALUE)
Allocates an instance of klass.
char str[HTML_ESCAPE_MAX_LEN+1]
int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl, int allow_endless)
VALUE rb_block_call(VALUE q, ID w, int e, const VALUE *r, type *t, VALUE y)
Call a method with a block.
VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE)
const char * rb_obj_classname(VALUE)
VALUE rb_big_plus(VALUE x, VALUE y)
VALUE rb_int_gt(VALUE x, VALUE y)
#define RANGE_SET_BEG(r, v)
VALUE rb_rescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2,...)
An equivalent of rescue clause.
VALUE rb_exec_recursive_paired(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE, VALUE)
VALUE rb_ivar_set(VALUE, ID, VALUE)
#define RGENGC_WB_PROTECTED_OBJECT
VALUE rb_range_new(VALUE beg, VALUE end, int exclude_end)
#define RB_INTEGER_TYPE_P(obj)
#define NEWOBJ_OF(obj, type, klass, flags)
int rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp)
#define rb_name_err_raise(mesg, recv, name)
VALUE rb_int_plus(VALUE x, VALUE y)
VALUE rb_str_cat(VALUE, const char *, long)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
#define RBIGNUM_NEGATIVE_P(b)
#define RANGE_SET_END(r, v)
VALUE rb_int_minus(VALUE x, VALUE y)
VALUE rb_str_upto_each(VALUE, VALUE, int, int(*each)(VALUE, VALUE), VALUE)