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

C++ rb_str_export_to_enc函数代码示例

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

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



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

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


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


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


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


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


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


示例7: rb_yajl_encoder_new

/*
 * Document-method: new
 *
 * call-seq: initialize([:pretty => false[, :indent => '  '][, :terminator => "\n"]])
  *
  * :pretty will enable/disable beautifying or "pretty priting" the output string.
  *
  * :indent is the character(s) used to indent the output string.
  *
  * :terminator allows you to specify a character to be used as the termination character after a full JSON string has been generated by
  * the encoder. This would be especially useful when encoding in chunks (via a block or callback during the encode process), to be able to
  * determine when the last chunk of the current encode is sent.
  * If you specify this option to be nil, it will be ignored if encoding directly to an IO or simply returning a string. But if a block is used,
  * the encoder will still pass it - I hope that makes sense ;).
 */
static VALUE rb_yajl_encoder_new(int argc, VALUE * argv, VALUE klass) {
    yajl_encoder_wrapper * wrapper;
    yajl_gen_config cfg;
    VALUE opts, obj, indent;
    unsigned char *indentString = NULL, *actualIndent = NULL;
    int beautify = 0, htmlSafe = 0;

    /* Scan off config vars */
    if (rb_scan_args(argc, argv, "01", &opts) == 1) {
        Check_Type(opts, T_HASH);

        if (rb_hash_aref(opts, sym_pretty) == Qtrue) {
            beautify = 1;
            indent = rb_hash_aref(opts, sym_indent);
            if (indent != Qnil) {
#ifdef HAVE_RUBY_ENCODING_H
                indent = rb_str_export_to_enc(indent, utf8Encoding);
#endif
                Check_Type(indent, T_STRING);
                indentString = (unsigned char*)malloc(RSTRING_LEN(indent)+1);
                memcpy(indentString, RSTRING_PTR(indent), RSTRING_LEN(indent));
                indentString[RSTRING_LEN(indent)] = '\0';
                actualIndent = indentString;
            }
        }
        if (rb_hash_aref(opts, sym_html_safe) == Qtrue) {
          htmlSafe = 1;
        }
    }
    if (!indentString) {
      indentString = defaultIndentString;
    }
    cfg = (yajl_gen_config){beautify, (const char *)indentString, htmlSafe};

    obj = Data_Make_Struct(klass, yajl_encoder_wrapper, yajl_encoder_wrapper_mark, yajl_encoder_wrapper_free, wrapper);
    wrapper->indentString = actualIndent;
    wrapper->encoder = yajl_gen_alloc(&cfg, NULL);
    wrapper->on_progress_callback = Qnil;
    if (opts != Qnil && rb_funcall(opts, intern_has_key, 1, sym_terminator) == Qtrue) {
        wrapper->terminator = rb_hash_aref(opts, sym_terminator);
#ifdef HAVE_RUBY_ENCODING_H
        if (TYPE(wrapper->terminator) == T_STRING) {
            wrapper->terminator = rb_str_export_to_enc(wrapper->terminator, utf8Encoding);
        }
#endif
    } else {
        wrapper->terminator = 0;
    }
    rb_obj_call_init(obj, 0, 0);
    return obj;
}
开发者ID:curtosis,项目名称:lucite,代码行数:66,代码来源:yajl_ext.c


示例8: rb_yajl_encoder_new

