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

C++ rb_default_internal_encoding函数代码示例

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

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



在下文中一共展示了rb_default_internal_encoding函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:brianmario,项目名称:streamly,代码行数:27,代码来源:streamly.c


示例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;
}
开发者ID:johncant,项目名称:mysql2,代码行数:29,代码来源:client.c


示例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;
}
开发者ID:fcheung,项目名称:yajl-ruby,代码行数:26,代码来源:yajl_ext.c


示例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;
}
开发者ID:0xCCD,项目名称:mysql2,代码行数:25,代码来源:client.c


示例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;
}
开发者ID:0xCCD,项目名称:mysql2,代码行数:26,代码来源:client.c


示例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;
}
开发者ID:Rosiv,项目名称:omnibus-portable,代码行数:27,代码来源:parser.c


示例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;
  }
}
开发者ID:foobargem,项目名称:mysql2,代码行数:34,代码来源:mysql2_ext.c


示例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);
}
开发者ID:jimflood,项目名称:sqlite3-ruby,代码行数:30,代码来源:database.c


示例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;
}
开发者ID:gammons,项目名称:mysql2,代码行数:31,代码来源:result.c


示例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;
    }
}
开发者ID:heathd,项目名称:mysql2,代码行数:32,代码来源:client.c


示例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);
}
开发者ID:AhmedElassuty,项目名称:mysql2,代码行数:27,代码来源:statement.c


示例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;
}
开发者ID:Rosiv,项目名称:omnibus-portable,代码行数:12,代码来源:parser.c


示例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;
}
开发者ID:fcheung,项目名称:yajl-ruby,代码行数:13,代码来源:yajl_ext.c


示例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"));
	}
}
开发者ID:arton,项目名称:RScript20,代码行数:48,代码来源:RScriptCore.cpp


示例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;
}
开发者ID:aq1018,项目名称:ruv,代码行数:50,代码来源:ruv_buffer.c


示例16: rb_mysql_result_fetch_field

static VALUE rb_mysql_result_fetch_field(VALUE self, unsigned int idx, short int symbolize_keys) {
  mysql2_result_wrapper * wrapper;
  VALUE rb_field;
  GetMysql2Result(self, wrapper);

  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;
#ifdef HAVE_RUBY_ENCODING_H
    rb_encoding *default_internal_enc = rb_default_internal_encoding();
    rb_encoding *conn_enc = rb_to_encoding(wrapper->encoding);
#endif

    field = mysql_fetch_field_direct(wrapper->result, idx);
    if (symbolize_keys) {
      char buf[field->name_length+1];
      memcpy(buf, field->name, field->name_length);
      buf[field->name_length] = 0;

#ifdef HAVE_RB_INTERN3
      rb_field = rb_intern3(buf, field->name_length, rb_utf8_encoding());
      rb_field = ID2SYM(rb_field);
#else
      VALUE colStr;
      colStr = rb_str_new2(buf);
      rb_field = ID2SYM(rb_to_id(colStr));
#endif
    } else {
      rb_field = rb_str_new(field->name, field->name_length);
#ifdef HAVE_RUBY_ENCODING_H
      rb_enc_associate(rb_field, conn_enc);
      if (default_internal_enc) {
        rb_field = rb_str_export_to_enc(rb_field, default_internal_enc);
      }
#endif
    }
    rb_ary_store(wrapper->fields, idx, rb_field);
  }

  return rb_field;
}
开发者ID:GromBacher,项目名称:mysql2,代码行数:46,代码来源:result.c


示例17: rb_mysql_client_info

static VALUE rb_mysql_client_info(RB_MYSQL_UNUSED VALUE self) {
  VALUE version = rb_hash_new(), client_info;
#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"));
#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;
}
开发者ID:foobargem,项目名称:mysql2,代码行数:18,代码来源:mysql2_ext.c


示例18: file_path_convert

