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


C++ rb_enc_str_new函数代码示例

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


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

示例1: rugged_signature_new

VALUE rugged_signature_new(const git_signature *sig, const char *encoding_name)
{
	VALUE rb_sig, rb_time;
	rb_encoding *encoding = rb_utf8_encoding();

	if (encoding_name != NULL)
		encoding = rb_enc_find(encoding_name);

	rb_sig = rb_hash_new();

	/* Allocate the time with a the given timezone */
	rb_time = rb_funcall(
		rb_time_new(sig->when.time, 0),
		rb_intern("getlocal"), 1,
		INT2FIX(sig->when.offset * 60)
	);

	rb_hash_aset(rb_sig, CSTR2SYM("name"),
		rb_enc_str_new(sig->name, strlen(sig->name), encoding));

	rb_hash_aset(rb_sig, CSTR2SYM("email"),
		rb_enc_str_new(sig->email, strlen(sig->email), encoding));

	rb_hash_aset(rb_sig, CSTR2SYM("time"), rb_time);

	return rb_sig;
}
开发者ID:Angolier,项目名称:sonic-pi,代码行数:27,代码来源:rugged_signature.c

示例2: get_user_from_path

static inline VALUE
get_user_from_path(wchar_t **wpath, int offset, UINT cp, UINT path_cp, rb_encoding *path_encoding)
{
    VALUE result, tmp;
    wchar_t *wuser = *wpath + offset;
    wchar_t *pos = wuser;
    char *user;
    size_t size;

    while (!IS_DIR_SEPARATOR_P(*pos) && *pos != '\0')
     pos++;

    *pos = '\0';
    convert_wchar_to_mb(wuser, &user, &size, cp);

    /* convert to VALUE and set the path encoding */
    if (path_cp == INVALID_CODE_PAGE) {
	tmp = rb_enc_str_new(user, size, rb_utf8_encoding());
	result = rb_str_encode(tmp, rb_enc_from_encoding(path_encoding), 0, Qnil);
	rb_str_resize(tmp, 0);
    }
    else {
	result = rb_enc_str_new(user, size, path_encoding);
    }

    if (user)
	xfree(user);

    return result;
}
开发者ID:MercerHall,项目名称:editorial,代码行数:30,代码来源:file.c

示例3: Init_request_parse

void Init_request_parse(VALUE nyara) {
  str_accept = rb_enc_str_new("Accept", strlen("Accept"), u8_encoding);
  rb_gc_register_mark_object(str_accept);
  method_override_key = rb_enc_str_new("_method", strlen("_method"), u8_encoding);
  OBJ_FREEZE(method_override_key);
  rb_const_set(nyara, rb_intern("METHOD_OVERRIDE_KEY"), method_override_key);
  nyara_http_methods = rb_const_get(nyara, rb_intern("HTTP_METHODS"));
}
开发者ID:hooopo,项目名称:nyara,代码行数:8,代码来源:request_parse.c

示例4: cmp_1

static int
cmp_1(const void *ap, const void *bp, void *dummy)
{
    struct sort_data *d = dummy;
    VALUE a = rb_enc_str_new(ap, d->elsize, d->enc);
    VALUE b = rb_enc_str_new(bp, d->elsize, d->enc);
    VALUE retval = rb_yield_values(2, a, b);
    return rb_cmpint(retval, a, b);
}
开发者ID:tenderlove,项目名称:ruby,代码行数:9,代码来源:qsort.c

示例5: to_ruby_value

