本文整理汇总了C++中rb_default_internal_encoding函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_default_internal_encoding函数的具体用法?C++ rb_default_internal_encoding怎么用?C++ rb_default_internal_encoding使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_default_internal_encoding函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: data_handler
static size_t data_handler(char * stream, size_t size, size_t nmemb, VALUE handler) {
size_t str_len = size * nmemb;
if(TYPE(handler) == T_STRING) {
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *default_internal_enc = rb_default_internal_encoding();
if (default_internal_enc) {
handler = rb_str_export_to_enc(handler, default_internal_enc);
} else {
handler = rb_str_export_to_enc(handler, utf8Encoding);
}
#endif
rb_str_buf_cat(handler, stream, str_len);
} else {
VALUE chunk = rb_str_new(stream, str_len);
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *default_internal_enc = rb_default_internal_encoding();
if (default_internal_enc) {
chunk = rb_str_export_to_enc(chunk, default_internal_enc);
} else {
chunk = rb_str_export_to_enc(chunk, utf8Encoding);
}
#endif
rb_funcall(handler, rb_intern("call"), 1, chunk);
}
return str_len;
}
示例2: 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;
}
示例3: yajl_found_hash_key
static int yajl_found_hash_key(void * ctx, const unsigned char * stringVal, unsigned int stringLen) {
yajl_parser_wrapper * wrapper;
GetParser((VALUE)ctx, wrapper);
VALUE keyStr;
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *default_internal_enc = rb_default_internal_encoding();
#endif
if (wrapper->symbolizeKeys) {
char buf[stringLen+1];
memcpy(buf, stringVal, stringLen);
buf[stringLen] = 0;
yajl_set_static_value(ctx, ID2SYM(rb_intern(buf)));
} 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;
}
示例4: rb_mysql_client_info
static VALUE rb_mysql_client_info(VALUE self) {
VALUE version, client_info;
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *default_internal_enc;
rb_encoding *conn_enc;
#endif
GET_CLIENT(self);
version = rb_hash_new();
#ifdef HAVE_RUBY_ENCODING_H
default_internal_enc = rb_default_internal_encoding();
conn_enc = rb_to_encoding(wrapper->encoding);
#endif
rb_hash_aset(version, sym_id, LONG2NUM(mysql_get_client_version()));
client_info = rb_str_new2(mysql_get_client_info());
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate(client_info, conn_enc);
if (default_internal_enc) {
client_info = rb_str_export_to_enc(client_info, default_internal_enc);
}
#endif
rb_hash_aset(version, sym_version, client_info);
return version;
}
示例5: 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;
}
示例6: 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;
}
示例7: rb_mysql_client_escape
static VALUE rb_mysql_client_escape(VALUE self, VALUE str) {
MYSQL * client;
VALUE newStr;
unsigned long newLen, oldLen;
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(rb_iv_get(self, "@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);
char escaped[(oldLen*2)+1];
Data_Get_Struct(self, MYSQL, client);
REQUIRE_OPEN_DB(client);
newLen = mysql_real_escape_string(client, escaped, StringValuePtr(str), RSTRING_LEN(str));
if (newLen == oldLen) {
// no need to return a new ruby string if nothing changed
return str;
} else {
newStr = rb_str_new(escaped, 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;
}
}
示例8: rb_comparator_func
int rb_comparator_func(void * ctx, int a_len, const void * a, int b_len, const void * b)
{
VALUE comparator;
VALUE a_str;
VALUE b_str;
VALUE comparison;
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding * internal_encoding;
internal_encoding = rb_default_internal_encoding();
#endif
comparator = (VALUE)ctx;
a_str = rb_str_new((const char *)a, a_len);
b_str = rb_str_new((const char *)b, b_len);
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(a_str, rb_utf8_encindex());
rb_enc_associate_index(b_str, rb_utf8_encindex());
if(internal_encoding) {
a_str = rb_str_export_to_enc(a_str, internal_encoding);
b_str = rb_str_export_to_enc(b_str, internal_encoding);
}
#endif
comparison = rb_funcall(comparator, rb_intern("compare"), 2, a_str, b_str);
return NUM2INT(comparison);
}
示例9: 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;
}
示例10: 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;
}
}
示例11: 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);
}
示例12: string_callback
int string_callback(void *ctx, const unsigned char *stringVal, size_t stringLen) {
VALUE str = rb_str_new((const char *)stringVal, stringLen);
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *default_internal_enc = rb_default_internal_encoding();
rb_enc_associate(str, utf8Encoding);
if (default_internal_enc) {
str = rb_str_export_to_enc(str, default_internal_enc);
}
#endif
set_value(ctx,str);
return 1;
}
示例13: yajl_found_string
static int yajl_found_string(void * ctx, const unsigned char * stringVal, unsigned int stringLen) {
VALUE str = rb_str_new((const char *)stringVal, stringLen);
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *default_internal_enc = rb_default_internal_encoding();
rb_enc_associate(str, utf8Encoding);
if (default_internal_enc) {
str = rb_str_export_to_enc(str, default_internal_enc);
}
#endif
yajl_set_static_value(ctx, str);
yajl_check_and_fire_callback(ctx);
return 1;
}
示例14: ATLTRACE
void CRScriptCore::InitializeEnvironment()
{
ATLTRACE(_("Initialize Environment in Thread:%08X\n"), GetCurrentThreadId());
#ifndef __IRubyEngine_INTERFACE_DEFINED__
int stacktop;
s_pStackTop = reinterpret_cast<LPBYTE>(&stacktop);
#endif
int dummyargc(1);
char* dummyargv[] = {"dummy", NULL };
char** pargv;
ruby_sysinit(&dummyargc, &pargv);
RUBY_INIT_STACK;
ruby_init();
ruby_options(3, asr_argv);
s_pEncoding = rb_default_internal_encoding();
if (!s_pEncoding) s_pEncoding = rb_default_external_encoding();
try
{
rb_require("win32ole");
VALUE v = rb_eval_string("WIN32OLE");
// override original constructor
rb_define_singleton_method(v, "new", reinterpret_cast<VALUE(*)(...)>(fole_s_new), -1);
rb_define_singleton_method(v, "connect", reinterpret_cast<VALUE(*)(...)>(fole_s_connect), 1);
rb_define_singleton_method(v, "attach", reinterpret_cast<VALUE(*)(...)>(foleex_attach), 2);
rb_define_method(v, "__release", reinterpret_cast<VALUE(*)(...)>(foleex_release), 0);
rb_define_method(v, "method_missing", reinterpret_cast<VALUE(*)(...)>(foleex_missing), -1);
rb_define_method(v, "each", reinterpret_cast<VALUE(*)(...)>(foleex_each), 0);
if (rb_const_defined_at(v, rb_intern("ARGV")) == Qfalse)
{
rb_define_const(v, "ARGV", rb_ary_new());
}
s_valueWin32Ole = v;
s_valueWIN32OLERuntimeError = rb_eval_string("WIN32OLERuntimeError");
v = rb_define_class("WIN32OLEEX", v);
s_valueWin32OleEx = v;
rb_define_singleton_method(v, "attach", reinterpret_cast<VALUE(*)(...)>(foleex_attach), 2);
rb_define_method(v, "method_missing", reinterpret_cast<VALUE(*)(...)>(foleex_missing), -1);
//
s_valueActiveRubyScript = rb_define_class("ActiveScriptRuby", rb_cObject);
rb_define_singleton_method(s_valueActiveRubyScript, "trace", (VALUE(*)(...))trace_hook, 6);
rb_define_singleton_method(s_valueActiveRubyScript, "settrace", (VALUE(*)(...))trace_set, 1);
rb_define_singleton_method(s_valueActiveRubyScript, "rubyize", (VALUE(*)(...))rubyize, 1);
}
catch (...)
{
ATLTRACE(_T("Exception for class\n"));
}
}
示例15: ruv_buffer_read
// read from buffer and return a ruby string
// params: start=0, length=self.length, encoding=Encoding.default_internal_encoding
// return: ruby string
VALUE ruv_buffer_read(int argc, VALUE* argv, VALUE rb_buffer) {
VALUE rb_start, rb_length, rb_intern_enc, rb_str;
size_t start, length;
rb_encoding *intern_enc;
ruv_buffer_t *buffer;
char *str_p;
Data_Get_Struct(rb_buffer, ruv_buffer_t, buffer);
rb_scan_args(argc, argv, "03", &rb_start, &rb_length, &rb_intern_enc);
if(!NIL_P(rb_start)) {
Check_Type(rb_start, T_FIXNUM);
start = NUM2SIZET(rb_start);
} else {
start = 0;
}
if(start >= buffer->length) {
rb_raise(rb_eArgError, "start is out of bounds.");
}
if(!NIL_P(rb_length)) {
Check_Type(rb_length, T_FIXNUM);
length = NUM2SIZET(length);
} else {
length = buffer->length - start;
}
// make sure it's not out of bound
length = MIN(length, buffer->length - start);
if(!NIL_P(rb_intern_enc)) {
intern_enc = rb_enc_get(rb_intern_enc);
} else {
intern_enc = rb_default_internal_encoding();
}
str_p = buffer->data + start;
rb_str = rb_tainted_str_new(str_p, length);
if(intern_enc) {
rb_str = rb_str_export_to_enc(rb_str, intern_enc);
}
return rb_str;
}