当前位置: 首页>>代码示例>>C++>>正文


C++ rb_check_string_type函数代码示例

本文整理汇总了C++中rb_check_string_type函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_check_string_type函数的具体用法?C++ rb_check_string_type怎么用?C++ rb_check_string_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rb_check_string_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: search

/**
 * call-seq:
 *   search(*queries, ...) → an_array
 *
 * Search the database with POSIX regular expressions for packages.
 * === Parameters
 * [*queries (splat)]
 *   A list of strings interpreted as POSIX regular expressions.
 *   For a package to be found, it must match _all_ queries terms,
 *   not just a single one. Each query is matched against both
 *   the package name and the package description, where only
 *   one needs to match for the package to be considered.
 *
 *   Note that the match is not performed by Ruby or even Oniguruma/Onigmo,
 *   but directly in libalpm via the +regexp+ library in C.
 *
 * === Return value
 * An array of Package instances whose names matched _all_ regular expressions.
 */
static VALUE search(int argc, VALUE argv[], VALUE self)
{
  alpm_db_t* p_db = NULL;
  alpm_list_t* targets = NULL;
  alpm_list_t* packages = NULL;
  alpm_list_t* item = NULL;
  VALUE result = rb_ary_new();
  int i;

  Data_Get_Struct(self, alpm_db_t, p_db);

  /* Convert our Ruby array to an alpm_list with C strings */
  for(i=0; i < argc; i++) {
    VALUE term = rb_check_string_type(argv[i]);
    if (!RTEST(term)) {
      rb_raise(rb_eTypeError, "Argument is not a string (#to_str)");
      return Qnil;
    }

    targets = alpm_list_add(targets, StringValuePtr(term));
  }

  /* Perform the query */
  packages = alpm_db_search(p_db, targets);
  if (!packages)
    return result;

  for(item=packages; item; item = alpm_list_next(item))
    rb_ary_push(result, Data_Wrap_Struct(rb_cAlpm_Package, NULL, NULL, item->data));

  alpm_list_free(targets);
  return result;
}
开发者ID:Quintus,项目名称:ruby-alpm,代码行数:52,代码来源:database.c

示例2: nst_s_new

/*
  Foo = Numo::Struct.new {
    int8     :byte
    float64  :float, [2,2]
    dcomplex :compl
  }
 */
static VALUE
nst_s_new(int argc, VALUE *argv, VALUE klass)
{
    VALUE name=Qnil, rest, size;
    VALUE st, members;
    ID id;

    rb_scan_args(argc, argv, "0*", &rest);
    if (RARRAY_LEN(rest)>0) {
        name = RARRAY_AREF(rest,0);
        if (!NIL_P(name)) {
            VALUE tmp = rb_check_string_type(name);
            if (!NIL_P(tmp)) {
                rb_ary_shift(rest);
            } else {
                name = Qnil;
            }
        }
    }

    if (NIL_P(name)) {
        st = rb_define_class_id(name, klass);
        rb_funcall(klass, rb_intern("inherited"), 1, st);
    }
    else {
        char *cname = StringValuePtr(name);
        id = rb_intern(cname);
        if (!rb_is_const_id(id)) {
            rb_name_error(id, "identifier %s needs to be constant", cname);
        }
        if (rb_const_defined_at(klass, id)) {
            rb_warn("redefining constant Struct::%s", cname);
            rb_mod_remove_const(klass, ID2SYM(id));
        }
        st = rb_define_class_under(klass, rb_id2name(id), klass);
    }

    rb_iv_set(st, "__members__", rb_ary_new());
    rb_iv_set(st, "__offset__", INT2FIX(0));

    if (rb_block_given_p()) {
        rb_mod_module_eval(0, 0, st);
    }

    size = rb_iv_get(st, "__offset__");
    members = rb_iv_get(st, "__members__");
    //printf("size=%d\n",NUM2INT(size));
    rb_define_const(st, CONTIGUOUS_STRIDE, size);
    rb_define_const(st, ELEMENT_BYTE_SIZE, size);
    rb_define_const(st, ELEMENT_BIT_SIZE,  rb_funcall(size,'*',1,INT2FIX(8)));

    OBJ_FREEZE(members);
    rb_define_const(st, "DEFINITIONS", members);

    rb_define_singleton_method(st, "new", rb_class_new_instance, -1);
    //rb_define_singleton_method(st, "[]", rb_class_new_instance, -1);
    rb_define_method(st, "allocate", nst_allocate, 0);

    return st;
}
开发者ID:metanest,项目名称:narray-devel,代码行数:67,代码来源:struct.c