static VALUE
file_path_convert(VALUE name)
{
#ifndef _WIN32 /* non Windows == Unix */
    rb_encoding *fname_encoding = rb_enc_from_index(ENCODING_GET(name));
    rb_encoding *fs_encoding;
    if (rb_default_internal_encoding() != NULL
	    && rb_usascii_encoding() != fname_encoding
	    && rb_ascii8bit_encoding() != fname_encoding
	    && (fs_encoding = rb_filesystem_encoding()) != fname_encoding
	    && !rb_enc_str_asciionly_p(name)) {
	/* Don't call rb_filesystem_encoding() before US-ASCII and ASCII-8BIT */
	/* fs_encoding should be ascii compatible */
	name = rb_str_conv_enc(name, fname_encoding, fs_encoding);
    }
#endif
    return name;
}
开发者ID:shirosaki,项目名称:fenix,代码行数:18,代码来源:file.c


示例19: data_objects_typecast

/*
 * Common typecasting logic that can be used or overriden by Adapters.
 */
extern VALUE data_objects_typecast(const char *value, long length, const VALUE type, int encoding) {
#ifdef HAVE_RUBY_ENCODING_H
  rb_encoding *internal_encoding = rb_default_internal_encoding();
#else
  void *internal_encoding = NULL;
#endif

  if (type == rb_cInteger) {
    return rb_cstr2inum(value, 10);
  }
  else if (type == rb_cString) {
    return DATA_OBJECTS_STR_NEW(value, length, encoding, internal_encoding);
  }
  else if (type == rb_cFloat) {
    return rb_float_new(rb_cstr_to_dbl(value, Qfalse));
  }
  else if (type == rb_cBigDecimal) {
    return rb_funcall(rb_cBigDecimal, DO_ID_NEW, 1, rb_str_new(value, length));
  }
  else if (type == rb_cDate) {
    return data_objects_parse_date(value);
  }
  else if (type == rb_cDateTime) {
    return data_objects_parse_date_time(value);
  }
  else if (type == rb_cTime) {
    return data_objects_parse_time(value);
  }
  else if (type == rb_cTrueClass) {
    return (!value || strcmp("0", value) == 0) ? Qfalse : Qtrue;
  }
  else if (type == rb_cByteArray) {
    return rb_funcall(rb_cByteArray, DO_ID_NEW, 1, rb_str_new(value, length));
  }
  else if (type == rb_cClass) {
    return rb_funcall(mDO, rb_intern("full_const_get"), 1, rb_str_new(value, length));
  }
  else if (type == rb_cNilClass) {
    return Qnil;
  }
  else {
    return DATA_OBJECTS_STR_NEW(value, length, encoding, internal_encoding);
  }
}
开发者ID:CompendiumSoftware,项目名称:do_mysql,代码行数:47,代码来源:do_common.c


示例20: rb_mysql_client_real_escape

/* call-seq:
 *    client.escape(string)
 *
 * Escape +string+ so that it may be used in a SQL statement.
 */
static VALUE rb_mysql_client_real_escape(VALUE self, VALUE str) {
  unsigned char *newStr;
  VALUE rb_str;
  unsigned long newLen, oldLen;
#ifdef HAVE_RUBY_ENCODING_H
  rb_encoding *default_internal_enc;
  rb_encoding *conn_enc;
#endif
  GET_CLIENT(self);

  REQUIRE_CONNECTED(wrapper);
  Check_Type(str, T_STRING);
#ifdef HAVE_RUBY_ENCODING_H
  default_internal_enc = rb_default_internal_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 = xmalloc(oldLen*2+1);

  newLen = mysql_real_escape_string(wrapper->client, (char *)newStr, RSTRING_PTR(str), oldLen);
  if (newLen == oldLen) {
    /* no need to return a new ruby string if nothing changed */
#ifdef HAVE_RUBY_ENCODING_H
    if (default_internal_enc) {
      str = rb_str_export_to_enc(str, default_internal_enc);
    }
#endif
    xfree(newStr);
    return str;
  } else {
    rb_str = rb_str_new((const char*)newStr, newLen);
#ifdef HAVE_RUBY_ENCODING_H
    rb_enc_associate(rb_str, conn_enc);
    if (default_internal_enc) {
      rb_str = rb_str_export_to_enc(rb_str, default_internal_enc);
    }
#endif
    xfree(newStr);
    return rb_str;
  }
}
开发者ID:jaylane,项目名称:mysql2,代码行数:49,代码来源:client.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ rb_define_alloc_func函数代码示例发布时间:2022-05-30
下一篇:
C++ rb_debug函数代码示例发布时间: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