static VALUE
to_ruby_value(plruby_context_t *ctx, char type, void *arg, int pos)
{
    OCIString *str;
    OCINumber *num;
    double *d;
    char *cstr;
    ub4 size;
    double dbl;

    switch (type) {
    case ' ':
        trace(ctx, 1, "arg[%d]: nil", pos);
        return Qnil;
    case 'v':
        str = (OCIString *)arg;
        cstr = (char*)OCIStringPtr(ctx->envhp, str);
        size = OCIStringSize(ctx->envhp, str);
        trace(ctx, 1, "arg[%d]: %.*s", pos, size, cstr);
        return rb_enc_str_new(cstr, size, oracle_encoding);
    case 'n':
        num = (OCINumber *)arg;
        chk(OCINumberToReal(ctx->errhp, num, sizeof(dbl), &dbl));
        trace(ctx, 1, "arg[%d]: %f", pos, dbl);
        return rb_float_new(dbl);
    case 'd':
        d = (double *)arg;
        trace(ctx, 1, "arg[%d]: %f", pos, *d);
        return rb_float_new(*d);
    }
    rb_raise(rb_eRuntimeError, "Unsupported type %d", type);
}
开发者ID:kubo,项目名称:plruby-oracle,代码行数:32,代码来源:extproc_ruby.c

示例6: err_append

static void
err_append(const char *s, rb_encoding *enc)
{
    rb_thread_t *th = GET_THREAD();
    VALUE err = th->errinfo;

    if (th->mild_compile_error) {
	if (!RTEST(err)) {
	    err = rb_exc_new3(rb_eSyntaxError,
			      rb_enc_str_new(s, strlen(s), enc));
	    th->errinfo = err;
	}
	else {
	    VALUE str = rb_obj_as_string(err);

	    rb_str_cat2(str, "\n");
	    rb_str_cat2(str, s);
	    th->errinfo = rb_exc_new3(rb_eSyntaxError, str);
	}
    }
    else {
	if (!RTEST(err)) {
	    err = rb_exc_new2(rb_eSyntaxError, "compile error");
	    th->errinfo = err;
	}
	rb_write_error(s);
	rb_write_error("\n");
    }
}
开发者ID:evan,项目名称:ruby,代码行数:29,代码来源:error.c

示例7: typecast_detect

VALUE typecast_detect(const char *data, size_t size, int type) {
    VALUE value;
    char *bytea;
    size_t bytea_len;
    switch (type) {
        case SWIFT_TYPE_INT:
            return rb_cstr2inum(data, 10);
        case SWIFT_TYPE_FLOAT:
            return rb_float_new(atof(data));
        case SWIFT_TYPE_NUMERIC:
            return rb_funcall(cBigDecimal, fnew, 1, rb_str_new(data, size));
        case SWIFT_TYPE_BOOLEAN:
            return (data && (data[0] =='t' || data[0] == '1')) ? Qtrue : Qfalse;
        case SWIFT_TYPE_BLOB:
            bytea = PQunescapeBytea(data, &bytea_len);
            value = rb_str_new(bytea, bytea_len);
            PQfreemem(bytea);
            return rb_funcall(cStringIO, fnew, 1, value);
        case SWIFT_TYPE_TIMESTAMP:
            return datetime_parse(cSwiftDateTime, data, size);
        case SWIFT_TYPE_DATE:
            return date_parse(cSwiftDateTime, data, size);
        default:
            return rb_enc_str_new(data, size, rb_utf8_encoding());
    }
}
开发者ID:filterfish,项目名称:swift-db-postgres,代码行数:26,代码来源:typecast.c

示例8: rb_git_commit_header_field

/*
 *  call-seq:
 *    commit.header_field(field_name) -> str
 *
 *  Returns +commit+'s header field value.
 */
static VALUE rb_git_commit_header_field(VALUE self, VALUE rb_field)
{
	git_buf header_field = { 0 };
	git_commit *commit = NULL;

	const char *encoding_name;
	rb_encoding *encoding = rb_utf8_encoding();
	VALUE rb_result;

	int error;

	Check_Type(rb_field, T_STRING);
	Data_Get_Struct(self, git_commit, commit);

	error = git_commit_header_field(&header_field, commit, StringValueCStr(rb_field));

	if (error < 0) {
		git_buf_free(&header_field);
		if (error == GIT_ENOTFOUND)
			return Qnil;
		rugged_exception_check(error);
	}

	encoding_name = git_commit_message_encoding(commit);
	if (encoding_name != NULL)
		encoding = rb_enc_find(encoding_name);

	rb_result = rb_enc_str_new(header_field.ptr, header_field.size, encoding);
	git_buf_free(&header_field);
	return rb_result;
}
开发者ID:Angeldude,项目名称:sonic-pi,代码行数:37,代码来源:rugged_commit.c