示例3: format_message

static VALUE
format_message(VALUE exc)
{
    CFMutableStringRef result = CFStringCreateMutable(NULL, 0);
    VALUE message = rb_vm_call(exc, sel_registerName("message"), 0, NULL);
    VALUE bt = rb_vm_call(exc, sel_registerName("backtrace"), 0, NULL);

    message = rb_check_string_type(message);
    const char *msg = message == Qnil ? "" : RSTRING_PTR(message);

    const long count = (bt != Qnil ? RARRAY_LEN(bt) : 0);
    if (count > 0) {
	for (long i = 0; i < count; i++) {
	    const char *bte = RSTRING_PTR(RARRAY_AT(bt, i));
	    if (i == 0) {
		CFStringAppendFormat(result, NULL, CFSTR("%s: %s (%s)\n"),
		    bte, msg, rb_class2name(*(VALUE *)exc));
	    }
	    else {
		CFStringAppendFormat(result, NULL, CFSTR("\tfrom %s\n"), bte);
	    }
	}
    }
    else {
	CFStringAppendFormat(result, NULL, CFSTR("%s (%s)\n"),
	    msg, rb_class2name(*(VALUE *)exc));
    }
    CFMakeCollectable(result);
    return (VALUE)result;
}
开发者ID:1nueve,项目名称:MacRuby,代码行数:30,代码来源:error.c

示例4: rxml_xpath_context_find

/*
 * call-seq:
 *    context.find("xpath") -> true|false|number|string|XML::XPath::Object
 *
 * Executes the provided xpath function.  The result depends on the execution
 * of the xpath statement.  It may be true, false, a number, a string or 
 * a node set.
 */
static VALUE rxml_xpath_context_find(VALUE self, VALUE xpath_expr)
{
  xmlXPathContextPtr xctxt;
  xmlXPathObjectPtr xobject;
  xmlXPathCompExprPtr xcompexpr;

  Data_Get_Struct(self, xmlXPathContext, xctxt);

  if (TYPE(xpath_expr) == T_STRING)
  {
    VALUE expression = rb_check_string_type(xpath_expr);
    xobject = xmlXPathEval((xmlChar*) StringValueCStr(expression), xctxt);
  }
  else if (rb_obj_is_kind_of(xpath_expr, cXMLXPathExpression))
  {
    Data_Get_Struct(xpath_expr, xmlXPathCompExpr, xcompexpr);
    xobject = xmlXPathCompiledEval(xcompexpr, xctxt);
  }
  else
  {
    rb_raise(rb_eTypeError,
        "Argument should be an intance of a String or XPath::Expression");
  }

  return rxml_xpath_to_value(xctxt, xobject);
}
开发者ID:tekwiz,项目名称:libxml-ruby,代码行数:34,代码来源:ruby_xml_xpath_context.c

示例5: rbreg_get

