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


C++ rb_enc_from_encoding函数代码示例

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


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


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