• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ rb_enc_from_encoding函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Init_nkf

void
Init_nkf()
{
    VALUE mNKF = rb_define_module("NKF");

    rb_define_module_function(mNKF, "nkf", rb_nkf_convert, 2);
    rb_define_module_function(mNKF, "guess", rb_nkf_guess, 1);
    rb_define_alias(rb_singleton_class(mNKF), "guess", "guess");

    rb_define_const(mNKF, "AUTO",	Qnil);
    rb_define_const(mNKF, "NOCONV",	Qnil);
    rb_define_const(mNKF, "UNKNOWN",	Qnil);
    rb_define_const(mNKF, "BINARY",	rb_enc_from_encoding(rb_nkf_enc_get("BINARY")));
    rb_define_const(mNKF, "ASCII",	rb_enc_from_encoding(rb_nkf_enc_get("US-ASCII")));
    rb_define_const(mNKF, "JIS",	rb_enc_from_encoding(rb_nkf_enc_get("ISO-2022-JP")));
    rb_define_const(mNKF, "EUC",	rb_enc_from_encoding(rb_nkf_enc_get("EUC-JP")));
    rb_define_const(mNKF, "SJIS",	rb_enc_from_encoding(rb_nkf_enc_get("Shift_JIS")));
    rb_define_const(mNKF, "UTF8",	rb_enc_from_encoding(rb_utf8_encoding()));
    rb_define_const(mNKF, "UTF16",	rb_enc_from_encoding(rb_nkf_enc_get("UTF-16BE")));
    rb_define_const(mNKF, "UTF32",	rb_enc_from_encoding(rb_nkf_enc_get("UTF-32BE")));

    /* Full version string of nkf */
    rb_define_const(mNKF, "VERSION", rb_str_new2(RUBY_NKF_VERSION));
    /* Version of nkf */
    rb_define_const(mNKF, "NKF_VERSION", rb_str_new2(NKF_VERSION));
    /* Release date of nkf */
    rb_define_const(mNKF, "NKF_RELEASE_DATE", rb_str_new2(NKF_RELEASE_DATE));
}
开发者ID:alloy,项目名称:mr-experimental,代码行数:28,代码来源:nkf.c


示例2: registerEnc

void registerEnc(wxFontEncoding enc,const char* name)
{
	rb_encoding *rb_enc = rb_enc_find(name);

	if(rb_enc)
		encodingholder[enc]=rb_enc_from_encoding(rb_enc);
}
开发者ID:Hanmac,项目名称:rwx,代码行数:7,代码来源:wxFont.cpp


示例3: get_user_from_path

static inline VALUE
get_user_from_path(wchar_t **wpath, int offset, UINT cp, UINT path_cp, rb_encoding *path_encoding)
{
    VALUE result, tmp;
    wchar_t *wuser = *wpath + offset;
    wchar_t *pos = wuser;
    char *user;
    size_t size;

    while (!IS_DIR_SEPARATOR_P(*pos) && *pos != '\0')
     pos++;

    *pos = '\0';
    convert_wchar_to_mb(wuser, &user, &size, cp);

    /* convert to VALUE and set the path encoding */
    if (path_cp == INVALID_CODE_PAGE) {
	tmp = rb_enc_str_new(user, size, rb_utf8_encoding());
	result = rb_str_encode(tmp, rb_enc_from_encoding(path_encoding), 0, Qnil);
	rb_str_resize(tmp, 0);
    }
    else {
	result = rb_enc_str_new(user, size, path_encoding);
    }

    if (user)
	xfree(user);

    return result;
}
开发者ID:MercerHall,项目名称:editorial,代码行数:30,代码来源:file.c


示例4: set_charset_name

static VALUE set_charset_name(VALUE self, VALUE value) {
  char *charset_name;
#ifdef HAVE_RUBY_ENCODING_H
  const struct mysql2_mysql_enc_name_to_rb_map *mysql2rb;
  rb_encoding *enc;
  VALUE rb_enc;
#endif
  GET_CLIENT(self);

  charset_name = RSTRING_PTR(value);

#ifdef HAVE_RUBY_ENCODING_H
  mysql2rb = mysql2_mysql_enc_name_to_rb(charset_name, (unsigned int)RSTRING_LEN(value));
  if (mysql2rb == NULL || mysql2rb->rb_name == NULL) {
    VALUE inspect = rb_inspect(value);
    rb_raise(cMysql2Error, "Unsupported charset: '%s'", RSTRING_PTR(inspect));
  } else {
    enc = rb_enc_find(mysql2rb->rb_name);
    rb_enc = rb_enc_from_encoding(enc);
    wrapper->encoding = rb_enc;
  }
#endif

  if (mysql_options(wrapper->client, MYSQL_SET_CHARSET_NAME, charset_name)) {
    /* TODO: warning - unable to set charset */
    rb_warn("%s\n", mysql_error(wrapper->client));
  }

  return value;
}
开发者ID:jaylane,项目名称:mysql2,代码行数:30,代码来源:client.c


