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


C++ rb_enc_name函数代码示例

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


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

示例1: call_ruby

static OCIAnyData *
call_ruby(plruby_context_t *ctx)
{
    VALUE obj;

    trace(ctx, 1, "before encode to ('%s')", rb_enc_name(oracle_encoding));
    obj = rb_enc_str_new(ctx->obj, strlen(ctx->obj), oracle_encoding);
    trace(ctx, 1, "after encode to ('%s')", rb_enc_name(oracle_encoding));

    trace(ctx, 1, "before eval('%s')", ctx->obj);
    obj = rb_funcall(rb_cObject, rb_intern("eval"), 1, obj);
    trace(ctx, 1, "after eval('%s')", ctx->obj);
    if (ctx->meth != NULL) {
        VALUE args[MAX_ARG];
        int idx;

        for (idx = 0; idx < MAX_ARG && ctx->args[idx] != EMPTY; idx++) {
            trace(ctx, 2, "before to_ruby_value(ctx, ctx->args[%d], %d)", idx, idx);
            args[idx] = to_ruby_value(ctx, ctx->argtype[idx], ctx->args[idx], idx);
            trace(ctx, 2, "after to_ruby_value(ctx, ctx->args[%d], %d) => %p", idx, idx, args[idx]);
        }
        trace(ctx, 1, "before calling %s method", ctx->meth);
        obj = rb_funcall2(obj, rb_intern(ctx->meth), idx, args);
        trace(ctx, 1, "after calling %s method", ctx->meth);
    }
    return to_return_value(ctx, obj);
}
开发者ID:kubo,项目名称:plruby-oracle,代码行数:27,代码来源:extproc_ruby.c

示例2: str_compat_and_valid

static VALUE
str_compat_and_valid(VALUE str, rb_encoding *enc)
{
    int cr;
    str = StringValue(str);
    cr = rb_enc_str_coderange(str);
    if (cr == ENC_CODERANGE_BROKEN) {
#ifdef PRIsVALUE
	rb_raise(rb_eArgError, "replacement must be valid byte sequence '%+"PRIsVALUE"'", str);
#else
	str = rb_inspect(str);
	rb_raise(rb_eArgError, "replacement must be valid byte sequence '%s'", RSTRING_PTR(str));
	RB_GC_GUARD(str);
#endif
    }
    else if (cr == ENC_CODERANGE_7BIT) {
	rb_encoding *e = STR_ENC_GET(str);
	if (!rb_enc_asciicompat(enc)) {
	    rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
		    rb_enc_name(enc), rb_enc_name(e));
	}
    }
    else { /* ENC_CODERANGE_VALID */
	rb_encoding *e = STR_ENC_GET(str);
	if (enc != e) {
	    rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
		    rb_enc_name(enc), rb_enc_name(e));
	}
    }
    return str;
}
开发者ID:BukhariH,项目名称:string-scrub,代码行数:31,代码来源:scrub.c

示例3: encoding_spec_rb_enc_set_index

static VALUE encoding_spec_rb_enc_set_index(VALUE self, VALUE obj, VALUE index) {
  int i = NUM2INT(index);

  rb_encoding* enc = rb_enc_from_index(i);
  rb_enc_set_index(obj, i);

  return rb_ary_new3(2, rb_str_new2(rb_enc_name(enc)),
                     rb_str_new2(rb_enc_name(rb_enc_get(obj))));
}
开发者ID:jonsmock,项目名称:rubinius,代码行数:9,代码来源:encoding_spec.c

示例4: rb_enc_check

rb_encoding*
rb_enc_check(VALUE str1, VALUE str2)
{
    rb_encoding *enc = rb_enc_compatible(str1, str2);
    if (!enc)
	rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
		 rb_enc_name(rb_enc_get(str1)),
		 rb_enc_name(rb_enc_get(str2)));
    return enc;
}
开发者ID:217,项目名称:ruby,代码行数:10,代码来源:encoding.c

示例5: rb_enc_check_str

rb_encoding*
rb_enc_check_str(VALUE str1, VALUE str2)
{
    rb_encoding *enc = enc_compatible_str(MUST_STRING(str1), MUST_STRING(str2));
    if (!enc)
	rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
		 rb_enc_name(rb_enc_get(str1)),
		 rb_enc_name(rb_enc_get(str2)));
    return enc;
}
开发者ID:tenderlove,项目名称:ruby,代码行数:10,代码来源:encoding.c

示例6: fenix_coerce_to_path

