/*
 * Document-method: offset
 *
 * call-seq:
 *    mtch.offset(n)      => array
 *    mtch.offset         => array
 *    mtch.offset(symbol) => array
 *
 * Returns a two-element array containing the beginning and ending offsets of
 * the <em>n</em>th match.
 *
 *    m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
 *    m.offset(0)   #=> [1, 7]
 *    m.offset(4)   #=> [6, 7]
 *
 * If no arguments are given, the offsets of the entire
 * sequence are returned.
 *
 *    m = ORegexp.new( '(.)(.)(\d+)(\d)' ).match("THX1138.")
 *    m.offset      #=> [1, 7]
 *
 * If the argument is a symbol, then the offsets of the
 * corresponding named group are returned, or <code>nil</code>
 * if the group does not exist.
 *
 *    m = ORegexp.new( '(?<begin>^.*?)(?<middle>\d)(?<end>.*)' ).match("THX1138")
 *    m.end(:middle) #=> [3, 4]
 */
static VALUE
og_oniguruma_match_offset(int argc, VALUE *argv, VALUE self)
{
  VALUE idx, first, k, nargv[2];
  
  rb_scan_args(argc, argv, "0*", &idx);
  
  first = rb_ary_entry(idx, 0);
  if (SYMBOL_P(first)) {
    k = og_oniguruma_match_to_index(self, first);
    if (!NIL_P(k)) {
      nargv[0] = k;
      nargv[1] = (VALUE)NULL;
      
      return rb_funcall3(self, rb_intern("offset_without_oniguruma"), 1, nargv);
    } else
      return Qnil;
  } else if (RARRAY(idx)->len == 0) {
    nargv[0] = INT2FIX(0);
    nargv[1] = (VALUE)NULL;
    
    return rb_funcall3(self, rb_intern("offset_without_oniguruma"), 1, nargv);
  }
  
  return rb_funcall3(self, rb_intern("offset_without_oniguruma"), RARRAY(idx)->len, RARRAY(idx)->ptr);
}
Example #2
0
static VALUE rb_array_collide_lists(VALUE self, VALUE list1Value, VALUE list2Value)
{
	struct ExtRect* list2=NULL;
	SDL_Rect rect1;
	int i1, i2;
	int list1len, list2len;
	VALUE yieldValue=rb_ary_new2(2);
	VALUE sprite;

	Check_Type(list1Value, T_ARRAY);
	Check_Type(list2Value, T_ARRAY);

	list1len=RARRAY(list1Value)->len;
	list2len=RARRAY(list2Value)->len;

	if(list1len==0 || list2len==0) return self;

	list2=(struct ExtRect*)malloc(list2len*sizeof(struct ExtRect));

	for(i2=0; i2<list2len; i2++){
		sprite=rb_ary_entry(list2Value,i2);
		if(sprite!=Qnil){
			list2[i2].rect=rb_funcall3(sprite, id_rect, 0, NULL);
			RECT2CRECT(list2[i2].rect, &list2[i2].crect);
			list2[i2].sprite=sprite;
		}else{
			list2[i2].sprite=Qnil;
		}
	}

	for(i1=0; i1<list1len; i1++){
		sprite=rb_ary_entry(list1Value,i1);
		if(sprite!=Qnil){
			RECT2CRECT(rb_funcall3(sprite, id_rect, 0, NULL), &rect1);
			for(i2=0; i2<list2len; i2++){
				if(list2[i2].sprite!=Qnil){
					if(intersect(&rect1, &list2[i2].crect)){
						rb_ary_store(yieldValue, 0, sprite);
						rb_ary_store(yieldValue, 1, list2[i2].sprite);
						rb_yield(yieldValue);
					}
				}
			}
		}
	}

	free(list2);
	return self;
}
Example #3
0
static rawmode_arg_t *
rawmode_opt(int argc, VALUE *argv, rawmode_arg_t *opts)
{
    rawmode_arg_t *optp = NULL;
    VALUE vopts;
    rb_scan_args(argc, argv, "0:", &vopts);
    if (!NIL_P(vopts)) {
	VALUE vmin = rb_hash_aref(vopts, ID2SYM(id_min));
	VALUE vtime = rb_hash_aref(vopts, ID2SYM(id_time));
	/* default values by `stty raw` */
	opts->vmin = 1;
	opts->vtime = 0;
	if (!NIL_P(vmin)) {
	    opts->vmin = NUM2INT(vmin);
	    optp = opts;
	}
	if (!NIL_P(vtime)) {
	    VALUE v10 = INT2FIX(10);
	    vtime = rb_funcall3(vtime, '*', 1, &v10);
	    opts->vtime = NUM2INT(vtime);
	    optp = opts;
	}
    }
    return optp;
}
Example #4
0
static VALUE
do_erb_protected_method_call(VALUE data)
{
	struct erb_protect_info *info = (struct erb_protect_info *) data;
	ID method_id;

	assert(info);

	method_id = rb_intern(info->name);

	return rb_funcall3(erb_module, method_id, info->argc, info->args);
}
Example #5
0
static rawmode_arg_t *
rawmode_opt(int argc, VALUE *argv, rawmode_arg_t *opts)
{
    rawmode_arg_t *optp = NULL;
    VALUE vopts;
    rb_scan_args(argc, argv, "0:", &vopts);
    if (!NIL_P(vopts)) {
	VALUE vmin = rb_hash_aref(vopts, ID2SYM(rb_intern("min")));
	VALUE vtime = rb_hash_aref(vopts, ID2SYM(rb_intern("time")));
	VALUE v10 = INT2FIX(10);
	if (!NIL_P(vmin)) {
	    vmin = rb_funcall3(vmin, '*', 1, &v10);
	    opts->vmin = NUM2INT(vmin);
	    optp = opts;
	}
	if (!NIL_P(vtime)) {
	    vtime = rb_funcall3(vtime, '*', 1, &v10);
	    opts->vtime = NUM2INT(vtime);
	    optp = opts;
	}
    }
    return optp;
}
Example #6
0
static rawmode_arg_t *
rawmode_opt(int argc, VALUE *argv, rawmode_arg_t *opts)
{
    rawmode_arg_t *optp = NULL;
    VALUE vopts;
#ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
    rb_scan_args(argc, argv, "0:", &vopts);
#else
    vopts = Qnil;
    if (argc > 0) {
	vopts = argv[--argc];
	if (!NIL_P(vopts)) {
# ifdef HAVE_RB_CHECK_HASH_TYPE
	    vopts = rb_check_hash_type(vopts);
	    if (NIL_P(vopts)) ++argc;
# else
	    Check_Type(vopts, T_HASH);
# endif
	}
    }
    rb_scan_args(argc, argv, "0");
#endif
    if (!NIL_P(vopts)) {
	VALUE vmin = rb_hash_aref(vopts, ID2SYM(rb_intern("min")));
	VALUE vtime = rb_hash_aref(vopts, ID2SYM(rb_intern("time")));
	/* default values by `stty raw` */
	opts->vmin = 1;
	opts->vtime = 0;
	if (!NIL_P(vmin)) {
	    opts->vmin = NUM2INT(vmin);
	    optp = opts;
	}
	if (!NIL_P(vtime)) {
	    VALUE v10 = INT2FIX(10);
	    vtime = rb_funcall3(vtime, '*', 1, &v10);
	    opts->vtime = NUM2INT(vtime);
	    optp = opts;
	}
    }
    return optp;
}
static void method_caller(xmlXPathParserContextPtr ctxt, int nargs)
{
    const xmlChar * function;
    const xmlChar * functionURI;
    size_t i, count;

    xsltTransformContextPtr transform;
    xmlXPathObjectPtr xpath;
    VALUE obj;
    VALUE *args;
    VALUE result;

    transform = xsltXPathGetTransformContext(ctxt);

    function = ctxt->context->function;
    functionURI = ctxt->context->functionURI;
    obj = (VALUE)xsltGetExtData(transform, functionURI);

    count = (size_t)ctxt->valueNr;
    args = calloc(count, sizeof(VALUE *));

    for(i = 0; i < count; i++) {
	VALUE thing;

	xpath = valuePop(ctxt);
	switch(xpath->type) {
	    case XPATH_STRING:
		thing = NOKOGIRI_STR_NEW2(xpath->stringval);
		break;
	    case XPATH_NODESET:
		if(NULL == xpath->nodesetval) {
		    thing = Nokogiri_wrap_xml_node_set(
			    xmlXPathNodeSetCreate(NULL),
			    DOC_RUBY_OBJECT(ctxt->context->doc));
		} else {
		    thing = Nokogiri_wrap_xml_node_set(xpath->nodesetval,
			    DOC_RUBY_OBJECT(ctxt->context->doc));
		}
		break;
	    default:
		rb_raise(rb_eRuntimeError, "do not handle type: %d", xpath->type);
	}
	args[i] = thing;
	xmlFree(xpath);
    }
    result = rb_funcall3(obj, rb_intern((const char *)function), (int)count, args);
    free(args);
    switch(TYPE(result)) {
	case T_FLOAT:
	case T_BIGNUM:
	case T_FIXNUM:
	    xmlXPathReturnNumber(ctxt, NUM2DBL(result));
	    break;
	case T_STRING:
	    xmlXPathReturnString(
		    ctxt,
		    xmlStrdup((xmlChar *)StringValuePtr(result))
		    );
	    break;
	case T_TRUE:
	    xmlXPathReturnTrue(ctxt);
	    break;
	case T_FALSE:
	    xmlXPathReturnFalse(ctxt);
	    break;
	case T_NIL:
	    break;
	default:
	    rb_raise(rb_eRuntimeError, "Invalid return type");
    }
}
Example #8
0
static VALUE
call_mi(VALUE args)
{
  VALUE *values = (VALUE *)args;
  return rb_funcall3(values[0], values[1], (int)values[2], values+3);
}
Example #9
0
static VALUE protected_start_mapping(VALUE pointer)
{
    VALUE *args = (VALUE *)pointer;
    return rb_funcall3(args[0], id_start_mapping, 4, args + 1);
}
Example #10
0
static VALUE protected_start_sequence(VALUE pointer)
{
    VALUE *args = (VALUE *)pointer;
    return rb_funcall3(args[0], id_start_sequence, 4, args + 1);
}
Example #11
0
static VALUE protected_scalar(VALUE pointer)
{
    VALUE *args = (VALUE *)pointer;
    return rb_funcall3(args[0], id_scalar, 6, args + 1);
}
Example #12
0
static VALUE protected_start_document(VALUE pointer)
{
    VALUE *args = (VALUE *)pointer;
    return rb_funcall3(args[0], id_start_document, 3, args + 1);
}
Example #13
0
static VALUE protected_event_location(VALUE pointer)
{
    VALUE *args = (VALUE *)pointer;
    return rb_funcall3(args[0], id_event_location, 4, args + 1);
}
Example #14
0
static VALUE kernel_spec_rb_funcall3(VALUE self, VALUE obj, VALUE method) {
  return rb_funcall3(obj, SYM2ID(method), 0, NULL);
}
Example #15
0
 void RubyOutputStream::close(void)
 {
 	rb_funcall3((VALUE ) rubyIO, rb_intern("close"), 0, NULL);
 }