示例5: encoding_spec_rb_enc_compatible

static VALUE encoding_spec_rb_enc_compatible(VALUE self, VALUE a, VALUE b) {
  rb_encoding* enc = rb_enc_compatible(a, b);

  if(!enc) return INT2FIX(0);

  return rb_enc_from_encoding(enc);
}
开发者ID:DanielVartanov,项目名称:rubinius,代码行数:7,代码来源:encoding_spec.c


示例6: eruta_ruby_init

int eruta_ruby_init() {
  VALUE options = Qnil, sublet = Qnil;

  void Init_prelude(void);

  RUBY_INIT_STACK;
  ruby_init();
  ruby_init_loadpath();
  ruby_script("eruta");

#ifdef HAVE_RB_ENC_SET_DEFAULT_INTERNAL
  {
    VALUE encoding = Qnil;

    /* FIXME: Fix for ruby 1.9.2p429 borrowed from ruby? */
    (void)rb_filesystem_encoding();

    /* Set encoding */
    encoding = rb_enc_from_encoding(rb_locale_encoding());
    rb_enc_set_default_external(encoding);
  }
#endif /* HAVE_RB_ENC_SET_DEFAULT_INTERNAL */

  /* FIXME: Fake ruby_init_gems(Qtrue) */
  rb_define_module("Gem");
  Init_prelude();
  
  
  /* Bypassing garbage collection. Why? */
  /* shelter = rb_ary_new();
  rb_gc_register_address(&shelter);
  */
  
}
开发者ID:beoran,项目名称:eruta,代码行数:34,代码来源:eruta.c


示例7: rb_tinytds_encoding

static VALUE rb_tinytds_encoding(VALUE self) {
    GET_CLIENT_WRAPPER(self);
#ifdef HAVE_RUBY_ENCODING_H
    return rb_enc_from_encoding(cwrap->encoding);
#else
    return Qnil;
#endif
}
开发者ID:filipeamoreira,项目名称:tiny_tds,代码行数:8,代码来源:client.c


示例8: 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


示例9: mriBindingExecute

static void mriBindingExecute()
{
	/* Normally only a ruby executable would do a sysinit,
	 * but not doing it will lead to crashes due to closed
	 * stdio streams on some platforms (eg. Windows) */
	int argc = 0;
	char **argv = 0;
	ruby_sysinit(&argc, &argv);

	ruby_setup();
	rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding()));

	Config &conf = shState->rtData().config;

	if (!conf.rubyLoadpaths.empty())
	{
		/* Setup custom load paths */
		VALUE lpaths = rb_gv_get(":");

		for (size_t i = 0; i < conf.rubyLoadpaths.size(); ++i)
		{
			std::string &path = conf.rubyLoadpaths[i];

			VALUE pathv = rb_str_new(path.c_str(), path.size());
			rb_ary_push(lpaths, pathv);
		}
	}

	RbData rbData;
	shState->setBindingData(&rbData);
	BacktraceData btData;

	mriBindingInit();


	STEAMSHIM_init();
	_rb_define_module_function(rb_mKernel, "_steam_achievement_unlock",
	                           _steamAchievementUnlock);


	std::string &customScript = conf.customScript;
	if (!customScript.empty())
		runCustomScript(customScript);
	else
		runRMXPScripts(btData);

	VALUE exc = rb_errinfo();
	if (!NIL_P(exc) && !rb_obj_is_kind_of(exc, rb_eSystemExit))
		showExc(exc, btData);

	ruby_cleanup(0);


	STEAMSHIM_deinit();


	shState->rtData().rqTermAck.set();
}
开发者ID:Ancurio,项目名称:mkxp-abs,代码行数:58,代码来源:binding-mri.cpp


