Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 518 lines (436 sloc) 10.729 kB
817a62d 2000-05-01
matz authored
1 /**********************************************************************
99d0354 Initial revision
matz authored
2
3 range.c -
4
5 $Author$
6 $Date$
7 created at: Thu Aug 19 17:46:47 JST 1993
8
d550752 * re.c (match_select): should propagate taintness.
matz authored
9 Copyright (C) 1993-2002 Yukihiro Matsumoto
99d0354 Initial revision
matz authored
10
817a62d 2000-05-01
matz authored
11 **********************************************************************/
99d0354 Initial revision
matz authored
12
13 #include "ruby.h"
14
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
15 VALUE rb_cRange;
b53fdf2 * ruby.c (proc_options): unexpected SecurityError happens when -T4.
matz authored
16 static ID id_cmp, id_succ, id_beg, id_end, id_excl;
07bb9f2 1.4.0
matz authored
17
5c51be8 matz
matz authored
18 #define EXCL(r) RTEST(rb_ivar_get((r), id_excl))
19 #define SET_EXCL(r,v) rb_ivar_set((r), id_excl, (v)?Qtrue:Qfalse)
99d0354 Initial revision
matz authored
20
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
21 static VALUE
22 range_check(args)
23 VALUE *args;
24 {
b53fdf2 * ruby.c (proc_options): unexpected SecurityError happens when -T4.
matz authored
25 if (!FIXNUM_P(args[0]) && !rb_obj_is_kind_of(args[0], rb_cNumeric)) {
01d834c * parse.y: yyparse #defines moved from intern.h
matz authored
26 rb_funcall(args[0], id_cmp, 1, args[1]);
27 /* rb_funcall(args[0], id_succ, 0, 0); */
b53fdf2 * ruby.c (proc_options): unexpected SecurityError happens when -T4.
matz authored
28 }
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
29 return Qnil;
30 }
31
32 static VALUE
33 range_failed()
34 {
35 rb_raise(rb_eArgError, "bad value for range");
bd5567f 19991206
matz authored
36 return Qnil; /* dummy */
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
37 }
99d0354 Initial revision
matz authored
38
5928d4c 2000-02-29
matz authored
39 static void
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
40 range_init(range, beg, end, exclude_end)
41 VALUE range, beg, end;
07bb9f2 1.4.0
matz authored
42 int exclude_end;
99d0354 Initial revision
matz authored
43 {
07bb9f2 1.4.0
matz authored
44 VALUE args[2];
99d0354 Initial revision
matz authored
45
07bb9f2 1.4.0
matz authored
46 args[0] = beg; args[1] = end;
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
47 if (!FIXNUM_P(beg) || !FIXNUM_P(end)) {
f6e9837 * regex.c (re_search): should consider reverse search.
matz authored
48 rb_rescue(range_check, (VALUE)args, range_failed, 0);
99d0354 Initial revision
matz authored
49 }
50
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
51 SET_EXCL(range, exclude_end);
52 rb_ivar_set(range, id_beg, beg);
53 rb_ivar_set(range, id_end, end);
99d0354 Initial revision
matz authored
54 }
55
56 VALUE
07bb9f2 1.4.0
matz authored
57 rb_range_new(beg, end, exclude_end)
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
58 VALUE beg, end;
07bb9f2 1.4.0
matz authored
59 int exclude_end;
60 {
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
61 VALUE range = rb_obj_alloc(rb_cRange);
5928d4c 2000-02-29
matz authored
62
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
63 range_init(range, beg, end, exclude_end);
64 return range;
07bb9f2 1.4.0
matz authored
65 }
66
67 static VALUE
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
68 range_initialize(argc, argv, range)
07bb9f2 1.4.0
matz authored
69 int argc;
70 VALUE *argv;
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
71 VALUE range;
07bb9f2 1.4.0
matz authored
72 {
bb85be1 * array.c (rb_ary_sort_bang): returns self, even if its length is
matz authored
73 VALUE beg, end, flags;
07bb9f2 1.4.0
matz authored
74
bb85be1 * array.c (rb_ary_sort_bang): returns self, even if its length is
matz authored
75 rb_scan_args(argc, argv, "21", &beg, &end, &flags);
5928d4c 2000-02-29
matz authored
76 /* Ranges are immutable, so that they should be initialized only once. */
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
77 if (rb_ivar_defined(range, id_beg)) {
b6b8afa * numeric.c (num_step): better iteration condition for float
matz authored
78 rb_name_error(rb_intern("initialize"), "`initialize' called twice");
5928d4c 2000-02-29
matz authored
79 }
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
80 range_init(range, beg, end, RTEST(flags));
5928d4c 2000-02-29
matz authored
81 return Qnil;
07bb9f2 1.4.0
matz authored
82 }
83
84 static VALUE
85 range_exclude_end_p(range)
86 VALUE range;
99d0354 Initial revision
matz authored
87 {
07bb9f2 1.4.0
matz authored
88 return EXCL(range)?Qtrue:Qfalse;
99d0354 Initial revision
matz authored
89 }
90
91 static VALUE
5c51be8 matz
matz authored
92 range_eq(range, obj)
93 VALUE range, obj;
94 {
2ba87ec thread_critical bug reported by Dave - matz
matz authored
95 if (range == obj) return Qtrue;
5c51be8 matz
matz authored
96 if (!rb_obj_is_kind_of(obj, rb_cRange)) return Qfalse;
97
98 if (!rb_equal(rb_ivar_get(range, id_beg), rb_ivar_get(obj, id_beg)))
99 return Qfalse;
100 if (!rb_equal(rb_ivar_get(range, id_end), rb_ivar_get(obj, id_end)))
101 return Qfalse;
102
103 if (EXCL(range) != EXCL(obj)) return Qfalse;
104
105 return Qtrue;
106 }
107
b53fdf2 * ruby.c (proc_options): unexpected SecurityError happens when -T4.
matz authored
108 static int
6432869 * string.c (rb_str_new2): NULL pointer check added.
matz authored
109 r_eq(a, b)
b53fdf2 * ruby.c (proc_options): unexpected SecurityError happens when -T4.
matz authored
110 VALUE a, b;
111 {
112 if (a == b) return Qtrue;
113
114 if (rb_funcall(a, id_cmp, 1, b) == INT2FIX(0))
115 return Qtrue;
116 return Qfalse;
117 }
118
119 static int
6432869 * string.c (rb_str_new2): NULL pointer check added.
matz authored
120 r_lt(a, b)
b53fdf2 * ruby.c (proc_options): unexpected SecurityError happens when -T4.
matz authored
121 VALUE a, b;
122 {
123 VALUE r = rb_funcall(a, id_cmp, 1, b);
124
6432869 * string.c (rb_str_new2): NULL pointer check added.
matz authored
125 if (rb_cmpint(r) < 0) return Qtrue;
b53fdf2 * ruby.c (proc_options): unexpected SecurityError happens when -T4.
matz authored
126 return Qfalse;
127 }
128
129 static int
6432869 * string.c (rb_str_new2): NULL pointer check added.
matz authored
130 r_le(a, b)
b53fdf2 * ruby.c (proc_options): unexpected SecurityError happens when -T4.
matz authored
131 VALUE a, b;
132 {
133 VALUE r = rb_funcall(a, id_cmp, 1, b);
134
6432869 * string.c (rb_str_new2): NULL pointer check added.
matz authored
135 if (rb_cmpint(r) <= 0) return Qtrue;
b53fdf2 * ruby.c (proc_options): unexpected SecurityError happens when -T4.
matz authored
136 return Qfalse;
137 }
138
139 static int
140 r_gt(a,b)
141 VALUE a, b;
142 {
143 VALUE r = rb_funcall(a, id_cmp, 1, b);
144
6432869 * string.c (rb_str_new2): NULL pointer check added.
matz authored
145 if (rb_cmpint(r) > 0) return Qtrue;
b53fdf2 * ruby.c (proc_options): unexpected SecurityError happens when -T4.
matz authored
146 return Qfalse;
147 }
148
5c51be8 matz
matz authored
149 static VALUE
7b1e0f2 * file.c (path_check_1): forgot to initialize 'p'.
matz authored
150 range_eql(range, obj)
151 VALUE range, obj;
152 {
153 if (range == obj) return Qtrue;
154 if (!rb_obj_is_kind_of(obj, rb_cRange)) return Qfalse;
155
156 if (!rb_eql(rb_ivar_get(range, id_beg), rb_ivar_get(obj, id_beg)))
157 return Qfalse;
158 if (!rb_eql(rb_ivar_get(range, id_end), rb_ivar_get(obj, id_end)))
159 return Qfalse;
160
161 if (EXCL(range) != EXCL(obj)) return Qfalse;
162
163 return Qtrue;
164 }
165
166 static VALUE
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
167 range_hash(range)
168 VALUE range;
7b1e0f2 * file.c (path_check_1): forgot to initialize 'p'.
matz authored
169 {
170 long hash = EXCL(range);
171 VALUE v;
172
173 v = rb_hash(rb_ivar_get(range, id_beg));
174 hash ^= v << 1;
175 v = rb_hash(rb_ivar_get(range, id_end));
176 hash ^= v << 9;
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
177 hash ^= EXCL(range) << 24;
7b1e0f2 * file.c (path_check_1): forgot to initialize 'p'.
matz authored
178
179 return INT2FIX(hash);
180 }
181
182 static VALUE
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
183 str_step(args)
299d4e6 * range.c (range_step): new method.
matz authored
184 VALUE *args;
185 {
186 return rb_str_upto(args[0], args[1], EXCL(args[2]));
187 }
188
189 static VALUE
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
190 step_i(i, iter)
299d4e6 * range.c (range_step): new method.
matz authored
191 VALUE i;
192 long *iter;
193 {
194 iter[0]--;
195 if (iter[0] == 0) {
196 rb_yield(i);
197 iter[0] = iter[1];
198 }
199 return Qnil;
200 }
201
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
202 static void
203 range_each_func(range, func, v, e, arg)
204 VALUE range;
205 void (*func) _((VALUE, void*));
206 void *arg;
207 {
208 if (EXCL(range)) {
209 while (r_lt(v, e)) {
210 if (r_eq(v, e)) break;
211 (*func)(v, arg);
212 v = rb_funcall(v, id_succ, 0, 0);
213 }
214 }
215 else {
216 while (r_le(v, e)) {
217 (*func)(v, arg);
218 if (r_eq(v, e)) break;
219 v = rb_funcall(v, id_succ, 0, 0);
220 }
221 }
222 }
223
299d4e6 * range.c (range_step): new method.
matz authored
224 static VALUE
225 range_step(argc, argv, range)
226 int argc;
227 VALUE *argv;
228 VALUE range;
229 {
230 VALUE b, e, step;
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
231 long unit;
299d4e6 * range.c (range_step): new method.
matz authored
232
233 b = rb_ivar_get(range, id_beg);
234 e = rb_ivar_get(range, id_end);
b6b8afa * numeric.c (num_step): better iteration condition for float
matz authored
235 if (rb_scan_args(argc, argv, "01", &step) == 0) {
236 step = INT2FIX(1);
237 }
299d4e6 * range.c (range_step): new method.
matz authored
238
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
239 unit = NUM2LONG(step);
240 if (unit <= 0) {
241 rb_raise(rb_eArgError, "step can't be <= 0");
242 }
299d4e6 * range.c (range_step): new method.
matz authored
243 if (FIXNUM_P(b) && FIXNUM_P(e)) { /* fixnums are special */
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
244 long end = FIX2LONG(e);
b6b8afa * numeric.c (num_step): better iteration condition for float
matz authored
245 long i;
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
246
40e566a * error.c: use HAVE_DECL_SYS_NERR instead of platform names.
matz authored
247 if (!EXCL(range)) end += 1;
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
248 for (i=FIX2LONG(b); i<end; i+=unit) {
40e566a * error.c: use HAVE_DECL_SYS_NERR instead of platform names.
matz authored
249 rb_yield(INT2NUM(i));
299d4e6 * range.c (range_step): new method.
matz authored
250 }
251 }
252 else if (rb_obj_is_kind_of(b, rb_cNumeric)) {
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
253 ID c = rb_intern(EXCL(range) ? "<" : "<=");
299d4e6 * range.c (range_step): new method.
matz authored
254
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
255 while (RTEST(rb_funcall(b, c, 1, e))) {
40e566a * error.c: use HAVE_DECL_SYS_NERR instead of platform names.
matz authored
256 rb_yield(b);
257 b = rb_funcall(b, '+', 1, step);
299d4e6 * range.c (range_step): new method.
matz authored
258 }
259 }
260 else if (TYPE(b) == T_STRING) {
261 VALUE args[5];
a469664 * range.c (range_step): 'iter' here should be an array.
matz authored
262 long iter[2];
299d4e6 * range.c (range_step): new method.
matz authored
263
264 args[0] = b; args[1] = e; args[2] = range;
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
265 iter[0] = 1; iter[1] = unit;
266 rb_iterate((VALUE(*)_((VALUE)))str_step, (VALUE)args, step_i, (VALUE)iter);
299d4e6 * range.c (range_step): new method.
matz authored
267 }
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
268 else {
269 long args[2];
299d4e6 * range.c (range_step): new method.
matz authored
270
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
271 if (!rb_respond_to(b, id_succ)) {
272 rb_raise(rb_eTypeError, "cannot iterate from %s",
273 rb_class2name(CLASS_OF(b)));
299d4e6 * range.c (range_step): new method.
matz authored
274 }
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
275 args[0] = 1;
276 args[1] = unit;
277 range_each_func(range, step_i, b, e, args);
299d4e6 * range.c (range_step): new method.
matz authored
278 }
279 return range;
280 }
281
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
282 static void
283 each_i(v, arg)
284 VALUE v;
285 void *arg;
286 {
287 rb_yield(v);
288 }
289
299d4e6 * range.c (range_step): new method.
matz authored
290 static VALUE
b6b8afa * numeric.c (num_step): better iteration condition for float
matz authored
291 range_each(range)
292 VALUE range;
293 {
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
294 VALUE beg, end;
295
296 beg = rb_ivar_get(range, id_beg);
297 end = rb_ivar_get(range, id_end);
298
299 if (!rb_respond_to(beg, id_succ)) {
300 rb_raise(rb_eTypeError, "cannot iterate from %s",
301 rb_class2name(CLASS_OF(beg)));
302 }
303 if (TYPE(beg) == T_STRING) {
304 VALUE args[5];
305 long iter[2];
306
307 args[0] = beg; args[1] = end; args[2] = range;
308 iter[0] = 1; iter[1] = 1;
309 rb_iterate((VALUE(*)_((VALUE)))str_step, (VALUE)args, step_i, (VALUE)iter);
310 }
311 else {
312 range_each_func(range, each_i, beg, end, 0);
313 }
314 return range;
b6b8afa * numeric.c (num_step): better iteration condition for float
matz authored
315 }
316
317 static VALUE
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
318 range_first(range)
319 VALUE range;
99d0354 Initial revision
matz authored
320 {
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
321 return rb_ivar_get(range, id_beg);
99d0354 Initial revision
matz authored
322 }
323
324 static VALUE
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
325 range_last(range)
326 VALUE range;
99d0354 Initial revision
matz authored
327 {
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
328 return rb_ivar_get(range, id_end);
99d0354 Initial revision
matz authored
329 }
330
331 VALUE
07bb9f2 1.4.0
matz authored
332 rb_range_beg_len(range, begp, lenp, len, err)
99d0354 Initial revision
matz authored
333 VALUE range;
07bb9f2 1.4.0
matz authored
334 long *begp, *lenp;
335 long len;
336 int err;
99d0354 Initial revision
matz authored
337 {
07bb9f2 1.4.0
matz authored
338 long beg, end, b, e;
99d0354 Initial revision
matz authored
339
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
340 if (!rb_obj_is_kind_of(range, rb_cRange)) return Qfalse;
99d0354 Initial revision
matz authored
341
07bb9f2 1.4.0
matz authored
342 beg = b = NUM2LONG(rb_ivar_get(range, id_beg));
343 end = e = NUM2LONG(rb_ivar_get(range, id_end));
344
345 if (beg < 0) {
346 beg += len;
347 if (beg < 0) goto out_of_range;
348 }
349 if (err == 0 || err == 2) {
350 if (beg > len) goto out_of_range;
351 if (end > len || (!EXCL(range) && end == len))
352 end = len;
353 }
354 if (end < 0) {
355 end += len;
356 if (end < 0) {
357 if (beg == 0 && end == -1 && !EXCL(range)) {
358 len = 0;
359 goto length_set;
360 }
361 goto out_of_range;
362 }
363 }
364 len = end - beg;
365 if (!EXCL(range)) len++; /* include end point */
366 if (len < 0) goto out_of_range;
367
368 length_set:
369 *begp = beg;
370 *lenp = len;
371
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
372 return Qtrue;
07bb9f2 1.4.0
matz authored
373
374 out_of_range:
375 if (err) {
2231bb6 * array.c: fixed format string for 'long' args (%d -> %ld).
michal authored
376 rb_raise(rb_eRangeError, "%ld..%s%ld out of range",
f4d7f48 * class.c (rb_include_module): detect cyclic module inclusion.
matz authored
377 b, EXCL(range)? "." : "", e);
07bb9f2 1.4.0
matz authored
378 }
379 return Qnil;
99d0354 Initial revision
matz authored
380 }
381
382 static VALUE
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
383 range_min(range)
384 VALUE range;
385
386 {
bfd97c5 object.c: rb_Integer reformat, nil#to_f added to rb_define_method.
michal authored
387 VALUE b = rb_ivar_get(range, id_beg);
388 VALUE e = rb_ivar_get(range, id_end);
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
389
390 if (r_le(b, e)) return b;
391 return e;
392 }
393
394 static VALUE
395 range_max(range)
396 VALUE range;
397 {
bfd97c5 object.c: rb_Integer reformat, nil#to_f added to rb_define_method.
michal authored
398 VALUE b = rb_ivar_get(range, id_beg);
399 VALUE e = rb_ivar_get(range, id_end);
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
400
401 if (r_gt(b, e)) return b;
402 return e;
403 }
404
405 static VALUE
99d0354 Initial revision
matz authored
406 range_to_s(range)
407 VALUE range;
408 {
409 VALUE str, str2;
410
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
411 str = rb_obj_as_string(rb_ivar_get(range, id_beg));
412 str2 = rb_obj_as_string(rb_ivar_get(range, id_end));
620b13d 2000-04-10
matz authored
413 str = rb_str_dup(str);
07bb9f2 1.4.0
matz authored
414 rb_str_cat(str, "...", EXCL(range)?3:2);
620b13d 2000-04-10
matz authored
415 rb_str_append(str, str2);
416 OBJ_INFECT(str, str2);
99d0354 Initial revision
matz authored
417
418 return str;
419 }
420
421 static VALUE
422 range_inspect(range)
423 VALUE range;
424 {
425 VALUE str, str2;
426
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
427 str = rb_inspect(rb_ivar_get(range, id_beg));
428 str2 = rb_inspect(rb_ivar_get(range, id_end));
620b13d 2000-04-10
matz authored
429 str = rb_str_dup(str);
07bb9f2 1.4.0
matz authored
430 rb_str_cat(str, "...", EXCL(range)?3:2);
620b13d 2000-04-10
matz authored
431 rb_str_append(str, str2);
432 OBJ_INFECT(str, str2);
99d0354 Initial revision
matz authored
433
434 return str;
435 }
436
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
437 static void
438 member_i(v, args)
439 VALUE v;
440 VALUE *args;
1462975 991207
matz authored
441 {
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
442 if (rb_equal(v, args[0])) {
443 args[1] = Qtrue;
444 }
1462975 991207
matz authored
445 }
446
447 static VALUE
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
448 range_member(range, val)
449 VALUE range, val;
99d0354 Initial revision
matz authored
450 {
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
451 VALUE beg, end;
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
452 VALUE args[2];
99d0354 Initial revision
matz authored
453
07bb9f2 1.4.0
matz authored
454 beg = rb_ivar_get(range, id_beg);
455 end = rb_ivar_get(range, id_end);
99d0354 Initial revision
matz authored
456
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
457 if (!rb_respond_to(beg, id_succ)) {
458 rb_raise(rb_eTypeError, "cannot iterate from %s",
459 rb_class2name(CLASS_OF(beg)));
07bb9f2 1.4.0
matz authored
460 }
0390fc5 * range.c (range_step): iteration done using "+" if elements are
matz authored
461 args[0] = val;
462 args[1] = Qfalse;
463 range_each_func(range, member_i, beg, end, args);
464 return args[1];
b53fdf2 * ruby.c (proc_options): unexpected SecurityError happens when -T4.
matz authored
465 }
466
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
467 static VALUE
468 range_include(range, val)
469 VALUE range, val;
470 {
471 VALUE beg, end;
472
473 beg = rb_ivar_get(range, id_beg);
474 end = rb_ivar_get(range, id_end);
475 if (r_gt(beg, val)) return Qfalse;
476 if (EXCL(range)) {
477 if (r_lt(val, end)) return Qtrue;
478 }
479 else {
480 if (r_le(val, end)) return Qtrue;
481 }
482 return Qfalse;
483 }
484
99d0354 Initial revision
matz authored
485 void
486 Init_Range()
487 {
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
488 rb_cRange = rb_define_class("Range", rb_cObject);
489 rb_include_module(rb_cRange, rb_mEnumerable);
5928d4c 2000-02-29
matz authored
490 rb_define_method(rb_cRange, "initialize", range_initialize, -1);
5c51be8 matz
matz authored
491 rb_define_method(rb_cRange, "==", range_eq, 1);
eca0b53 * parse.y (yylex): obsolete '?<whitespace>'; use '?\s', '?\n',
matz authored
492 rb_define_method(rb_cRange, "===", range_include, 1);
7b1e0f2 * file.c (path_check_1): forgot to initialize 'p'.
matz authored
493 rb_define_method(rb_cRange, "eql?", range_eql, 1);
494 rb_define_method(rb_cRange, "hash", range_hash, 0);
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
495 rb_define_method(rb_cRange, "each", range_each, 0);
299d4e6 * range.c (range_step): new method.
matz authored
496 rb_define_method(rb_cRange, "step", range_step, -1);
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
497 rb_define_method(rb_cRange, "first", range_first, 0);
498 rb_define_method(rb_cRange, "last", range_last, 0);
499 rb_define_method(rb_cRange, "begin", range_first, 0);
500 rb_define_method(rb_cRange, "end", range_last, 0);
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
501 rb_define_method(rb_cRange, "min", range_min, 0);
502 rb_define_method(rb_cRange, "max", range_max, 0);
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
503 rb_define_method(rb_cRange, "to_s", range_to_s, 0);
504 rb_define_method(rb_cRange, "inspect", range_inspect, 0);
a7cf78e * parse.y (yylex): fixed 'print CGI::bar() {}, "\n"' syntax
matz authored
505 rb_define_alias(rb_cRange, "to_ary", "to_a");
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
506
07bb9f2 1.4.0
matz authored
507 rb_define_method(rb_cRange, "exclude_end?", range_exclude_end_p, 0);
508
b53fdf2 * ruby.c (proc_options): unexpected SecurityError happens when -T4.
matz authored
509 rb_define_method(rb_cRange, "member?", range_member, 1);
90b8654 * eval.c (rb_eval): ruby_frame->last_func may be null, if it's
matz authored
510 rb_define_method(rb_cRange, "include?", range_include, 1);
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
511
512 id_cmp = rb_intern("<=>");
b53fdf2 * ruby.c (proc_options): unexpected SecurityError happens when -T4.
matz authored
513 id_succ = rb_intern("succ");
a2af08d This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
514 id_beg = rb_intern("begin");
515 id_end = rb_intern("end");
5c51be8 matz
matz authored
516 id_excl = rb_intern("excl");
99d0354 Initial revision
matz authored
517 }
Something went wrong with that request. Please try again.