Ruby
2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
|
Go to the documentation of this file.
22 static ID id_beg, id_end, id_excl;
24 #define id_succ idSucc
28 #define RANGE_SET_BEG(r, v) (RSTRUCT_SET(r, 0, v))
29 #define RANGE_SET_END(r, v) (RSTRUCT_SET(r, 1, v))
30 #define RANGE_SET_EXCL(r, v) (RSTRUCT_SET(r, 2, v))
31 #define RBOOL(v) ((v) ? Qtrue : Qfalse)
33 #define EXCL(r) RTEST(RANGE_EXCL(r))
56 range_init(
range, beg, end,
RBOOL(exclude_end));
82 VALUE beg, end, flags;
245 while (r_less(
v, e) < 0) {
246 if ((*func)(
v,
arg))
break;
251 while ((c = r_less(
v, e)) <= 0) {
252 if ((*func)(
v,
arg))
break;
318 check_step_domain(
VALUE step)
393 VALUE b, e, step, tmp;
402 if ((b_num_p && (
NIL_P(e) || e_num_p)) || (
NIL_P(b) && e_num_p)) {
404 range_step_size, b, e, step,
EXCL(
range));
410 step = check_step_domain(step);
432 if (
i + unit <
i)
break;
486 if (!discrete_object_p(b)) {
501 return range_step(1, &step,
range);
504 #if SIZEOF_DOUBLE == 8 && defined(HAVE_INT64_T)
513 union int64_double convert;
525 double_as_int64(
double d)
527 union int64_double convert;
529 return d < 0 ? -convert.i : convert.i;
544 bsearch_integer_range(
VALUE beg,
VALUE end,
int excl)
549 #define BSEARCH_CHECK(expr) \
551 VALUE val = (expr); \
552 VALUE v = rb_yield(val); \
554 if (v == INT2FIX(0)) return val; \
555 smaller = (SIGNED_VALUE)v < 0; \
557 else if (v == Qtrue) { \
561 else if (v == Qfalse || v == Qnil) { \
564 else if (rb_obj_is_kind_of(v, rb_cNumeric)) { \
565 int cmp = rb_cmpint(rb_funcall(v, id_cmp, 1, INT2FIX(0)), v, INT2FIX(0)); \
566 if (!cmp) return val; \
570 rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE \
571 " (must be numeric, true, false or nil)", \
597 if (!smaller)
return Qnil;
674 #define BSEARCH(conv) \
676 RETURN_ENUMERATOR(range, 0, 0); \
677 if (EXCL(range)) high--; \
679 while (low < high) { \
680 mid = ((high < 0) == (low < 0)) ? low + ((high - low) / 2) \
681 : (low < -high) ? -((-1 - low - high)/2 + 1) : (low + high) / 2; \
682 BSEARCH_CHECK(conv(mid)); \
690 if (low == org_high) { \
691 BSEARCH_CHECK(conv(low)); \
692 if (!smaller) return Qnil; \
707 #if SIZEOF_DOUBLE == 8 && defined(HAVE_INT64_T)
712 BSEARCH(int64_as_double_to_num);
715 else if (is_integer_p(beg) && is_integer_p(end)) {
717 return bsearch_integer_range(beg, end,
EXCL(
range));
719 else if (is_integer_p(beg) &&
NIL_P(end)) {
726 return bsearch_integer_range(beg, mid, 0);
731 else if (
NIL_P(beg) && is_integer_p(end)) {
738 return bsearch_integer_range(mid, end, 0);
817 return range_size(
range);
879 if (
NIL_P(end))
goto fixnum_endless;
880 if (
FIXNUM_P(end))
goto fixnum_loop;
883 if (
NIL_P(end))
goto bignum_endless;
935 if (!discrete_object_p(beg)) {
940 range_each_func(
range, each_i, 0);
1149 else if (
argc != 0) {
1208 if (c == 0)
return Qnil;
1275 long beg, end, origbeg, origend;
1283 if (
NIL_P(e)) excl = 0;
1295 if (
err == 0 ||
err == 2) {
1312 origbeg, excl ?
"." :
"", origend);
1408 VALUE ret = range_include_internal(
range, val, 1);
1409 if (ret !=
Qundef)
return ret;
1438 VALUE ret = range_include_internal(
range, val, 0);
1439 if (ret !=
Qundef)
return ret;
1449 linear_object_p(beg) || linear_object_p(end);
1454 return r_cover_p(
range, beg, end, val);
1458 if (string_use_cover) {
1459 return r_cover_p(
range, beg, end, val);
1466 else if (
NIL_P(beg)) {
1472 else if (
NIL_P(end)) {
1525 return RBOOL(r_cover_range_p(
range, beg, end, val));
1527 return r_cover_p(
range, beg, end, val);
1539 VALUE val_beg, val_end, val_max;
1547 if (!
NIL_P(val_beg) && !
NIL_P(val_end) && r_less(val_beg, val_end) > -
EXCL(val))
return FALSE;
1548 if (!
NIL_P(val_beg) && !r_cover_p(
range, beg, end, val_beg))
return FALSE;
1550 cmp_end = r_less(end, val_end);
1553 return cmp_end >= 0;
1558 else if (cmp_end >= 0) {
1565 return r_less(end, val_max) >= 0;
1571 if (
NIL_P(beg) || r_less(beg, val) <= 0) {
1573 if (
NIL_P(end) || r_less(val, end) <= -excl)
1596 VALUE beg, end, excl;
1602 range_modify(
range);
1753 #define rb_intern(str) rb_intern_const(str)
1761 "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)
VALUE rb_struct_define_without_accessor(const char *, VALUE, rb_alloc_func_t,...)
#define RETURN_ENUMERATOR(obj, argc, argv)
#define RARRAY_AREF(a, i)
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)