static VALUE rbreg_get(VALUE, VALUE rname) {
    lwc::Registry *reg = lwc::Registry::Instance();
    if (!reg) {
        rb_raise(rb_eRuntimeError, "lwc::Registry has not yet been initialized");
    }
    VALUE sname = rb_check_string_type(rname);
    if (NIL_P(sname)) {
        rb_raise(rb_eTypeError, "RLWC::Registry.get expects a string as argument");
    }
    char *name = RSTRING(sname)->ptr;
    lwc::Object *obj = reg->get(name);
    if (!obj) {
        return Qnil;
    } else {
        VALUE rv = Qnil;
        //if (!strcmp(obj->getLoaderName(), "rbloader")) {
        //  rv = ((Object*)obj)->self();
        //
        //} else {
        rv = rb_funcall2(cLWCObject, rb_intern("new"), 0, NULL);
        SetObjectPointer(rv, obj);
        //}
        return rv;
    }
}
开发者ID:gatgui,项目名称:lwc,代码行数:25,代码来源:registry.cpp

示例6: trap_handler

static sighandler_t
trap_handler(VALUE *cmd, int sig)
{
    sighandler_t func = sighandler;
    VALUE command;

    if (NIL_P(*cmd)) {
	func = SIG_IGN;
    }
    else {
	command = rb_check_string_type(*cmd);
	if (!NIL_P(command)) {
	    SafeStringValue(command);	/* taint check */
	    *cmd = command;
	    switch (RSTRING_LEN(command)) {
	      case 0:
                goto sig_ign;
		break;
              case 14:
		if (strncmp(RSTRING_PTR(command), "SYSTEM_DEFAULT", 14) == 0) {
                    func = SIG_DFL;
                    *cmd = 0;
		}
                break;
	      case 7:
		if (strncmp(RSTRING_PTR(command), "SIG_IGN", 7) == 0) {
sig_ign:
                    func = SIG_IGN;
                    *cmd = 0;
		}
		else if (strncmp(RSTRING_PTR(command), "SIG_DFL", 7) == 0) {
sig_dfl:
                    func = default_handler(sig);
                    *cmd = 0;
		}
		else if (strncmp(RSTRING_PTR(command), "DEFAULT", 7) == 0) {
                    goto sig_dfl;
		}
		break;
	      case 6:
		if (strncmp(RSTRING_PTR(command), "IGNORE", 6) == 0) {
                    goto sig_ign;
		}
		break;
	      case 4:
		if (strncmp(RSTRING_PTR(command), "EXIT", 4) == 0) {
		    *cmd = Qundef;
		}
		break;
	    }
	}
	else {
	    rb_proc_t *proc;
	    GetProcPtr(*cmd, proc);
	}
    }

    return func;
}
开发者ID:professor,项目名称:rhodes,代码行数:59,代码来源:signal.c

示例7: rb_u_string_rindex_m

/* @overload rindex(pattern, offset = -1)
 *
 *   Returns the maximal index of the receiver where PATTERN matches, equal to
 *   or less than _i_, where _i_ = OFFSET if OFFSET ≥ 0, _i_ = {#length} -
 *   abs(OFFSET) otherwise, or nil if there is no match.
 *
 *   If PATTERN is a Regexp, the Regexp special variables `$&`, `$'`,
 *   <code>$\`</code>, `$1`, `$2`, …, `$`_n_ are updated accordingly.
 *
 *   If PATTERN responds to `#to_str`, the matching is performed by a byte
 *   comparison.
 *
 *   @param [Regexp, #to_str] pattern
 *   @param [#to_int] offset
 *   @return [Integer, nil]
 *   @see #index */
