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


C++ rb_enc_find_index函数代码示例

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


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

示例1: transcode_string

static VALUE transcode_string(VALUE src, int * parser_encoding)
{
    int utf8    = rb_utf8_encindex();
    int utf16le = rb_enc_find_index("UTF16_LE");
    int utf16be = rb_enc_find_index("UTF16_BE");
    int source_encoding = rb_enc_get_index(src);

    if (source_encoding == utf8) {
	*parser_encoding = YAML_UTF8_ENCODING;
	return src;
    }

    if (source_encoding == utf16le) {
	*parser_encoding = YAML_UTF16LE_ENCODING;
	return src;
    }

    if (source_encoding == utf16be) {
	*parser_encoding = YAML_UTF16BE_ENCODING;
	return src;
    }

    src = rb_str_export_to_enc(src, rb_utf8_encoding());
    RB_GC_GUARD(src);

    *parser_encoding = YAML_UTF8_ENCODING;
    return src;
}
开发者ID:eregon,项目名称:psych,代码行数:28,代码来源:parser.c

示例2: rb_nkf_enc_get

rb_encoding* rb_nkf_enc_get(const char *name)
{
#if 0
    int idx = rb_enc_find_index(name);
    if (idx < 0) {
	nkf_encoding *nkf_enc = nkf_enc_find(name);
	idx = rb_enc_find_index(nkf_enc_name(nkf_enc_to_base_encoding(nkf_enc)));
	if (idx < 0) {
	    idx = rb_define_dummy_encoding(name);
	} else {
	    rb_encoding *rb_enc = rb_enc_from_index(idx);
	    idx = rb_enc_replicate(name, rb_enc);
	}
    }
    return rb_enc_from_index(idx);
#else
	struct nkf_osx_name_enc_table { 
	  const char*      name; 
	  CFStringEncoding enc;
	};

	static struct nkf_osx_name_enc_table table[] = {
	  { "BINARY",      kCFStringEncodingNonLossyASCII },
	  { "US-ASCII",    kCFStringEncodingASCII  	},
	  { "ISO-2022-JP", kCFStringEncodingISO_2022_JP  	},
	  { "ISO-2022-JP-1", kCFStringEncodingISO_2022_JP_1  	},
	  { "ISO-2022-JP-2", kCFStringEncodingISO_2022_JP_2  	},
	  { "ISO-2022-JP-3", kCFStringEncodingISO_2022_JP_3  	},
	  { "EUC-JP",      kCFStringEncodingEUC_JP },
	  { "Shift_JIS",   kCFStringEncodingShiftJIS 	},
	  { "UTF-8",       kCFStringEncodingUTF8   	},
	  { "UTF-16",      kCFStringEncodingUTF16   },
	  { "UTF-16BE",    kCFStringEncodingUTF16BE },
	  { "UTF-16LE",    kCFStringEncodingUTF16LE },
	  { "UTF-32",      kCFStringEncodingUTF32   },
	  { "UTF-32BE",    kCFStringEncodingUTF32BE },
	  { "UTF-32LE",    kCFStringEncodingUTF32LE },
	  { NULL,          kCFStringEncodingNonLossyASCII }
	};

	struct nkf_osx_name_enc_table* ptr = table;
	while (ptr->name) {
	  if (strcmp(name, ptr->name) == 0)
		return &(ptr->enc);
	  ptr++;
	}
	return &(ptr->enc);
#endif
}
开发者ID:Sophrinix,项目名称:iphone-macruby,代码行数:49,代码来源:nkf.c

示例3: rb_nkf_enc_get

rb_encoding* rb_nkf_enc_get(const char *name)
{
    int idx = rb_enc_find_index(name);
    if (idx < 0) {
	nkf_encoding *nkf_enc = nkf_enc_find(name);
	idx = rb_enc_find_index(nkf_enc_name(nkf_enc_to_base_encoding(nkf_enc)));
	if (idx < 0) {
	    idx = rb_define_dummy_encoding(name);
	} else {
	    rb_encoding *rb_enc = rb_enc_from_index(idx);
	    idx = rb_enc_replicate(name, rb_enc);
	}
    }
    return rb_enc_from_index(idx);
}
开发者ID:alloy,项目名称:mr-experimental,代码行数:15,代码来源:nkf.c

示例4: do_sqlite3_cConnection_initialize

VALUE do_sqlite3_cConnection_initialize(VALUE self, VALUE uri) {
  VALUE path = rb_funcall(uri, rb_intern("path"), 0);
  sqlite3 *db = NULL;
  int ret;

#ifdef HAVE_SQLITE3_OPEN_V2
  ret = sqlite3_open_v2(StringValuePtr(path), &db, do_sqlite3_flags_from_uri(uri), 0);
#else
  ret = sqlite3_open(StringValuePtr(path), &db);
#endif

  if (ret != SQLITE_OK) {
    do_sqlite3_raise_error(self, db, Qnil);
  }

  rb_iv_set(self, "@uri", uri);
  rb_iv_set(self, "@connection", Data_Wrap_Struct(rb_cObject, 0, 0, db));
  // Sqlite3 only supports UTF-8, so this is the standard encoding
  rb_iv_set(self, "@encoding", rb_str_new2("UTF-8"));
#ifdef HAVE_RUBY_ENCODING_H
  rb_iv_set(self, "@encoding_id", INT2FIX(rb_enc_find_index("UTF-8")));
#endif

  return Qtrue;
}
开发者ID:bmatcuk,项目名称:do,代码行数:25,代码来源:do_sqlite3.c