static VALUE rb_yajl_encoder_new(int argc, VALUE * argv, VALUE klass) {
    yajl_encoder_wrapper * wrapper;
    yajl_gen_config cfg;
    VALUE opts, obj, indent;
    const char * indentString = "  ";
    int beautify = 0;
    int ascii_only = default_to_ascii_only == Qtrue ? 1 : 0;

    /* Scan off config vars */
    if (rb_scan_args(argc, argv, "01", &opts) == 1) {
        Check_Type(opts, T_HASH);

        if (rb_hash_aref(opts, sym_pretty) == Qtrue) {
            beautify = 1;
            indent = rb_hash_aref(opts, sym_indent);
            if (indent != Qnil) {
#ifdef HAVE_RUBY_ENCODING_H
                indent = rb_str_export_to_enc(indent, utf8Encoding);
#endif
                Check_Type(indent, T_STRING);
                indentString = RSTRING_PTR(indent);
            }
        }

        if (rb_hash_aref(opts, sym_ascii_only) == Qtrue) {
            ascii_only= 1;
        }
        if (rb_hash_aref(opts, sym_ascii_only) == Qfalse) {
            ascii_only= 0;
        }

    }
    cfg = (yajl_gen_config){beautify, indentString, ascii_only};

    obj = Data_Make_Struct(klass, yajl_encoder_wrapper, yajl_encoder_wrapper_mark, yajl_encoder_wrapper_free, wrapper);
    wrapper->encoder = yajl_gen_alloc(&cfg, NULL);
    wrapper->on_progress_callback = Qnil;
    if (opts != Qnil && rb_funcall(opts, intern_has_key, 1, sym_terminator) == Qtrue) {
        wrapper->terminator = rb_hash_aref(opts, sym_terminator);
#ifdef HAVE_RUBY_ENCODING_H
        if (TYPE(wrapper->terminator) == T_STRING) {
            wrapper->terminator = rb_str_export_to_enc(wrapper->terminator, utf8Encoding);
        }
#endif
    } else {
        wrapper->terminator = 0;
    }
    rb_obj_call_init(obj, 0, 0);
    return obj;
}
开发者ID:fcheung,项目名称:yajl-ruby,代码行数:50,代码来源:yajl_ext.c


示例9: scalar

/* call-seq: emitter.scalar(value, anchor, tag, plain, quoted, style)
 *
 * Emit a scalar with +value+, +anchor+, +tag+, and a +plain+ or +quoted+
 * string type with +style+.
 *
 * See Psych::Handler#scalar
 */
static VALUE scalar(
    VALUE self,
    VALUE value,
    VALUE anchor,
    VALUE tag,
    VALUE plain,
    VALUE quoted,
    VALUE style
) {
    yaml_emitter_t * emitter;
    yaml_event_t event;
#ifdef HAVE_RUBY_ENCODING_H
    rb_encoding *encoding;
#endif
    Data_Get_Struct(self, yaml_emitter_t, emitter);

    Check_Type(value, T_STRING);

#ifdef HAVE_RUBY_ENCODING_H
    encoding = rb_utf8_encoding();

    value = rb_str_export_to_enc(value, encoding);

    if(!NIL_P(anchor)) {
        Check_Type(anchor, T_STRING);
        anchor = rb_str_export_to_enc(anchor, encoding);
    }

    if(!NIL_P(tag)) {
        Check_Type(tag, T_STRING);
        tag = rb_str_export_to_enc(tag, encoding);
    }
#endif

    yaml_scalar_event_initialize(
        &event,
        (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValuePtr(anchor)),
        (yaml_char_t *)(NIL_P(tag) ? NULL : StringValuePtr(tag)),
        (yaml_char_t*)StringValuePtr(value),
        (int)RSTRING_LEN(value),
        plain ? 1 : 0,
        quoted ? 1 : 0,
        (yaml_scalar_style_t)NUM2INT(style)
    );

    emit(emitter, &event);

    return self;
}
开发者ID:halorgium,项目名称:rubinius,代码行数:56,代码来源:emitter.c


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


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


示例12: oci8_lob_write

/*
 * @overload write(data)
 *
 *  Writes +data+ to LOB.
 *
 *  @param [String] data
 *  @return [Integer] number of characters written if +self+ is a {CLOB} or a {NCLOB}.
 *    number of bytes written if +self+ is a {BLOB} or a {BFILE}.
 */
static VALUE oci8_lob_write(VALUE self, VALUE data)
{
    oci8_lob_t *lob = TO_LOB(self);
    oci8_svcctx_t *svcctx = check_svcctx(lob);
    volatile VALUE str;
    ub8 byte_amt;
    ub8 char_amt;

    lob_open(lob);
    if (TYPE(data) != T_STRING) {
        str = rb_obj_as_string(data);
    } else {
        str = data;
    }
    if (lob->lobtype == OCI_TEMP_CLOB) {
        str = rb_str_export_to_enc(str, oci8_encoding);
    }
    byte_amt = RSTRING_LEN(str);
    if (byte_amt == 0) {
        /* to avoid ORA-24801: illegal parameter value in OCI lob function */
        return INT2FIX(0);
    }
    char_amt = 0;
    chker2(OCILobWrite2_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &byte_amt, &char_amt, lob->pos + 1, RSTRING_PTR(str), byte_amt, OCI_ONE_PIECE, NULL, NULL, 0, lob->csfrm),
           &svcctx->base);
    RB_GC_GUARD(str);
    if (lob->lobtype == OCI_TEMP_CLOB) {
        lob->pos += char_amt;
        return UINT2NUM(char_amt);
    } else {
        lob->pos += byte_amt;
        return UINT2NUM(byte_amt);
    }
}
开发者ID:Captnwalker1,项目名称:ruby-oci8,代码行数:43,代码来源:lob.c