VALUE
rb_u_string_rindex_m(int argc, VALUE *argv, VALUE self)
{
        const struct rb_u_string *string = RVAL2USTRING(self);

        VALUE sub, rboffset;
        long offset;
        if (rb_scan_args(argc, argv, "11", &sub, &rboffset) == 2)
                offset = NUM2LONG(rboffset);
        else
                /* TODO: Why not simply use -1?  Benchmark which is faster. */
                offset = u_n_chars_n(USTRING_STR(string), USTRING_LENGTH(string));

        const char *begin = rb_u_string_begin_from_offset(string, offset);
        const char *end = USTRING_END(string);
        if (begin == NULL) {
                if (offset <= 0) {
                        if (TYPE(sub) == T_REGEXP)
                                rb_backref_set(Qnil);

                        return Qnil;
                }

                begin = end;
                /* TODO: this converting back and forward can be optimized away
                 * if rb_u_string_index_regexp() and rb_u_string_rindex() were split up
                 * into two additional functions, adding
                 * rb_u_string_index_regexp_pointer() and rb_u_string_rindex_pointer(),
                 * so that one can pass a pointer to start at immediately
                 * instead of an offset that gets calculated into a pointer. */
                offset = u_n_chars_n(USTRING_STR(string), USTRING_LENGTH(string));
        }

        switch (TYPE(sub)) {
        case T_REGEXP:
                /* TODO: What’s this first test for, exactly? */
                if (RREGEXP(sub)->ptr == NULL || RREGEXP_SRC_LEN(sub) > 0)
                        offset = rb_u_string_index_regexp(self, begin, sub, true);
                break;
        default: {
                VALUE tmp = rb_check_string_type(sub);
                if (NIL_P(tmp))
                        rb_u_raise(rb_eTypeError, "type mismatch: %s given",
                                   rb_obj_classname(sub));

                sub = tmp;
        }
                /* fall through */
        case T_STRING:
                offset = rb_u_string_rindex(self, sub, offset);
                break;
        }

        if (offset < 0)
                return Qnil;

        return LONG2NUM(offset);
}
开发者ID:now,项目名称:u,代码行数:74,代码来源:rb_u_string_rindex.c

示例8: rxml_xpath_context_find

/*
 * call-seq:
 *    context.find("xpath") -> true|false|number|string|XML::XPath::Object
 *
 * Executes the provided xpath function.  The result depends on the execution
 * of the xpath statement.  It may be true, false, a number, a string or 
 * a node set.
 */
static VALUE rxml_xpath_context_find(VALUE self, VALUE xpath_expr)
{
  xmlXPathContextPtr xctxt;
  xmlXPathObjectPtr xobject;
  xmlXPathCompExprPtr xcompexpr;
  VALUE result;

  Data_Get_Struct(self, xmlXPathContext, xctxt);

  if (TYPE(xpath_expr) == T_STRING)
  {
    VALUE expression = rb_check_string_type(xpath_expr);
    xobject = xmlXPathEval((xmlChar*) StringValueCStr(expression), xctxt);
  }
  else if (rb_obj_is_kind_of(xpath_expr, cXMLXPathExpression))
  {
    Data_Get_Struct(xpath_expr, xmlXPathCompExpr, xcompexpr);
    xobject = xmlXPathCompiledEval(xcompexpr, xctxt);
  }
  else
  {
    rb_raise(rb_eTypeError,
        "Argument should be an intance of a String or XPath::Expression");
  }

  if (xobject == NULL)
  {
    /* xmlLastError is different than xctxt->lastError.  Use
     xmlLastError since it has the message set while xctxt->lastError
     does not. */
    xmlErrorPtr xerror = xmlGetLastError();
    rxml_raise(xerror);
  }

  switch (xobject->type)
  {
  case XPATH_NODESET:
    result = rxml_xpath_object_wrap(xctxt->doc, xobject);
    break;
  case XPATH_BOOLEAN:
    result = (xobject->boolval != 0) ? Qtrue : Qfalse;
    xmlXPathFreeObject(xobject);
    break;
  case XPATH_NUMBER:
    result = rb_float_new(xobject->floatval);
    xmlXPathFreeObject(xobject);
    break;
  case XPATH_STRING:
    result = rb_str_new2((const char*)xobject->stringval);
    xmlXPathFreeObject(xobject);
    break;
  default:
    result = Qnil;
    xmlXPathFreeObject(xobject);
  }
  return result;
}
开发者ID:BMorearty,项目名称:Webiva,代码行数:65,代码来源:ruby_xml_xpath_context.c