示例5: rb_enc_find

rb_encoding *
rb_enc_find(const char *name)
{
    int idx = rb_enc_find_index(name);
    if (idx < 0) idx = 0;
    return rb_enc_from_index(idx);
}
开发者ID:217,项目名称:ruby,代码行数:7,代码来源:encoding.c

示例6: mysql2_set_field_string_encoding

static VALUE mysql2_set_field_string_encoding(VALUE val, MYSQL_FIELD field, rb_encoding *default_internal_enc, rb_encoding *conn_enc) {
  /* if binary flag is set, respect its wishes */
  if (field.flags & BINARY_FLAG && field.charsetnr == 63) {
    rb_enc_associate(val, binaryEncoding);
  } else if (!field.charsetnr) {
    /* MySQL 4.x may not provide an encoding, binary will get the bytes through */
    rb_enc_associate(val, binaryEncoding);
  } else {
    /* lookup the encoding configured on this field */
    const char *enc_name;
    int enc_index;

    enc_name = mysql2_mysql_enc_to_rb[field.charsetnr-1];
    if (enc_name != NULL) {
      /* use the field encoding we were able to match */
      enc_index = rb_enc_find_index(enc_name);
      rb_enc_set_index(val, enc_index);
    } else {
      /* otherwise fall-back to the connection's encoding */
      rb_enc_associate(val, conn_enc);
    }

    if (default_internal_enc) {
      val = rb_str_export_to_enc(val, default_internal_enc);
    }
  }
  return val;
}
开发者ID:Frantz103,项目名称:clubartizan-Rails,代码行数:28,代码来源:result.c

示例7: transcode_io

static VALUE transcode_io(VALUE src, int * parser_encoding)
{
    VALUE io_external_encoding;
    int io_external_enc_index;

    io_external_encoding = rb_funcall(src, rb_intern("external_encoding"), 0);

    /* if no encoding is returned, assume ascii8bit. */
    if (NIL_P(io_external_encoding)) {
	io_external_enc_index = rb_ascii8bit_encindex();
    } else {
	io_external_enc_index = rb_to_encoding_index(io_external_encoding);
    }

    /* Treat US-ASCII as utf_8 */
    if (io_external_enc_index == rb_usascii_encindex()) {
	*parser_encoding = YAML_UTF8_ENCODING;
	return src;
    }

    if (io_external_enc_index == rb_utf8_encindex()) {
	*parser_encoding = YAML_UTF8_ENCODING;
	return src;
    }

    if (io_external_enc_index == rb_enc_find_index("UTF-16LE")) {
	*parser_encoding = YAML_UTF16LE_ENCODING;
	return src;
    }

    if (io_external_enc_index == rb_enc_find_index("UTF-16BE")) {
	*parser_encoding = YAML_UTF16BE_ENCODING;
	return src;
    }

    /* Just guess on ASCII-8BIT */
    if (io_external_enc_index == rb_ascii8bit_encindex()) {
	*parser_encoding = YAML_ANY_ENCODING;
	return src;
    }

    /* If the external encoding is something we don't know how to handle,
     * fall back to YAML_ANY_ENCODING. */
    *parser_encoding = YAML_ANY_ENCODING;

    return src;
}
开发者ID:tenderlove,项目名称:psych,代码行数:47,代码来源:psych_parser.c

示例8: transcode_io

static VALUE transcode_io(VALUE src, int * parser_encoding)
{
    VALUE io_external_encoding;
    int io_external_enc_index;

    io_external_encoding = rb_funcall(src, rb_intern("external_encoding"), 0);

    /* if no encoding is returned, assume ascii8bit. */
    if (NIL_P(io_external_encoding)) {
	io_external_enc_index = rb_ascii8bit_encindex();
    } else {
	io_external_enc_index = rb_to_encoding_index(io_external_encoding);
    }

    /* Treat US-ASCII as utf_8 */
    if (io_external_enc_index == rb_usascii_encindex()) {
	*parser_encoding = YAML_UTF8_ENCODING;
	return src;
    }

    if (io_external_enc_index == rb_utf8_encindex()) {
	*parser_encoding = YAML_UTF8_ENCODING;
	return src;
    }

    if (io_external_enc_index == rb_enc_find_index("UTF-16LE")) {
	*parser_encoding = YAML_UTF16LE_ENCODING;
	return src;
    }

    if (io_external_enc_index == rb_enc_find_index("UTF-16BE")) {
	*parser_encoding = YAML_UTF16BE_ENCODING;
	return src;
    }

    /* Just guess on ASCII-8BIT */
    if (io_external_enc_index == rb_ascii8bit_encindex()) {
	*parser_encoding = YAML_ANY_ENCODING;
	return src;
    }

    rb_raise(rb_eArgError, "YAML file must be UTF-8, UTF-16LE, or UTF-16BE, not %s",
	    rb_enc_name(rb_enc_from_index(io_external_enc_index)));

    return Qnil;
}
开发者ID:eregon,项目名称:psych,代码行数:46,代码来源:parser.c

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

