static VALUE // bug? rb_csa_search_l(VALUE self, VALUE oc, VALUE range) { CSA *sa = csa_ptr(self); i64 ll,rr; int c; i64 ret; c = FIX2INT(oc); #if USE_RANGE ll = FIX2LONG(range_first(range)); rr = FIX2LONG(range_last(range)); if (range_exclude_end_p(range) == Qtrue) rr--; #else if (RALEN(range) != 2) { return Qnil; } ll = FIX2LONG(RAPTR(range)[0]); rr = FIX2LONG(RAPTR(range)[1]); #endif ret = sa->searchsub(c, sa, &ll, &rr); if (ret == -1) return Qnil; #if USE_RANGE return rb_range_new(LONG2FIX(ll), LONG2FIX(rr), Qnil); #else return rb_ary_new3(2, LONG2FIX(ll), LONG2FIX(rr)); #endif }
static VALUE //rb_csa_text(VALUE self, VALUE oi, VALUE oj) rb_csa_text(VALUE self, VALUE range) { CSA *sa = csa_ptr(self); i64 i,j,n; uchar *buf; #if USE_RANGE i = FIX2LONG(range_first(range)); j = FIX2LONG(range_last(range)); if (range_exclude_end_p(range) == Qtrue) j--; #else // i = FIX2LONG(oi); // j = FIX2LONG(oj); if (RALEN(range) != 2) { return Qnil; } i = FIX2LONG(RAPTR(range)[0]); j = FIX2LONG(RAPTR(range)[1]); #endif n = sa->n; if (i < 0 || i > n || j < 0 || j > n) { // error return Qnil; } buf = (uchar *)alloca(j-i+1+1); sa->text(buf, sa, i, j); buf[j-i+1] = 0; return rb_str_new(buf, j-i+1); }
static VALUE rb_csa_child_l(VALUE self, VALUE range) { CSA *sa = csa_ptr(self); i64 l,r,ll,rr; int c,i; VALUE charset; i64 ret; #if USE_RANGE ll = FIX2LONG(range_first(range)); rr = FIX2LONG(range_last(range)); if (range_exclude_end_p(range) == Qtrue) rr--; #else if (RALEN(range) != 2) { return Qnil; } ll = FIX2LONG(RAPTR(range)[0]); rr = FIX2LONG(RAPTR(range)[1]); #endif l = r = -1; if (!rb_block_given_p()) charset = rb_ary_new(); for (i=0; i<sa->m; i++) { c = sa->AtoC[i]; l = ll; r = rr; ret = sa->searchsub(c, sa, &l, &r); if (ret == 0) { if (rb_block_given_p()) { rb_yield(rb_ary_new3(2,INT2FIX(c), #if USE_RANGE rb_range_new(LONG2FIX(l), LONG2FIX(r), Qnil))); #else rb_ary_new3(2,LONG2FIX(l),LONG2FIX(r)))); #endif } else { rb_ary_push(charset, rb_ary_new3(2,INT2FIX(c), #if USE_RANGE rb_range_new(LONG2FIX(l), LONG2FIX(r), Qnil))); #else rb_ary_new3(2,LONG2FIX(l),LONG2FIX(r)))); #endif } } }
static VALUE range_min(int argc, VALUE *argv, VALUE range) { if (rb_block_given_p()) { return rb_call_super(argc, argv); } else if (argc != 0) { return range_first(argc, argv, range); } else { VALUE b = RANGE_BEG(range); VALUE e = RANGE_END(range); int c = rb_cmpint(rb_funcall(b, id_cmp, 1, e), b, e); if (c > 0 || (c == 0 && EXCL(range))) return Qnil; return b; } }