本文整理汇总了C++中rb_utf8_encoding函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_utf8_encoding函数的具体用法?C++ rb_utf8_encoding怎么用?C++ rb_utf8_encoding使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_utf8_encoding函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: 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
示例2: 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
示例3: Init_nkf
void
Init_nkf()
{
VALUE mNKF = rb_define_module("NKF");
rb_define_module_function(mNKF, "nkf", rb_nkf_convert, 2);
rb_define_module_function(mNKF, "guess", rb_nkf_guess, 1);
rb_define_alias(rb_singleton_class(mNKF), "guess", "guess");
rb_define_const(mNKF, "AUTO", Qnil);
rb_define_const(mNKF, "NOCONV", Qnil);
rb_define_const(mNKF, "UNKNOWN", Qnil);
rb_define_const(mNKF, "BINARY", rb_enc_from_encoding(rb_nkf_enc_get("BINARY")));
rb_define_const(mNKF, "ASCII", rb_enc_from_encoding(rb_nkf_enc_get("US-ASCII")));
rb_define_const(mNKF, "JIS", rb_enc_from_encoding(rb_nkf_enc_get("ISO-2022-JP")));
rb_define_const(mNKF, "EUC", rb_enc_from_encoding(rb_nkf_enc_get("EUC-JP")));
rb_define_const(mNKF, "SJIS", rb_enc_from_encoding(rb_nkf_enc_get("Shift_JIS")));
rb_define_const(mNKF, "UTF8", rb_enc_from_encoding(rb_utf8_encoding()));
rb_define_const(mNKF, "UTF16", rb_enc_from_encoding(rb_nkf_enc_get("UTF-16BE")));
rb_define_const(mNKF, "UTF32", rb_enc_from_encoding(rb_nkf_enc_get("UTF-32BE")));
/* Full version string of nkf */
rb_define_const(mNKF, "VERSION", rb_str_new2(RUBY_NKF_VERSION));
/* Version of nkf */
rb_define_const(mNKF, "NKF_VERSION", rb_str_new2(NKF_VERSION));
/* Release date of nkf */
rb_define_const(mNKF, "NKF_RELEASE_DATE", rb_str_new2(NKF_RELEASE_DATE));
}
开发者ID:alloy,项目名称:mr-experimental,代码行数:28,代码来源:nkf.c
示例4: 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
示例5: Init_streamly_ext
// Ruby Extension initializer
void Init_streamly_ext() {
mStreamly = rb_define_module("Streamly");
cRequest = rb_define_class_under(mStreamly, "Request", rb_cObject);
rb_define_singleton_method(cRequest, "new", rb_streamly_new, -1);
rb_define_method(cRequest, "initialize", rb_streamly_init, -1);
rb_define_method(cRequest, "execute", rb_streamly_execute, -1);
eStreamlyError = rb_define_class_under(mStreamly, "Error", rb_eStandardError);
eUnsupportedProtocol = rb_define_class_under(mStreamly, "UnsupportedProtocol", rb_eStandardError);
eURLFormatError = rb_define_class_under(mStreamly, "URLFormatError", rb_eStandardError);
eHostResolutionError = rb_define_class_under(mStreamly, "HostResolutionError", rb_eStandardError);
eConnectionFailed = rb_define_class_under(mStreamly, "ConnectionFailed", rb_eStandardError);
ePartialFileError = rb_define_class_under(mStreamly, "PartialFileError", rb_eStandardError);
eTimeoutError = rb_define_class_under(mStreamly, "TimeoutError", rb_eStandardError);
eTooManyRedirects = rb_define_class_under(mStreamly, "TooManyRedirects", rb_eStandardError);
sym_method = ID2SYM(rb_intern("method"));
sym_url = ID2SYM(rb_intern("url"));
sym_payload = ID2SYM(rb_intern("payload"));
sym_headers = ID2SYM(rb_intern("headers"));
sym_head = ID2SYM(rb_intern("head"));
sym_get = ID2SYM(rb_intern("get"));
sym_post = ID2SYM(rb_intern("post"));
sym_put = ID2SYM(rb_intern("put"));
sym_delete = ID2SYM(rb_intern("delete"));
sym_username = ID2SYM(rb_intern("username"));
sym_password = ID2SYM(rb_intern("password"));
sym_response_header_handler = ID2SYM(rb_intern("response_header_handler"));
sym_response_body_handler = ID2SYM(rb_intern("response_body_handler"));
#ifdef HAVE_RUBY_ENCODING_H
utf8Encoding = rb_utf8_encoding();
#endif
}
开发者ID:brianmario,项目名称:streamly,代码行数:36,代码来源:streamly.c
示例6: 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
示例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: 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
示例9: 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
示例10: 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
示例11: 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
示例12: 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
示例13: 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
示例14: 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
示例15: 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
示例16: cfstring_to_rb_string
static VALUE cfstring_to_rb_string(CFStringRef s){
if(CFStringGetTypeID() != CFGetTypeID(s)){
rb_raise(rb_eTypeError, "Non cfstring passed to cfstring_to_rb_string");
}
const char * fastBuffer = CFStringGetCStringPtr(s, kCFStringEncodingUTF8);
if(fastBuffer){
return rb_enc_str_new(fastBuffer, strlen(fastBuffer), rb_utf8_encoding());
}else{
CFIndex bufferLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(s),kCFStringEncodingUTF8);
char * buffer = malloc(bufferLength);
CFIndex used = 0;
CFStringGetBytes(s,CFRangeMake(0, CFStringGetLength(s)), kCFStringEncodingUTF8, 0, false, (UInt8*)buffer, bufferLength, &used);
VALUE rb_string = rb_enc_str_new(buffer, used, rb_utf8_encoding());
free(buffer);
return rb_string;
}
}
开发者ID:fcheung,项目名称:keychain_c,代码行数:17,代码来源:keychain.c
示例17: rb_git_commit_to_mbox
/*
* call-seq:
* commit.to_mbox(options = {}) -> str
*
* Returns +commit+'s contents formatted to resemble UNIX mailbox format.
*
* Does not (yet) support merge commits.
*
* The following options can be passed in the +options+ Hash:
*
* :patch_no ::
* Number for this patch in the series. Defaults to +1+.
*
* :total_patches ::
* Total number of patches in the series. Defaults to +1+.
*
* :exclude_subject_patch_marker ::
* If set to true, no "[PATCH]" marker will be
* added to the beginning of the subject line.
*
* Additionally, you can also pass the same options as for Rugged::Tree#diff.
*/
static VALUE rb_git_commit_to_mbox(int argc, VALUE *argv, VALUE self)
{
git_buf email_patch = { NULL };
git_repository *repo;
git_commit *commit;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_format_email_flags_t flags = GIT_DIFF_FORMAT_EMAIL_NONE;
VALUE rb_repo = rugged_owner(self), rb_email_patch = Qnil, rb_val, rb_options;
int error;
size_t patch_no = 1, total_patches = 1;
rb_scan_args(argc, argv, ":", &rb_options);
rugged_check_repo(rb_repo);
Data_Get_Struct(rb_repo, git_repository, repo);
Data_Get_Struct(self, git_commit, commit);
if (!NIL_P(rb_options)) {
Check_Type(rb_options, T_HASH);
rb_val = rb_hash_aref(rb_options, CSTR2SYM("patch_no"));
if (!NIL_P(rb_val))
patch_no = NUM2INT(rb_val);
rb_val = rb_hash_aref(rb_options, CSTR2SYM("total_patches"));
if (!NIL_P(rb_val))
total_patches = NUM2INT(rb_val);
if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("exclude_subject_patch_marker"))))
flags |= GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER;
rugged_parse_diff_options(&opts, rb_options);
}
error = git_diff_commit_as_email(
&email_patch,
repo,
commit,
patch_no,
total_patches,
flags,
&opts);
if (error) goto cleanup;
rb_email_patch = rb_enc_str_new(email_patch.ptr, email_patch.size, rb_utf8_encoding());
cleanup:
xfree(opts.pathspec.strings);
git_buf_free(&email_patch);
rugged_exception_check(error);
return rb_email_patch;
}
开发者ID:jacobvosmaer,项目名称:rugged,代码行数:80,代码来源:rugged_commit.c
示例18: mriBindingExecute
static void mriBindingExecute()
{
/* Normally only a ruby executable would do a sysinit,
* but not doing it will lead to crashes due to closed
* stdio streams on some platforms (eg. Windows) */
int argc = 0;
char **argv = 0;
ruby_sysinit(&argc, &argv);
ruby_setup();
rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding()));
Config &conf = shState->rtData().config;
if (!conf.rubyLoadpaths.empty())
{
/* Setup custom load paths */
VALUE lpaths = rb_gv_get(":");
for (size_t i = 0; i < conf.rubyLoadpaths.size(); ++i)
{
std::string &path = conf.rubyLoadpaths[i];
VALUE pathv = rb_str_new(path.c_str(), path.size());
rb_ary_push(lpaths, pathv);
}
}
RbData rbData;
shState->setBindingData(&rbData);
BacktraceData btData;
mriBindingInit();
STEAMSHIM_init();
_rb_define_module_function(rb_mKernel, "_steam_achievement_unlock",
_steamAchievementUnlock);
std::string &customScript = conf.customScript;
if (!customScript.empty())
runCustomScript(customScript);
else
runRMXPScripts(btData);
VALUE exc = rb_errinfo();
if (!NIL_P(exc) && !rb_obj_is_kind_of(exc, rb_eSystemExit))
showExc(exc, btData);
ruby_cleanup(0);
STEAMSHIM_deinit();
shState->rtData().rqTermAck.set();
}
开发者ID:Ancurio,项目名称:mkxp-abs,代码行数:58,代码来源:binding-mri.cpp
示例19: mochilo_pack_str
void mochilo_pack_str(mochilo_buf *buf, VALUE rb_str)
{
long size = RSTRING_LEN(rb_str);
rb_encoding *encoding;
const struct mochilo_enc_map *enc2id;
const char *enc_name;
encoding = rb_enc_get(rb_str);
enc_name = rb_enc_name(encoding);
if (encoding == rb_utf8_encoding()) {
// use str type from msgpack spec
if (size < 0x20) {
uint8_t lead = 0xa0 | size;
mochilo_buf_putc(buf, lead);
} else if (size < 0x100) {
uint8_t lead = size;
mochilo_buf_putc(buf, MSGPACK_T_STR8);
mochilo_buf_putc(buf, lead);
} else if (size < 0x10000) {
uint16_t lead = size;
mochilo_buf_putc(buf, MSGPACK_T_STR16);
mochilo_buf_put16be(buf, &lead);
} else if (size < 0x100000000) {
mochilo_buf_putc(buf, MSGPACK_T_STR32);
mochilo_buf_put32be(buf, &size);
} else {
// there is no str 64
rb_raise(rb_eMochiloPackError,
"String cannot be larger than %ld bytes", 0x100000000);
}
} else {
// if another encoding is used we need to use our custom types
if (size < 0x100) {
uint8_t lead = size;
mochilo_buf_putc(buf, MSGPACK_T_ENC8);
mochilo_buf_putc(buf, lead);
} else if (size < 0x10000) {
uint16_t lead = size;
mochilo_buf_putc(buf, MSGPACK_T_ENC16);
mochilo_buf_put16be(buf, &lead);
} else if (size < 0x100000000) {
mochilo_buf_putc(buf, MSGPACK_T_ENC32);
mochilo_buf_put32be(buf, &size);
} else {
// there is no ext 64
rb_raise(rb_eMochiloPackError,
"String cannot be larger than %ld bytes", 0x100000000);
}
enc2id = mochilo_encoding_to_id(enc_name, (unsigned int)strlen(enc_name));
mochilo_buf_putc(buf, enc2id ? enc2id->id : 0);
}
mochilo_buf_put(buf, RSTRING_PTR(rb_str), size);
}
开发者ID:bkeepers,项目名称:mochilo,代码行数:57,代码来源:mochilo_pack.c
示例20: rbgutil_string_set_utf8_encoding
VALUE
rbgutil_string_set_utf8_encoding(VALUE string)
{
#ifdef HAVE_RUBY_ENCODING_H
if (!NIL_P(string))
rb_enc_associate(string, rb_utf8_encoding());
#endif
return string;
}
开发者ID:benolee,项目名称:ruby-gnome2,代码行数:9,代码来源:rbgutil.c
注:本文中的rb_utf8_encoding函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论