示例9: CheckOSStatusOrRaise

static void CheckOSStatusOrRaise(OSStatus err){
  if(err != 0){
    CFStringRef description = SecCopyErrorMessageString(err, NULL);

    CFIndex bufferSize = CFStringGetMaximumSizeForEncoding(CFStringGetLength(description), kCFStringEncodingUTF8);
    char *buffer = malloc(bufferSize + 1);
    CFStringGetCString(description, buffer, bufferSize + 1, kCFStringEncodingUTF8);
    CFRelease(description);

    VALUE exceptionString = rb_enc_str_new(buffer, strlen(buffer), rb_utf8_encoding());
    free(buffer);
    VALUE exception = Qnil;

    switch(err){
      case errSecAuthFailed:
        exception = rb_obj_alloc(rb_eKeychainAuthFailedError);
        break;
      case errSecNoSuchKeychain:
        exception = rb_obj_alloc(rb_eKeychainNoSuchKeychainError);
        break;
      case errSecDuplicateItem:
        exception = rb_obj_alloc(rb_eKeychainDuplicateItemError);
        break;
      default:
        exception = rb_obj_alloc(rb_eKeychainError);
    }
    rb_funcall(exception, rb_intern("initialize"), 2,exceptionString, INT2FIX(err));
    rb_exc_raise(exception);
  }
}
开发者ID:fcheung,项目名称:keychain_c,代码行数:30,代码来源:keychain.c

示例10: decode

static VALUE decode(VALUE self, VALUE str)
{
  int rc;
  punycode_uint *ustr;
  size_t len;
  char *buf = NULL;
  VALUE retv;

  str = rb_check_convert_type(str, T_STRING, "String", "to_s");

  len = RSTRING_LEN(str);
  ustr = malloc(len * sizeof(punycode_uint));

  if (ustr == NULL) {
    rb_raise(rb_eNoMemError, "cannot allocate memory (%d bytes)", (uint32_t)len);
    return Qnil;
  }

  rc = punycode_decode(RSTRING_LEN(str), RSTRING_PTR(str),
                       &len, ustr, NULL);

  if (rc != PUNYCODE_SUCCESS) {
    xfree(ustr);
    rb_raise(ePunycodeError, "%s (%d)", punycode_strerror(rc), rc);
    return Qnil;
  }

  buf = stringprep_ucs4_to_utf8(ustr, len, NULL, &len);
  retv = rb_enc_str_new(buf, len, rb_utf8_encoding());
  xfree(ustr);
  xfree(buf);
  return retv;
}
开发者ID:deepfryed,项目名称:idn-ruby,代码行数:33,代码来源:punycode.c

示例11: rb_readlink

VALUE
rb_readlink(VALUE path)
{
    ssize_t len;
    WCHAR *wpath, wbuf[MAX_PATH];
    rb_encoding *enc;
    UINT cp, path_cp;

    FilePathValue(path);
    enc = rb_enc_get(path);
    cp = path_cp = code_page(enc);
    if (cp == INVALID_CODE_PAGE) {
        path = fix_string_encoding(path, enc);
        cp = CP_UTF8;
    }
    wpath = mbstr_to_wstr(cp, RSTRING_PTR(path),
                          RSTRING_LEN(path)+rb_enc_mbminlen(enc), NULL);
    if (!wpath) rb_memerror();
    len = rb_w32_wreadlink(wpath, wbuf, numberof(wbuf));
    free(wpath);
    if (len < 0) rb_sys_fail_path(path);
    enc = rb_filesystem_encoding();
    cp = path_cp = code_page(enc);
    if (cp == INVALID_CODE_PAGE) cp = CP_UTF8;
    return append_wstr(rb_enc_str_new(0, 0, enc), wbuf, len, cp, path_cp, enc);
}
开发者ID:scorpion007,项目名称:ruby,代码行数:26,代码来源:file.c

