~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to range.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-05-16 12:37:06 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20080516123706-r4llcdfd35aobrjv
Tags: 1.9.0.1-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.
* debian/control:
  - ruby1.9 pkg: moved rdoc1.9 suggestion to depends. (LP: #228345)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
  range.c -
4
4
 
5
5
  $Author: nobu $
6
 
  $Date: 2007-12-05 15:15:23 +0900 (Wed, 05 Dec 2007) $
7
6
  created at: Thu Aug 19 17:46:47 JST 1993
8
7
 
9
8
  Copyright (C) 1993-2007 Yukihiro Matsumoto
11
10
**********************************************************************/
12
11
 
13
12
#include "ruby/ruby.h"
 
13
#include "ruby/encoding.h"
14
14
 
15
15
VALUE rb_cRange;
16
16
static ID id_cmp, id_succ, id_beg, id_end, id_excl;
253
253
        iter[0] -= INT2FIX(1) & ~FIXNUM_FLAG;
254
254
    }
255
255
    else {
256
 
        VALUE one = INT2FIX(1);
257
 
        iter[0] = rb_funcall(iter[0], '-', 1, &one);
 
256
        iter[0] = rb_funcall(iter[0], '-', 1, INT2FIX(1));
258
257
    }
259
258
    if (iter[0] == INT2FIX(0)) {
260
259
        rb_yield(i);
598
597
        excl = EXCL(range);
599
598
    }
600
599
    else {
601
 
        b = rb_check_to_integer(range, "begin");
602
 
        if (NIL_P(b))
603
 
            return Qfalse;
604
 
        e = rb_check_to_integer(range, "end");
605
 
        if (NIL_P(e))
606
 
            return Qfalse;
 
600
        if (!rb_respond_to(range, id_beg)) return Qfalse;
 
601
        if (!rb_respond_to(range, id_end)) return Qfalse;
 
602
        b = rb_funcall(range, id_beg, 0);
 
603
        e = rb_funcall(range, id_end, 0);
607
604
        excl = RTEST(rb_funcall(range, rb_intern("exclude_end?"), 0));
608
605
    }
609
606
    beg = NUM2LONG(b);
750
747
        }
751
748
        return Qfalse;
752
749
    }
 
750
    else if (TYPE(beg) == T_STRING && TYPE(end) == T_STRING &&
 
751
             RSTRING_LEN(beg) == 1 && RSTRING_LEN(end) == 1) {
 
752
        if (NIL_P(val)) return Qfalse;
 
753
        if (TYPE(val) == T_STRING) {
 
754
            if (RSTRING_LEN(val) == 0 || RSTRING_LEN(val) > 1)
 
755
                return Qfalse;
 
756
            else {
 
757
                char b = RSTRING_PTR(beg)[0];
 
758
                char e = RSTRING_PTR(end)[0];
 
759
                char v = RSTRING_PTR(val)[0];
 
760
 
 
761
                if (ISASCII(b) && ISASCII(e) && ISASCII(v)) {
 
762
                    if (b <= v && v < e) return Qtrue;
 
763
                    if (!EXCL(range) && v == e) return Qtrue;
 
764
                    return Qfalse;
 
765
                }
 
766
            }
 
767
        }
 
768
    }
753
769
    /* TODO: ruby_frame->this_func = rb_intern("include?"); */
754
770
    return rb_call_super(1, &val);
755
771
}