示例10: rb_obj_encoding

VALUE
rb_obj_encoding(VALUE obj)
{
    rb_encoding *enc = rb_enc_get(obj);
    if (!enc) {
	rb_raise(rb_eTypeError, "unknown encoding");
    }
    return rb_enc_from_encoding(enc);
}
开发者ID:217,项目名称:ruby,代码行数:9,代码来源:encoding.c


示例11: dir_enc_str

static VALUE
dir_enc_str(VALUE str, struct dir_data *dirp)
{
    rb_enc_associate(str, dirp->extenc);
    if (dirp->intenc) {
        str = rb_str_transcode(str, rb_enc_from_encoding(dirp->intenc));
    }
    return str;
}
开发者ID:tflynn,项目名称:ruby19-norubygems,代码行数:9,代码来源:dir.c


示例12: 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


示例13: fix_string_encoding

static inline VALUE
fix_string_encoding(VALUE str, rb_encoding *encoding)
{
    VALUE result, tmp;

    tmp = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), encoding);
    result = rb_str_encode(tmp, rb_enc_from_encoding(rb_utf8_encoding()), 0, Qnil);

    return result;
}
开发者ID:MercerHall,项目名称:editorial,代码行数:10,代码来源:file.c


示例14: enc_cb

static int enc_cb(void * _self, int UNUSED(columns), char **data, char **UNUSED(names))
{
  VALUE self = (VALUE)_self;

  int index = rb_enc_find_index(data[0]);
  rb_encoding * e = rb_enc_from_index(index);
  rb_iv_set(self, "@encoding", rb_enc_from_encoding(e));

  return 0;
}
开发者ID:kashif,项目名称:sqlite3-ruby,代码行数:10,代码来源:database.c


示例15: enc_compatible_p

/*
 * call-seq:
 *   Encoding.compatible?(str1, str2) -> enc or nil
 *
 * Checks the compatibility of two strings.
 * If they are compatible, means concatenatable,
 * returns an encoding which the concatenated string will be.
 * If they are not compatible, nil is returned.
 *
 *   Encoding.compatible?("\xa1".force_encoding("iso-8859-1"), "b")
 *   #=> #<Encoding:ISO-8859-1>
 *
 *   Encoding.compatible?(
 *     "\xa1".force_encoding("iso-8859-1"),
 *     "\xa1\xa1".force_encoding("euc-jp"))
 *   #=> nil
 *
 */
static VALUE
enc_compatible_p(VALUE klass, VALUE str1, VALUE str2)
{
    rb_encoding *enc;

    if (!enc_capable(str1)) return Qnil;
    if (!enc_capable(str2)) return Qnil;
    enc = rb_enc_compatible(str1, str2);
    if (!enc) return Qnil;
    return rb_enc_from_encoding(enc);
}
开发者ID:217,项目名称:ruby,代码行数:29,代码来源:encoding.c


示例16: rxml_document_rb_encoding_get

static VALUE rxml_document_rb_encoding_get(VALUE self)
{
  xmlDocPtr xdoc;
  const char *xencoding;
  rb_encoding* rbencoding;
  Data_Get_Struct(self, xmlDoc, xdoc);

  xencoding = (const char*)xdoc->encoding;
  rbencoding = rxml_xml_encoding_to_rb_encoding(mXMLEncoding, xmlParseCharEncoding(xencoding));
  return rb_enc_from_encoding(rbencoding);
}
开发者ID:CITguy,项目名称:libxml-ruby,代码行数:11,代码来源:ruby_xml_document.c


示例17: pg_tmir_copy_get

static VALUE
pg_tmir_copy_get( t_typemap *p_typemap, VALUE field_str, int fieldno, int format, int enc_idx )
{
	t_tmir *this = (t_tmir *) p_typemap;
	rb_encoding *p_encoding = rb_enc_from_index(enc_idx);
	VALUE enc = rb_enc_from_encoding(p_encoding);
	/* field_str is reused in-place by pg_text_dec_copy_row(), so we need to make
	 * a copy of the string buffer for use in ruby space. */
	VALUE field_str_copy = rb_str_dup(field_str);
	rb_str_modify(field_str_copy);

	return rb_funcall( this->self, s_id_typecast_copy_get, 4, field_str_copy, INT2NUM(fieldno), INT2NUM(format), enc );
}
开发者ID:13l1236,项目名称:rails-app-for-lesson,代码行数:13,代码来源:pg_type_map_in_ruby.c