static VALUE
fenix_coerce_to_path(VALUE obj)
{
	VALUE tmp;
	ID to_path;
	rb_encoding *enc;
	int level = rb_safe_level();

	if (insecure_obj_p(obj, level)) {
		rb_insecure_operation();
	}

	CONST_ID(to_path, "to_path");
	tmp = rb_check_funcall(obj, to_path, 0, 0);
	if (tmp == Qundef)
		tmp = obj;

	StringValue(tmp);

	tmp = file_path_convert(tmp);
	if (obj != tmp && insecure_obj_p(tmp, level)) {
		rb_insecure_operation();
	}
	enc = rb_enc_get(tmp);
	if (!rb_enc_asciicompat(enc)) {
		tmp = rb_str_inspect(tmp);
		rb_raise(rb_eEncCompatError, "path name must be ASCII-compatible (%s): %s",
			 rb_enc_name(enc), RSTRING_PTR(tmp));
	}
	return rb_str_new4(tmp);
}
开发者ID:shirosaki,项目名称:fenix,代码行数:31,代码来源:file.c

示例7: rb_enc_vsprintf

VALUE
rb_enc_vsprintf(rb_encoding *enc, const char *fmt, va_list ap)
{
    rb_printf_buffer_extra buffer;
#define f buffer.base
    VALUE result;

    f._flags = __SWR | __SSTR;
    f._bf._size = 0;
    f._w = 120;
    result = rb_str_buf_new(f._w);
    if (enc) {
	if (rb_enc_mbminlen(enc) > 1) {
	    /* the implementation deeply depends on plain char */
	    rb_raise(rb_eArgError, "cannot construct wchar_t based encoding string: %s",
		     rb_enc_name(enc));
	}
	rb_enc_associate(result, enc);
    }
    f._bf._base = (unsigned char *)result;
    f._p = (unsigned char *)RSTRING_PTR(result);
    RBASIC_CLEAR_CLASS(result);
    f.vwrite = ruby__sfvwrite;
    f.vextra = ruby__sfvextra;
    buffer.value = 0;
    BSD_vfprintf(&f, fmt, ap);
    RBASIC_SET_CLASS_RAW(result, rb_cString);
    rb_str_resize(result, (char *)f._p - RSTRING_PTR(result));
#undef f

    return result;
}
开发者ID:DashYang,项目名称:sim,代码行数:32,代码来源:sprintf.c

示例8: setup_plruby_oracle

static VALUE setup_plruby_oracle(plruby_context_t *ctx)
{
    ub2 id;
    char name[OCI_NLS_MAXBUFSZ];
    VALUE mPLRubyOracle;
    VALUE enc;

    chk(OCIAttrGet(ctx->envhp, OCI_HTYPE_ENV, &id, NULL, OCI_ATTR_ENV_CHARSET_ID, ctx->errhp));
    OCINlsCharSetIdToName(ctx->envhp, (text*)name, sizeof(name), id);

    trace(ctx, 1, "before requre 'plruby_oracle'");
    rb_require("plruby_oracle");

    trace(ctx, 1, "before eval('PLRubyOracle')");
    mPLRubyOracle = rb_eval_string("PLRubyOracle");
    trace(ctx, 2, "rb_eval_string(\"PLRubyOracle\") => %p", mPLRubyOracle);

    trace(ctx, 1, "before PLRubyOracle.init('%s')", name);
    rb_funcall(mPLRubyOracle, rb_intern("init"), 1, rb_usascii_str_new2(name));

    enc = rb_cv_get(mPLRubyOracle, "@@encoding");
    trace(ctx, 2, "rb_cv_get(mPLRubyOracle, \"@@encoding\") => %s", StringValueCStr(enc));
    oracle_encoding = rb_to_encoding(enc);
    trace(ctx, 2, "rb_enc_get(enc) => %s", rb_enc_name(oracle_encoding));
    return Qnil;
}
开发者ID:kubo,项目名称:plruby-oracle,代码行数:26,代码来源:extproc_ruby.c

示例9: mochilo_pack_str

void mochilo_pack_str(mochilo_buf *buf, VALUE rb_str)
{
	long size = RSTRING_LEN(rb_str);
	rb_encoding *encoding;

	const struct mochilo_enc_map *enc2id;
	const char *enc_name;

	if (size < 0x10000) {
		uint16_t lead = size;
		mochilo_buf_putc(buf, MSGPACK_T_STR16);
		mochilo_buf_put16be(buf, &lead);
	}

	else {
		mochilo_buf_putc(buf, MSGPACK_T_STR32);
		mochilo_buf_put32be(buf, &size);
	}

	encoding = rb_enc_get(rb_str);
	enc_name = rb_enc_name(encoding);
	enc2id = mochilo_encoding_to_id(enc_name, (unsigned int)strlen(enc_name));

	mochilo_buf_putc(buf, enc2id ? enc2id->id : 0);
	mochilo_buf_put(buf, RSTRING_PTR(rb_str), size);
}
开发者ID:adelcambre,项目名称:mochilo,代码行数:26,代码来源:mochilo_pack.c