示例13: sdl2r_ttf_render_utf8_blended

static VALUE sdl2r_ttf_render_utf8_blended(VALUE klass, VALUE vfont, VALUE vtext, VALUE vcolor)
{
    struct SDL2RFont *fnt = SDL2R_GET_FONT_STRUCT(vfont);
    SDL_Color col;
    VALUE vsurface = sdl2r_surface_alloc(cSurface);
    struct SDL2RSurface *sur = SDL2R_GET_STRUCT(Surface, vsurface);

    Check_Type(vtext, T_STRING);
    if (rb_enc_get_index(vtext) != 0) {
        vtext = rb_str_export_to_enc(vtext, g_enc_utf8);
    }

    Check_Type(vcolor, T_ARRAY);
    col.r = NUM2INT(rb_ary_entry(vcolor, 0));
    col.g = NUM2INT(rb_ary_entry(vcolor, 1));
    col.b = NUM2INT(rb_ary_entry(vcolor, 2));
    col.a = NUM2INT(rb_ary_entry(vcolor, 3));

    sur->surface = TTF_RenderUTF8_Blended(fnt->font, RSTRING_PTR(vtext), col);
    if (!sur->surface) {
        rb_raise(eSDLError, TTF_GetError());
    }

    return vsurface;
}
开发者ID:ymmtmdk,项目名称:sdl2r.gem,代码行数:25,代码来源:sdl2r_ttf.c


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


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


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


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


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


示例19: initialize

/* call-seq: SQLite3::Database.new(file, options = {})
 *
 * Create a new Database object that opens the given file. If utf16
 * is +true+, the filename is interpreted as a UTF-16 encoded string.
 *
 * By default, the new database will return result rows as arrays
 * (#results_as_hash) and has type translation disabled (#type_translation=).
 */
static VALUE initialize(int argc, VALUE *argv, VALUE self)
{
  sqlite3RubyPtr ctx;
  VALUE file;
  VALUE opts;
  VALUE zvfs;
  int status;

  Data_Get_Struct(self, sqlite3Ruby, ctx);

  rb_scan_args(argc, argv, "12", &file, &opts, &zvfs);
  if(NIL_P(opts)) opts = rb_hash_new();

#ifdef HAVE_RUBY_ENCODING_H
  if(UTF16_LE_P(file)) {
    status = sqlite3_open16(utf16_string_value_ptr(file), &ctx->db);
  } else {
#endif

    if(Qtrue == rb_hash_aref(opts, sym_utf16)) {
      status = sqlite3_open16(utf16_string_value_ptr(file), &ctx->db);
    } else {

#ifdef HAVE_RUBY_ENCODING_H
      if(!UTF8_P(file)) {
        file = rb_str_export_to_enc(file, rb_utf8_encoding());
      }
#endif

      status = sqlite3_open_v2(
          StringValuePtr(file),
          &ctx->db,
          SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
          NIL_P(zvfs) ? NULL : StringValuePtr(zvfs)
      );
    }

#ifdef HAVE_RUBY_ENCODING_H
  }
#endif

  CHECK(ctx->db, status)

  rb_iv_set(self, "@tracefunc", Qnil);
  rb_iv_set(self, "@authorizer", Qnil);
  rb_iv_set(self, "@encoding", Qnil);
  rb_iv_set(self, "@busy_handler", Qnil);
  rb_iv_set(self, "@results_as_hash", rb_hash_aref(opts, sym_results_as_hash));
  rb_iv_set(self, "@type_translation", rb_hash_aref(opts, sym_type_translation));

  if(rb_block_given_p()) {
    rb_yield(self);
    rb_funcall(self, rb_intern("close"), 0);
  }

  return self;
}
开发者ID:kashif,项目名称:sqlite3-ruby,代码行数:65,代码来源:database.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_str_export_to_enc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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