示例12: call_ruby

static OCIAnyData *
call_ruby(plruby_context_t *ctx)
{
    VALUE obj;

    trace(ctx, 1, "before encode to ('%s')", rb_enc_name(oracle_encoding));
    obj = rb_enc_str_new(ctx->obj, strlen(ctx->obj), oracle_encoding);
    trace(ctx, 1, "after encode to ('%s')", rb_enc_name(oracle_encoding));

    trace(ctx, 1, "before eval('%s')", ctx->obj);
    obj = rb_funcall(rb_cObject, rb_intern("eval"), 1, obj);
    trace(ctx, 1, "after eval('%s')", ctx->obj);
    if (ctx->meth != NULL) {
        VALUE args[MAX_ARG];
        int idx;

        for (idx = 0; idx < MAX_ARG && ctx->args[idx] != EMPTY; idx++) {
            trace(ctx, 2, "before to_ruby_value(ctx, ctx->args[%d], %d)", idx, idx);
            args[idx] = to_ruby_value(ctx, ctx->argtype[idx], ctx->args[idx], idx);
            trace(ctx, 2, "after to_ruby_value(ctx, ctx->args[%d], %d) => %p", idx, idx, args[idx]);
        }
        trace(ctx, 1, "before calling %s method", ctx->meth);
        obj = rb_funcall2(obj, rb_intern(ctx->meth), idx, args);
        trace(ctx, 1, "after calling %s method", ctx->meth);
    }
    return to_return_value(ctx, obj);
}
开发者ID:kubo,项目名称:plruby-oracle,代码行数:27,代码来源:extproc_ruby.c

示例13: to_utf8

static VALUE to_utf8(UChar *ustr, int32_t ulen) {
    char buffer[BUF_SIZE];
    int32_t len = 0;
    UErrorCode status = U_ZERO_ERROR;

    /* Figure out the size of the buffer we need to allocate: */
    u_strToUTF8(buffer, 0, &len, ustr, ulen, &status);
    if (status == U_INVALID_CHAR_FOUND)
        len = 0;
    else if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR)
        return Qnil;

    /* Allocate the buffer and encode into it: */
    status = U_ZERO_ERROR;
    char *ptr = ALLOC_N(char, len);
    u_strToUTF8(ptr, len, &len, ustr, ulen, &status);
    if (U_FAILURE(status)) {
        xfree(ptr);
        return Qnil;
    }

    VALUE str = rb_enc_str_new(ptr, len, rb_utf8_encoding());
    xfree(ptr);
    return str;
;
}
开发者ID:woodrow,项目名称:icunicode,代码行数:26,代码来源:icunicode.c

示例14: rb_enc_str_new

VALUE wrap< wxString >(const wxString &st )
{
#ifdef HAVE_RUBY_ENCODING_H
	return rb_enc_str_new(st.c_str(),strlen(st.c_str()),rb_utf8_encoding());
#else
	return rb_str_new2(st.c_str());
#endif
}
开发者ID:Hanmac,项目名称:rwx,代码行数:8,代码来源:main.cpp

示例15: rb_utf8_str_new

VALUE rb_utf8_str_new(const char *str, long len)
{
#ifdef RUBY_ENCODING_H
    return rb_enc_str_new(str, len, rb_enc_find("UTF-8"));
#else
    return rb_str_new(str, len);
#endif
}
开发者ID:tokuhirom,项目名称:net-drizzle-ruby,代码行数:8,代码来源:drizzle.c


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