示例10: code_page

/*
  Return code page number of the encoding.
  Cache code page into a hash for performance since finding the code page in
  Encoding#names is slow.
*/
static UINT
code_page(rb_encoding *enc)
{
    VALUE code_page_value, name_key;
    VALUE encoding, names_ary = Qundef, name;
    char *enc_name;
    struct RString fake_str;
    ID names;
    long i;

    if (!enc)
	return system_code_page();

    enc_name = (char *)rb_enc_name(enc);

    fake_str.basic.flags = T_STRING|RSTRING_NOEMBED;
    fake_str.basic.klass = rb_cString;
    fake_str.as.heap.len = strlen(enc_name);
    fake_str.as.heap.ptr = enc_name;
    fake_str.as.heap.aux.capa = fake_str.as.heap.len;
    name_key = (VALUE)&fake_str;
    ENCODING_CODERANGE_SET(name_key, rb_usascii_encindex(), ENC_CODERANGE_7BIT);

    code_page_value = rb_hash_lookup(rb_code_page, name_key);
    if (code_page_value != Qnil)
	return (UINT)FIX2INT(code_page_value);

    name_key = rb_usascii_str_new2(enc_name);

    encoding = rb_enc_from_encoding(enc);
    if (!NIL_P(encoding)) {
	CONST_ID(names, "names");
	names_ary = rb_funcall(encoding, names, 0);
    }

    /* map US-ASCII and ASCII-8bit as code page 1252 (us-ascii) */
    if (enc == rb_usascii_encoding() || enc == rb_ascii8bit_encoding()) {
	UINT code_page = 1252;
	rb_hash_aset(rb_code_page, name_key, INT2FIX(code_page));
	return code_page;
    }

    if (names_ary != Qundef) {
	for (i = 0; i < RARRAY_LEN(names_ary); i++) {
	    name = RARRAY_PTR(names_ary)[i];
	    if (strncmp("CP", RSTRING_PTR(name), 2) == 0) {
		int code_page = atoi(RSTRING_PTR(name) + 2);
		if (code_page != 0) {
		    rb_hash_aset(rb_code_page, name_key, INT2FIX(code_page));
		    return (UINT)code_page;
		}
	    }
	}
    }

    rb_hash_aset(rb_code_page, name_key, INT2FIX(INVALID_CODE_PAGE));
    return INVALID_CODE_PAGE;
}
开发者ID:MercerHall,项目名称:editorial,代码行数:63,代码来源:file.c

示例11: must_encindex

static rb_encoding *
must_encindex(int index)
{
    rb_encoding *enc = rb_enc_from_index(index);
    if (!enc) {
	rb_raise(rb_eEncodingError, "encoding index out of bound: %d",
		 index);
    }
    if (ENC_TO_ENCINDEX(enc) != (int)(index & ENC_INDEX_MASK)) {
	rb_raise(rb_eEncodingError, "wrong encoding index %d for %s (expected %d)",
		 index, rb_enc_name(enc), ENC_TO_ENCINDEX(enc));
    }
    if (enc_autoload_p(enc) && enc_autoload(enc) == -1) {
	rb_loaderror("failed to load encoding (%s)",
		     rb_enc_name(enc));
    }
    return enc;
}
开发者ID:ksperling,项目名称:ruby,代码行数:18,代码来源:encoding.c

示例12: mochilo_pack_str

void mochilo_pack_str(mochilo_buf *buf, VALUE rb_str)
{
	long size = RSTRING_LEN(rb_str);
	rb_encoding *encoding;

	const struct mochilo_enc_map *enc2id;
	const char *enc_name;

	encoding = rb_enc_get(rb_str);
	enc_name = rb_enc_name(encoding);

	if (encoding == rb_utf8_encoding()) {
		// use str type from msgpack spec
		if (size < 0x20) {
			uint8_t lead = 0xa0 | size;
			mochilo_buf_putc(buf, lead);
		} else if (size < 0x100) {
			uint8_t lead = size;
			mochilo_buf_putc(buf, MSGPACK_T_STR8);
			mochilo_buf_putc(buf, lead);
		} else if (size < 0x10000) {
			uint16_t lead = size;
			mochilo_buf_putc(buf, MSGPACK_T_STR16);
			mochilo_buf_put16be(buf, &lead);
		} else if (size < 0x100000000) {
			mochilo_buf_putc(buf, MSGPACK_T_STR32);
			mochilo_buf_put32be(buf, &size);
		} else {
			// there is no str 64
			rb_raise(rb_eMochiloPackError,
				"String cannot be larger than %ld bytes", 0x100000000);
		}
	} else {
		// if another encoding is used we need to use our custom types
		if (size < 0x100) {
			uint8_t lead = size;
			mochilo_buf_putc(buf, MSGPACK_T_ENC8);
			mochilo_buf_putc(buf, lead);
		} else if (size < 0x10000) {
			uint16_t lead = size;
			mochilo_buf_putc(buf, MSGPACK_T_ENC16);
			mochilo_buf_put16be(buf, &lead);
		} else if (size < 0x100000000) {
			mochilo_buf_putc(buf, MSGPACK_T_ENC32);
			mochilo_buf_put32be(buf, &size);
		} else {
			// there is no ext 64
			rb_raise(rb_eMochiloPackError,
				"String cannot be larger than %ld bytes", 0x100000000);
		}

		enc2id = mochilo_encoding_to_id(enc_name, (unsigned int)strlen(enc_name));
		mochilo_buf_putc(buf, enc2id ? enc2id->id : 0);
	}

	mochilo_buf_put(buf, RSTRING_PTR(rb_str), size);
}
开发者ID:bkeepers,项目名称:mochilo,代码行数:57,代码来源:mochilo_pack.c

示例13: rb_enc_codelen

int
rb_enc_codelen(int c, rb_encoding *enc)
{
    int n = ONIGENC_CODE_TO_MBCLEN(enc,c);
    if (n == 0) {
	rb_raise(rb_eArgError, "invalid codepoint 0x%x in %s", c, rb_enc_name(enc));
    }
    return n;
}
开发者ID:217,项目名称:ruby,代码行数:9,代码来源:encoding.c

示例14: enc_inspect

/*
 * call-seq:
 *   enc.inspect -> string
 *
 * Returns a string which represents the encoding for programmers.
 *
 *   Encoding::UTF_8.inspect       #=> "#<Encoding:UTF-8>"
 *   Encoding::ISO_2022_JP.inspect #=> "#<Encoding:ISO-2022-JP (dummy)>"
 */
static VALUE
enc_inspect(VALUE self)
{
    VALUE str = rb_sprintf("#<%s:%s%s>", rb_obj_classname(self),
		      rb_enc_name((rb_encoding*)DATA_PTR(self)),
		      (enc_dummy_p(self) ? " (dummy)" : ""));
    ENCODING_CODERANGE_SET(str, rb_usascii_encindex(), ENC_CODERANGE_7BIT);
    return str;
}
开发者ID:217,项目名称:ruby,代码行数:18,代码来源:encoding.c

示例15: fenix_code_page

/*
  Return code page number of the encoding.
  Cache code page into a hash for performance since finding the code page in
  Encoding#names is slow.
*/
static UINT
fenix_code_page(rb_encoding *enc)
{
	VALUE code_page_value, name_key;
	VALUE encoding, names_ary = Qundef, name;
	char *enc_name;
	struct RString fake_str;
	ID names;
	long i;

	if (!enc)
		return system_code_page();

	enc_name = (char *)rb_enc_name(enc);

	fake_str.basic.flags = T_STRING|RSTRING_NOEMBED;
	fake_str.basic.klass = rb_cString;
	fake_str.as.heap.len = strlen(enc_name);
	fake_str.as.heap.ptr = enc_name;
	fake_str.as.heap.aux.capa = fake_str.as.heap.len;
	name_key = (VALUE)&fake_str;
	ENCODING_CODERANGE_SET(name_key, rb_usascii_encindex(), ENC_CODERANGE_7BIT);
	OBJ_FREEZE(name_key);

	code_page_value = rb_hash_lookup(rb_code_page, name_key);
	if (code_page_value != Qnil) {
		// printf("cached code page: %i\n", FIX2INT(code_page_value));
		if (FIX2INT(code_page_value) == -1) {
			return system_code_page();
		} else {
			return (UINT)FIX2INT(code_page_value);
		}
	}

	name_key = rb_usascii_str_new2(enc_name);

	encoding = rb_enc_from_encoding(enc);
	if (!NIL_P(encoding)) {
		CONST_ID(names, "names");
		names_ary = rb_funcall(encoding, names, 0);
	}

	if (names_ary != Qundef) {
		for (i = 0; i < RARRAY_LEN(names_ary); i++) {
			name = RARRAY_PTR(names_ary)[i];
			if (strncmp("CP", RSTRING_PTR(name), 2) == 0) {
				int code_page = atoi(RSTRING_PTR(name) + 2);
				rb_hash_aset(rb_code_page, name_key, INT2FIX(code_page));
				return (UINT)code_page;
			}
		}
	}

	rb_hash_aset(rb_code_page, name_key, INT2FIX(-1));
	return system_code_page();
}
开发者ID:shirosaki,项目名称:fenix,代码行数:61,代码来源:file.c


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