示例10: rb_enc_find_index2

int
rb_enc_find_index2(const char *name, long len)
{
    char buf[ENCODING_NAMELEN_MAX+1];

    if (len > ENCODING_NAMELEN_MAX) return -1;
    memcpy(buf, name, len);
    buf[len] = '\0';
    return rb_enc_find_index(buf);
}
开发者ID:tenderlove,项目名称:ruby,代码行数:10,代码来源:encoding.c

示例11: str_new

/*
  Set string encoding to UTF8
  See http://tenderlovemaking.com/2009/06/26/string-encoding-in-ruby-1-9-c-extensions.html
*/
static VALUE str_new(const char *str) {
  VALUE string = rb_str_new2(str);

  #ifdef HAVE_RUBY_ENCODING_H
  int enc = rb_enc_find_index("UTF-8");
  if(enc != -1) rb_enc_associate_index(string, enc);
  #endif

  return string;
}
开发者ID:playtimestudios,项目名称:admin_bounds,代码行数:14,代码来源:pbf_parser.c

示例12: summarize

static VALUE summarize(const VALUE self, volatile VALUE rb_str, volatile VALUE rb_dict_file, const VALUE rb_ratio, const VALUE rb_topics, const VALUE rb_sections) {
#ifdef HAVE_RUBY_ENCODING_H
    int enc = rb_enc_find_index("UTF-8");
#endif
    long int length = RSTRING_LEN(rb_str);
    char *text = StringValuePtr(rb_str);
    char *dictionary_file = StringValuePtr(rb_dict_file);
    int ratio = NUM2INT(rb_ratio);

    size_t result_len;
    OtsArticle *doc = ots_new_article();

    VALUE summary;
    VALUE topics;
    VALUE result;
    VALUE sections;

    if (!ots_load_xml_dictionary(doc, dictionary_file)) {
        ots_free_article(doc);
        rb_raise(rb_eRuntimeError, "Cannot load dictionary file");
        return Qnil;
    }

    ots_parse_stream(text, length, doc);
    ots_grade_doc(doc);
    ots_highlight_doc(doc, ratio);

    summary = rb_str_new2(ots_get_doc_text(doc, &result_len));
    topics = rb_str_new2((const char *)doc->title);
    sections = rb_ary_new();
    GList *li;
    for (li = (GList *) ots_get_doc_sections(doc); li != NULL; li = li->next) {
        VALUE section = rb_str_new2(li->data);
        rb_ary_push(sections, section);
    }

#ifdef HAVE_RUBY_ENCODING_H
    rb_enc_associate_index(summary, enc);
    rb_enc_associate_index(summary, enc);
#endif

    ots_free_article(doc);

    if (rb_topics == Qtrue) {
        result = rb_ary_new();
        rb_ary_push(result, summary);
        rb_ary_push(result, topics);
        return result;
    } else if (rb_sections == Qtrue) {
        return sections;
    } else {
        return summary;
    }
}
开发者ID:thcrock,项目名称:summarize,代码行数:54,代码来源:summarize.c

示例13: enc_cb

int enc_cb(void * _self, int columns, char **data, char **names)
{
  VALUE self = (VALUE)_self;
  int index = rb_enc_find_index("UTF-8");
  VALUE enc = rb_str_new2(data[0]);
  rb_enc_associate_index(enc, index);

  rb_iv_set(self, "@encoding", enc);

  return 0;
}
开发者ID:tenderlove,项目名称:deebee,代码行数:11,代码来源:deebee.c

示例14: str_find_encindex

/* Returns encoding index or UNSPECIFIED_ENCODING */
static int
str_find_encindex(VALUE enc)
{
    int idx;

    StringValue(enc);
    if (!rb_enc_asciicompat(rb_enc_get(enc))) {
	rb_raise(rb_eArgError, "invalid name encoding (non ASCII)");
    }
    idx = rb_enc_find_index(StringValueCStr(enc));
    return idx;
}
开发者ID:SongJungHwan,项目名称:hwan,代码行数:13,代码来源:encoding.c

示例15: opt_enc_index

static int
opt_enc_index(VALUE enc_name)
{
    const char *s = RSTRING_PTR(enc_name);
    int i = rb_enc_find_index(s);

    if (i < 0) {
	rb_raise(rb_eRuntimeError, "unknown encoding name - %s", s);
    }
    else if (rb_enc_dummy_p(rb_enc_from_index(i))) {
	rb_raise(rb_eRuntimeError, "dummy encoding is not acceptable - %s ", s);
    }
    return i;
}
开发者ID:Netfart,项目名称:rhodes,代码行数:14,代码来源:ruby.c


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