示例18: rb_grn_context_rb_string_encode

VALUE
rb_grn_context_rb_string_encode (grn_ctx *context, VALUE rb_string)
{
#ifdef HAVE_RUBY_ENCODING_H
    rb_encoding *encoding, *to_encode;

    encoding = rb_enc_get(rb_string);
    to_encode = rb_grn_encoding_to_ruby_encoding(context->encoding);
    if (rb_enc_to_index(encoding) != rb_enc_to_index(to_encode))
	rb_string = rb_str_encode(rb_string, rb_enc_from_encoding(to_encode),
				  0, Qnil);
#endif
    return rb_string;
}
开发者ID:nobu,项目名称:rroonga,代码行数:14,代码来源:rb-grn-context.c


示例19: set_encoding_const

static void
set_encoding_const(const char *name, rb_encoding *enc)
{
    VALUE encoding = rb_enc_from_encoding(enc);
    char *s = (char *)name;
    int haslower = 0, hasupper = 0, valid = 0;

    if (ISDIGIT(*s)) return;
    if (ISUPPER(*s)) {
	hasupper = 1;
	while (*++s && (ISALNUM(*s) || *s == '_')) {
	    if (ISLOWER(*s)) haslower = 1;
	}
    }
    if (!*s) {
	if (s - name > ENCODING_NAMELEN_MAX) return;
	valid = 1;
	rb_define_const(rb_cEncoding, name, encoding);
    }
    if (!valid || haslower) {
	size_t len = s - name;
	if (len > ENCODING_NAMELEN_MAX) return;
	if (!haslower || !hasupper) {
	    do {
		if (ISLOWER(*s)) haslower = 1;
		if (ISUPPER(*s)) hasupper = 1;
	    } while (*++s && (!haslower || !hasupper));
	    len = s - name;
	}
	len += strlen(s);
	if (len++ > ENCODING_NAMELEN_MAX) return;
	MEMCPY(s = ALLOCA_N(char, len), name, char, len);
	name = s;
	if (!valid) {
	    if (ISLOWER(*s)) *s = ONIGENC_ASCII_CODE_TO_UPPER_CASE((int)*s);
	    for (; *s; ++s) {
		if (!ISALNUM(*s)) *s = '_';
	    }
	    if (hasupper) {
		rb_define_const(rb_cEncoding, name, encoding);
	    }
	}
	if (haslower) {
	    for (s = (char *)name; *s; ++s) {
		if (ISLOWER(*s)) *s = ONIGENC_ASCII_CODE_TO_UPPER_CASE((int)*s);
	    }
	    rb_define_const(rb_cEncoding, name, encoding);
	}
    }
开发者ID:217,项目名称:ruby,代码行数:49,代码来源:encoding.c


示例20: Init_msgpack

/**
 * Document-module: MessagePack
 *
 * MessagePack is a binary-based efficient object serialization library.
 * It enables to exchange structured objects between many languages like JSON.
 * But unlike JSON, it is very fast and small.
 *
 * You can install MessagePack with rubygems.
 *
 *   gem install msgpack
 *
 * Simple usage is as follows:
 *
 *   require 'msgpack'
 *   msg = [1,2,3].to_msgpack  #=> "\x93\x01\x02\x03"
 *   MessagePack.unpack(msg)   #=> [1,2,3]
 *
 * Use Unpacker class for streaming deserialization.
 *
 */
void Init_msgpack(void)
{
	mMessagePack = rb_define_module("MessagePack");

	rb_define_const(mMessagePack, "VERSION", rb_str_new2(MESSAGEPACK_VERSION));

#ifdef COMPAT_HAVE_ENCODING
	s_enc_ascii8bit = rb_ascii8bit_encindex();
	s_enc_utf8 = rb_utf8_encindex();
	s_enc_usascii = rb_usascii_encindex();
	s_enc_utf8_value = rb_enc_from_encoding(rb_utf8_encoding());
#endif

	Init_msgpack_unpack(mMessagePack);
	Init_msgpack_pack(mMessagePack);
}
开发者ID:127lh,项目名称:metasploit-framework,代码行数:36,代码来源:rbinit.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ rb_enc_name函数代码示例发布时间:2022-05-30
下一篇:
C++ rb_enc_find_index函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap