本文整理汇总了C++中rb_enc_associate函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_enc_associate函数的具体用法?C++ rb_enc_associate怎么用?C++ rb_enc_associate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_enc_associate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: dnssd_service_resolve_reply
static void DNSSD_API
dnssd_service_resolve_reply(DNSServiceRef client, DNSServiceFlags flags,
uint32_t interface, DNSServiceErrorType e, const char *name,
const char *target, uint16_t port, uint16_t txt_len,
const unsigned char *txt_rec, void *context) {
VALUE service, reply, argv[7];
dnssd_check_error_code(e);
service = (VALUE)context;
argv[0] = service;
argv[1] = ULONG2NUM(flags);
argv[2] = ULONG2NUM(interface);
argv[3] = rb_str_new2(name);
rb_enc_associate(argv[3], rb_utf8_encoding());
argv[4] = rb_str_new2(target);
rb_enc_associate(argv[4], rb_utf8_encoding());
argv[5] = UINT2NUM(ntohs(port));
argv[6] = rb_str_new((char *)txt_rec, txt_len);
rb_enc_associate(argv[6], rb_utf8_encoding());
reply = rb_class_new_instance(7, argv, cDNSSDReplyResolve);
dnssd_service_callback(service, reply);
}
开发者ID:brianwells,项目名称:dnssd,代码行数:26,代码来源:service.c
示例2: yajl_found_hash_key
static int yajl_found_hash_key(void * ctx, const unsigned char * stringVal, unsigned int stringLen) {
yajl_parser_wrapper * wrapper;
VALUE keyStr;
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *default_internal_enc;
#endif
GetParser((VALUE)ctx, wrapper);
#ifdef HAVE_RUBY_ENCODING_H
default_internal_enc = rb_default_internal_encoding();
#endif
if (wrapper->symbolizeKeys) {
char buf[stringLen+1];
memcpy(buf, stringVal, stringLen);
buf[stringLen] = 0;
VALUE stringEncoded = rb_str_new2(buf);
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate(stringEncoded, rb_utf8_encoding());
#endif
yajl_set_static_value(ctx, ID2SYM(rb_to_id(stringEncoded)));
} else {
keyStr = rb_str_new((const char *)stringVal, stringLen);
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate(keyStr, utf8Encoding);
if (default_internal_enc) {
keyStr = rb_str_export_to_enc(keyStr, default_internal_enc);
}
#endif
yajl_set_static_value(ctx, keyStr);
}
yajl_check_and_fire_callback(ctx);
return 1;
}
开发者ID:curtosis,项目名称:lucite,代码行数:34,代码来源:yajl_ext.c
示例3: rb_raise_mysql2_stmt_error
void rb_raise_mysql2_stmt_error(mysql_stmt_wrapper *stmt_wrapper) {
VALUE e;
GET_CLIENT(stmt_wrapper->client);
VALUE rb_error_msg = rb_str_new2(mysql_stmt_error(stmt_wrapper->stmt));
VALUE rb_sql_state = rb_tainted_str_new2(mysql_stmt_sqlstate(stmt_wrapper->stmt));
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *conn_enc;
conn_enc = rb_to_encoding(wrapper->encoding);
rb_encoding *default_internal_enc = rb_default_internal_encoding();
rb_enc_associate(rb_error_msg, conn_enc);
rb_enc_associate(rb_sql_state, conn_enc);
if (default_internal_enc) {
rb_error_msg = rb_str_export_to_enc(rb_error_msg, default_internal_enc);
rb_sql_state = rb_str_export_to_enc(rb_sql_state, default_internal_enc);
}
#endif
e = rb_funcall(cMysql2Error, intern_new_with_args, 4,
rb_error_msg,
LONG2FIX(wrapper->server_version),
UINT2NUM(mysql_stmt_errno(stmt_wrapper->stmt)),
rb_sql_state);
rb_exc_raise(e);
}
开发者ID:AhmedElassuty,项目名称:mysql2,代码行数:27,代码来源:statement.c
示例4: tfio_read
// Reads data from the IO, according to the Rack specifications for `#read`.
static VALUE tfio_read(int argc, VALUE *argv, VALUE self) {
int fd = get_tmpfile(self);
size_t pos = get_pos(self);
size_t end = get_end(self);
VALUE buffer = Qnil;
char ret_nil = 0;
ssize_t len = 0;
// get the buffer object if given
if (argc == 2) {
Check_Type(argv[1], T_STRING);
buffer = argv[1];
}
// get the length object, if given
if (argc > 0 && argv[0] != Qnil) {
Check_Type(argv[0], T_FIXNUM);
len = FIX2LONG(argv[0]);
if (len < 0)
rb_raise(rb_eRangeError, "length should be bigger then 0.");
ret_nil = 1;
}
// return if we're at the EOF.
if (pos == end)
goto no_data;
// calculate length if it wasn't specified.
if (len == 0) {
// make sure we're not reading more then we have
len = end - pos;
// set position for future reads
set_pos(self, end);
if (len == 0)
goto no_data;
} else {
// set position for future reads
set_pos(self, pos + len);
}
// limit read to what we have
if (len + pos > end)
len = end - pos;
// create the buffer if we don't have one.
if (buffer == Qnil) {
buffer = rb_str_buf_new(len);
// make sure the buffer is binary encoded.
rb_enc_associate(buffer, BinaryEncoding);
} else {
// make sure the buffer is binary encoded.
rb_enc_associate(buffer, BinaryEncoding);
if (rb_str_capacity(buffer) < len)
rb_str_resize(buffer, len);
}
// read the data.
if (pread(fd, RSTRING_PTR(buffer), len, pos) <= 0)
goto no_data;
rb_str_set_len(buffer, len);
return buffer;
no_data:
if (ret_nil)
return Qnil;
else
return rb_str_buf_new(0);
}
开发者ID:boazsegev,项目名称:iodine,代码行数:61,代码来源:rb-rack-io.c
示例5: rb_raise_mysql2_error
static VALUE rb_raise_mysql2_error(mysql_client_wrapper *wrapper) {
VALUE rb_error_msg = rb_str_new2(mysql_error(wrapper->client));
VALUE rb_sql_state = rb_tainted_str_new2(mysql_sqlstate(wrapper->client));
VALUE e;
#ifdef HAVE_RUBY_ENCODING_H
if (wrapper->server_version < 50500) {
/* MySQL < 5.5 uses mixed encoding, just call it binary. */
int err_enc = rb_ascii8bit_encindex();
rb_enc_associate_index(rb_error_msg, err_enc);
rb_enc_associate_index(rb_sql_state, err_enc);
} else {
/* MySQL >= 5.5 uses UTF-8 errors internally and converts them to the connection encoding. */
rb_encoding *default_internal_enc = rb_default_internal_encoding();
rb_encoding *conn_enc = rb_to_encoding(wrapper->encoding);
rb_enc_associate(rb_error_msg, conn_enc);
rb_enc_associate(rb_sql_state, conn_enc);
if (default_internal_enc) {
rb_error_msg = rb_str_export_to_enc(rb_error_msg, default_internal_enc);
rb_sql_state = rb_str_export_to_enc(rb_sql_state, default_internal_enc);
}
}
#endif
e = rb_exc_new3(cMysql2Error, rb_error_msg);
rb_funcall(e, intern_error_number_eql, 1, UINT2NUM(mysql_errno(wrapper->client)));
rb_funcall(e, intern_sql_state_eql, 1, rb_sql_state);
rb_exc_raise(e);
return Qnil;
}
开发者ID:johncant,项目名称:mysql2,代码行数:29,代码来源:client.c
示例6: dnssd_service_query_record_reply
static void DNSSD_API
dnssd_service_query_record_reply(DNSServiceRef client, DNSServiceFlags flags,
uint32_t interface, DNSServiceErrorType e, const char *fullname,
uint16_t rrtype, uint16_t rrclass, uint16_t rdlen, const void *rdata,
uint32_t ttl, void *context) {
VALUE service, reply, argv[8];
dnssd_check_error_code(e);
service = (VALUE)context;
argv[0] = service;
argv[1] = ULONG2NUM(flags);
argv[2] = ULONG2NUM(interface);
argv[3] = rb_str_new2(fullname);
rb_enc_associate(argv[3], rb_utf8_encoding());
argv[4] = UINT2NUM(rrtype);
argv[5] = UINT2NUM(rrclass);
argv[6] = rb_str_new((char *)rdata, rdlen);
rb_enc_associate(argv[6], rb_utf8_encoding());
argv[7] = ULONG2NUM(ttl);
reply = rb_class_new_instance(8, argv, cDNSSDReplyQueryRecord);
dnssd_service_callback(service, reply);
}
开发者ID:brianwells,项目名称:dnssd,代码行数:26,代码来源:service.c
示例7: 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
示例8: syserr_initialize
static VALUE
syserr_initialize(int argc, VALUE *argv, VALUE self)
{
#if !defined(_WIN32)
char *strerror();
#endif
const char *err;
VALUE mesg, error, func;
VALUE klass = rb_obj_class(self);
if (klass == rb_eSystemCallError) {
st_data_t data = (st_data_t)klass;
rb_scan_args(argc, argv, "12", &mesg, &error, &func);
if (argc == 1 && FIXNUM_P(mesg)) {
error = mesg; mesg = Qnil;
}
if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &data)) {
klass = (VALUE)data;
/* change class */
if (!RB_TYPE_P(self, T_OBJECT)) { /* insurance to avoid type crash */
rb_raise(rb_eTypeError, "invalid instance type");
}
RBASIC_SET_CLASS(self, klass);
}
}
else {
rb_scan_args(argc, argv, "02", &mesg, &func);
error = rb_const_get(klass, rb_intern("Errno"));
}
if (!NIL_P(error)) err = strerror(NUM2INT(error));
else err = "unknown error";
if (!NIL_P(mesg)) {
rb_encoding *le = rb_locale_encoding();
VALUE str = StringValue(mesg);
rb_encoding *me = rb_enc_get(mesg);
if (NIL_P(func))
mesg = rb_sprintf("%s - %"PRIsVALUE, err, mesg);
else
mesg = rb_sprintf("%s @ %"PRIsVALUE" - %"PRIsVALUE, err, func, mesg);
if (le != me && rb_enc_asciicompat(me)) {
le = me;
}/* else assume err is non ASCII string. */
OBJ_INFECT(mesg, str);
rb_enc_associate(mesg, le);
}
else {
mesg = rb_str_new2(err);
rb_enc_associate(mesg, rb_locale_encoding());
}
rb_call_super(1, &mesg);
rb_iv_set(self, "errno", error);
return self;
}
开发者ID:knugie,项目名称:ruby,代码行数:54,代码来源:error.c
示例9: rb_tinytds_escape
static VALUE rb_tinytds_escape(VALUE self, VALUE string) {
Check_Type(string, T_STRING);
GET_CLIENT_WRAPPER(self);
VALUE new_string = rb_funcall(string, intern_gsub, 2, opt_escape_regex, opt_escape_dblquote);
rb_enc_associate(new_string, cwrap->encoding);
return new_string;
}
开发者ID:pd40,项目名称:tiny_tds,代码行数:7,代码来源:client.c
示例10: rb_raise_mysql2_error
static VALUE rb_raise_mysql2_error(mysql_client_wrapper *wrapper) {
VALUE rb_error_msg = rb_str_new2(mysql_error(wrapper->client));
VALUE rb_sql_state = rb_tainted_str_new2(mysql_sqlstate(wrapper->client));
VALUE e;
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate(rb_error_msg, rb_utf8_encoding());
rb_enc_associate(rb_sql_state, rb_usascii_encoding());
#endif
e = rb_funcall(cMysql2Error, rb_intern("new"), 2, rb_error_msg, LONG2FIX(wrapper->server_version));
rb_funcall(e, intern_error_number_eql, 1, UINT2NUM(mysql_errno(wrapper->client)));
rb_funcall(e, intern_sql_state_eql, 1, rb_sql_state);
rb_exc_raise(e);
return Qnil;
}
开发者ID:notonthehighstreet,项目名称:mysql2,代码行数:16,代码来源:client.c
示例11: rbverse_host_id2str
/*
* Convert a Verse host id to a String with ASCII8BIT encoding.
*/
inline VALUE
rbverse_host_id2str( const uint8 *hostid ) {
VALUE idstring = rb_str_new( (const char *)hostid, V_HOST_ID_SIZE );
rb_enc_associate( idstring, rb_ascii8bit_encoding() );
return idstring;
}
开发者ID:ged,项目名称:ruby-verse,代码行数:10,代码来源:verse_ext.c
示例12: sax_value_as_s
/* call-seq: as_s()
*
* *return* value as an String.
*/
static VALUE
sax_value_as_s(VALUE self) {
SaxDrive dr = DATA_PTR(self);
VALUE rs;
if ('\0' == *dr->buf.str) {
return Qnil;
}
if (dr->options.convert_special) {
ox_sax_collapse_special(dr, dr->buf.str, dr->buf.pos, dr->buf.line, dr->buf.col);
}
switch (dr->options.skip) {
case CrSkip:
buf_collapse_return(dr->buf.str);
break;
case SpcSkip:
buf_collapse_white(dr->buf.str);
break;
default:
break;
}
rs = rb_str_new2(dr->buf.str);
#if HAS_ENCODING_SUPPORT
if (0 != dr->encoding) {
rb_enc_associate(rs, dr->encoding);
}
#elif HAS_PRIVATE_ENCODING
if (Qnil != dr->encoding) {
rb_funcall(rs, ox_force_encoding_id, 1, dr->encoding);
}
#endif
return rs;
}
开发者ID:ohler55,项目名称:ox,代码行数:37,代码来源:sax_as.c
示例13: preserve_original_state
static inline void
preserve_original_state(VALUE orig, VALUE dest)
{
rb_enc_associate(dest, rb_enc_get(orig));
RB_OBJ_INFECT_RAW(dest, orig);
}
开发者ID:riddochc,项目名称:ruby,代码行数:7,代码来源:escape.c
示例14: map_key_callback
int map_key_callback(void *ctx, const unsigned char *stringVal, size_t stringLen) {
VALUE key;
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *default_internal_enc;
#endif
if ( ((CTX *)ctx)->symbolizeKeys ) {
#ifdef HAVE_RUBY_ENCODING_H
ID id = rb_intern3((const char *)stringVal, stringLen, utf8Encoding);
key = ID2SYM(id);
#else
VALUE str = rb_str_new((const char *)stringVal, stringLen);
key = rb_str_intern(str);
#endif
} else {
key = rb_str_new((const char *)stringVal, stringLen);
#ifdef HAVE_RUBY_ENCODING_H
default_internal_enc = rb_default_internal_encoding();
rb_enc_associate(key, utf8Encoding);
if (default_internal_enc) {
key = rb_str_export_to_enc(key, default_internal_enc);
}
#endif
}
set_key(ctx, key);
return 1;
}
开发者ID:Rosiv,项目名称:omnibus-portable,代码行数:27,代码来源:parser.c
示例15: rb_mysql_result_fetch_field
static VALUE rb_mysql_result_fetch_field(VALUE self, unsigned int idx, int symbolize_keys) {
VALUE rb_field;
GET_RESULT(self);
if (wrapper->fields == Qnil) {
wrapper->numberOfFields = mysql_num_fields(wrapper->result);
wrapper->fields = rb_ary_new2(wrapper->numberOfFields);
}
rb_field = rb_ary_entry(wrapper->fields, idx);
if (rb_field == Qnil) {
MYSQL_FIELD *field = NULL;
rb_encoding *default_internal_enc = rb_default_internal_encoding();
rb_encoding *conn_enc = rb_to_encoding(wrapper->encoding);
field = mysql_fetch_field_direct(wrapper->result, idx);
if (symbolize_keys) {
rb_field = rb_intern3(field->name, field->name_length, rb_utf8_encoding());
rb_field = ID2SYM(rb_field);
} else {
rb_field = rb_str_new(field->name, field->name_length);
rb_enc_associate(rb_field, conn_enc);
if (default_internal_enc) {
rb_field = rb_str_export_to_enc(rb_field, default_internal_enc);
}
}
rb_ary_store(wrapper->fields, idx, rb_field);
}
return rb_field;
}
开发者ID:gammons,项目名称:mysql2,代码行数:31,代码来源:result.c
示例16: rb_mysql_client_escape
static VALUE rb_mysql_client_escape(VALUE self, VALUE str) {
VALUE newStr;
unsigned long newLen, oldLen;
GET_CLIENT(self);
REQUIRE_OPEN_DB(wrapper);
Check_Type(str, T_STRING);
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *default_internal_enc = rb_default_internal_encoding();
rb_encoding *conn_enc = rb_to_encoding(wrapper->encoding);
// ensure the string is in the encoding the connection is expecting
str = rb_str_export_to_enc(str, conn_enc);
#endif
oldLen = RSTRING_LEN(str);
newStr = rb_str_new(0, oldLen*2+1);
newLen = mysql_real_escape_string(wrapper->client, RSTRING_PTR(newStr), StringValuePtr(str), oldLen);
if (newLen == oldLen) {
// no need to return a new ruby string if nothing changed
return str;
} else {
rb_str_resize(newStr, newLen);
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate(newStr, conn_enc);
if (default_internal_enc) {
newStr = rb_str_export_to_enc(newStr, default_internal_enc);
}
#endif
return newStr;
}
}
开发者ID:heathd,项目名称:mysql2,代码行数:32,代码来源:client.c
示例17: pgresult_getvalue
/*
* call-seq:
* res.getvalue( tup_num, field_num )
*
* Returns the value in tuple number _tup_num_, field _field_num_,
* or +nil+ if the field is +NULL+.
*/
static VALUE
pgresult_getvalue(VALUE self, VALUE tup_num, VALUE field_num)
{
VALUE val;
PGresult *result;
int i = NUM2INT(tup_num);
int j = NUM2INT(field_num);
result = pgresult_get(self);
if(i < 0 || i >= PQntuples(result)) {
rb_raise(rb_eArgError,"invalid tuple number %d", i);
}
if(j < 0 || j >= PQnfields(result)) {
rb_raise(rb_eArgError,"invalid field number %d", j);
}
if(PQgetisnull(result, i, j))
return Qnil;
val = rb_tainted_str_new(PQgetvalue(result, i, j),
PQgetlength(result, i, j));
#ifdef M17N_SUPPORTED
/* associate client encoding for text format only */
if ( 0 == PQfformat(result, j) ) {
ASSOCIATE_INDEX( val, self );
} else {
rb_enc_associate( val, rb_ascii8bit_encoding() );
}
#endif
return val;
}
开发者ID:danielcode,项目名称:ruby-pg,代码行数:38,代码来源:pg_result.c
示例18: require_libraries
static void
require_libraries(VALUE *req_list)
{
VALUE list = *req_list;
VALUE self = rb_vm_top_self();
ID require;
rb_thread_t *th = GET_THREAD();
rb_block_t *prev_base_block = th->base_block;
rb_encoding *extenc = rb_default_external_encoding();
int prev_parse_in_eval = th->parse_in_eval;
th->base_block = 0;
th->parse_in_eval = 0;
Init_ext(); /* should be called here for some reason :-( */
CONST_ID(require, "require");
while (list && RARRAY_LEN(list) > 0) {
VALUE feature = rb_ary_shift(list);
rb_enc_associate(feature, extenc);
RBASIC(feature)->klass = rb_cString;
OBJ_FREEZE(feature);
rb_funcall2(self, require, 1, &feature);
}
*req_list = 0;
th->parse_in_eval = prev_parse_in_eval;
th->base_block = prev_base_block;
}
开发者ID:MosesMendoza,项目名称:crossfader,代码行数:27,代码来源:ruby.c
示例19: rb_mysql_client_server_info
static VALUE rb_mysql_client_server_info(VALUE self) {
VALUE version, server_info;
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *default_internal_enc;
rb_encoding *conn_enc;
#endif
GET_CLIENT(self);
REQUIRE_OPEN_DB(wrapper);
#ifdef HAVE_RUBY_ENCODING_H
default_internal_enc = rb_default_internal_encoding();
conn_enc = rb_to_encoding(wrapper->encoding);
#endif
version = rb_hash_new();
rb_hash_aset(version, sym_id, LONG2FIX(mysql_get_server_version(wrapper->client)));
server_info = rb_str_new2(mysql_get_server_info(wrapper->client));
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate(server_info, conn_enc);
if (default_internal_enc) {
server_info = rb_str_export_to_enc(server_info, default_internal_enc);
}
#endif
rb_hash_aset(version, sym_version, server_info);
return version;
}
开发者ID:0xCCD,项目名称:mysql2,代码行数:26,代码来源:client.c
示例20: tfio_gets
/**
Gets returns a line. this is okay for small lines,
but shouldn't really be used.
Limited to ~ 1Mb of a line length.
*/
static VALUE tfio_gets(VALUE self) {
int fd = get_tmpfile(self);
size_t pos = get_pos(self);
size_t end = get_end(self);
if (pos == end)
return Qnil;
size_t pos_e = pos;
char c;
int ret;
VALUE buffer;
do {
ret = pread(fd, &c, 1, pos_e);
} while (ret > 0 && c != '\n' && (++pos_e < end));
set_pos(self, pos_e + 1);
if (pos > pos_e) {
buffer = rb_str_buf_new(pos_e - pos);
// make sure the buffer is binary encoded.
rb_enc_associate(buffer, BinaryEncoding);
if (pread(fd, RSTRING_PTR(buffer), pos_e - pos, pos) < 0)
return Qnil;
rb_str_set_len(buffer, pos_e - pos);
return buffer;
}
return Qnil;
}
开发者ID:boazsegev,项目名称:iodine,代码行数:32,代码来源:rb-rack-io.c
注:本文中的rb_enc_associate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论