示例9: rbreg_hasType

static VALUE rbreg_hasType(VALUE, VALUE rname) {
    lwc::Registry *reg = lwc::Registry::Instance();
    if (!reg) {
        rb_raise(rb_eRuntimeError, "lwc::Registry has not yet been initialized");
    }
    VALUE sname = rb_check_string_type(rname);
    if (NIL_P(sname)) {
        rb_raise(rb_eTypeError, "RLWC::Registry.hasType expects a string as argument");
    }
    char *name = RSTRING(sname)->ptr;
    return (reg->hasType(name) ? Qtrue : Qfalse);
}
开发者ID:gatgui,项目名称:lwc,代码行数:12,代码来源:registry.cpp

示例10: rbreg_getDesc

static VALUE rbreg_getDesc(VALUE, VALUE rname) {
    lwc::Registry *reg = lwc::Registry::Instance();
    if (!reg) {
        rb_raise(rb_eRuntimeError, "lwc::Registry has not yet been initialized");
    }
    VALUE sname = rb_check_string_type(rname);
    if (NIL_P(sname)) {
        rb_raise(rb_eTypeError, "RLWC::Registry.getDescription expects a string as argument");
    }
    char *name = RSTRING(sname)->ptr;
    const char *desc = reg->getDescription(name);
    return rb_str_new2(desc ? desc : "");
}
开发者ID:gatgui,项目名称:lwc,代码行数:13,代码来源:registry.cpp

示例11: rbreg_addModulePath

static VALUE rbreg_addModulePath(VALUE self, VALUE rpath) {
    lwc::Registry *reg = lwc::Registry::Instance();
    if (!reg) {
        rb_raise(rb_eRuntimeError, "lwc::Registry has not yet been initialized");
    }
    VALUE spath = rb_check_string_type(rpath);
    if (NIL_P(spath)) {
        rb_raise(rb_eTypeError, "RLWC::Registry.addModulePath expects a string as argument");
    }
    char *path = RSTRING(spath)->ptr;
    reg->addModulePath(path);
    return self;
}
开发者ID:gatgui,项目名称:lwc,代码行数:13,代码来源:registry.cpp

示例12: rbreg_docString

static VALUE rbreg_docString(int argc, VALUE *argv, VALUE) {
    if (argc < 1 || argc > 2) {
        rb_raise(rb_eArgError, "RLWC::Registry.docString accepts 1 or 2 arguments");
    }
    lwc::Registry *reg = lwc::Registry::Instance();
    if (!reg) {
        rb_raise(rb_eRuntimeError, "lwc::Registry has not yet been initialized");
    }
    VALUE sname = rb_check_string_type(argv[0]);
    if (NIL_P(sname)) {
        rb_raise(rb_eTypeError, "RLWC::Registry.docString expects a string as first argument");
    }
    char *name = RSTRING(sname)->ptr;
    std::string indent = "";
    if (argc == 2) {
        VALUE sindent = rb_check_string_type(argv[1]);
        if (NIL_P(sindent)) {
            rb_raise(rb_eTypeError, "RLWC::Registry.docString expects a string as second argument");
        }
        indent = RSTRING(sindent)->ptr;
    }
    return rb_str_new2(reg->docString(name, indent).c_str());
}
开发者ID:gatgui,项目名称:lwc,代码行数:23,代码来源:registry.cpp

示例13: c_medialib_entry_property_set

/*
 * call-seq:
 *  xc.medialib_entry_property_set(id, key, value, *source) -> result
 *
 * Write info to the medialib at _id_. _source_ is an optional argument that
 * describes where to write the mediainfo. If _source_ is omitted, the
 * mediainfo is written to "client/<yourclient>" where <yourclient> is the
 * name you specified in _Xmms::Client.new(name)_.
 */
static VALUE
c_medialib_entry_property_set (int argc, VALUE *argv, VALUE self)
{
	VALUE tmp, key, value, src = Qnil;
	RbXmmsClient *xmms = NULL;
	xmmsc_result_t *res;
	const char *ckey;
	bool is_str = false;
	uint32_t id;
	int32_t ivalue;

	Data_Get_Struct (self, RbXmmsClient, xmms);

	CHECK_DELETED (xmms);

	rb_scan_args (argc, argv, "31", &tmp, &key, &value, &src);

	id = check_int32 (tmp);
	Check_Type (key, T_SYMBOL);

	if (!NIL_P (rb_check_string_type (value)))
		is_str = true;
	else
		ivalue = check_int32 (value);

	ckey = rb_id2name (SYM2ID (key));

	if (NIL_P (src) && is_str)
		res = xmmsc_medialib_entry_property_set_str (xmms->real, id,
		                                             ckey,
		                                             StringValuePtr (value));
	else if (NIL_P (src))
		res = xmmsc_medialib_entry_property_set_int (xmms->real, id,
		                                             ckey, ivalue);
	else if (is_str)
		res = xmmsc_medialib_entry_property_set_str_with_source (
			xmms->real, id,
			StringValuePtr (src),
			ckey,
			StringValuePtr (value));
	else
		res = xmmsc_medialib_entry_property_set_int_with_source (
			xmms->real, id,
			StringValuePtr (src),
			ckey, ivalue);

	return TO_XMMS_CLIENT_RESULT (self, res);
}
开发者ID:dsheeler,项目名称:xmms2,代码行数:57,代码来源:rb_xmmsclient.c

示例14: range_each

static VALUE
range_each(VALUE range, SEL sel)
{
    VALUE beg, end;

    RETURN_ENUMERATOR(range, 0, 0);

    beg = RANGE_BEG(range);
    end = RANGE_END(range);

    if (FIXNUM_P(beg) && FIXNUM_P(end)) { /* fixnums are special */
	long lim = FIX2LONG(end);
	long i;

	if (!EXCL(range))
	    lim += 1;
	for (i = FIX2LONG(beg); i < lim; i++) {
	    rb_yield(LONG2FIX(i));
	    RETURN_IF_BROKEN();
	}
    }
    else if (SYMBOL_P(beg) && SYMBOL_P(end)) { /* symbols are special */
	VALUE args[2];

	args[0] = rb_sym_to_s(end);
	args[1] = EXCL(range) ? Qtrue : Qfalse;
	rb_objc_block_call(rb_sym_to_s(beg), selUpto, 2, args, sym_each_i, 0);
    }
    else {
	VALUE tmp = rb_check_string_type(beg);

	if (!NIL_P(tmp)) {
	    VALUE args[2];

	    args[0] = end;
	    args[1] = EXCL(range) ? Qtrue : Qfalse;
	    rb_objc_block_call(beg, selUpto, 2, args, rb_yield, 0);
	}
	else {
	    if (!discrete_object_p(beg)) {
		rb_raise(rb_eTypeError, "can't iterate from %s",
			 rb_obj_classname(beg));
	    }
	    range_each_func(range, each_i, NULL);
	}
    }
    return range;
}
开发者ID:HumbleRepose,项目名称:MacRuby,代码行数:48,代码来源:range.c

示例15: rb_to_encoding_index

int
rb_to_encoding_index(VALUE enc)
{
    int idx;

    idx = enc_check_encoding(enc);
    if (idx >= 0) {
	return idx;
    }
    else if (NIL_P(enc = rb_check_string_type(enc))) {
	return -1;
    }
    if (!rb_enc_asciicompat(rb_enc_get(enc))) {
	return -1;
    }
    return rb_enc_find_index(StringValueCStr(enc));
}
开发者ID:217,项目名称:ruby,代码行数:17,代码来源:encoding.c


注:本文中的rb_check_string_type函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。