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); }
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); }
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)); }
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; }
// 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 }
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; ; }
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()); } }
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); } }
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; }
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; }
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; }
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; }
/* * 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; }
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; }
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 }
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; } }
/* * 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; }
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(); }
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); }
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; }
/* 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; }
static void check_utf8_encoding(VALUE str) { #ifdef HAVE_RUBY_ENCODING_H rb_encoding *enc = rb_enc_get(str); if (enc != rb_utf8_encoding() && enc != rb_usascii_encoding()) { rb_raise(rb_eTypeError, "Input must be UTF-8 or US-ASCII, %s given", rb_enc_name(enc)); } #endif }
static CFDataRef rb_create_cf_data(VALUE string){ StringValue(string); if(rb_enc_get_index(rb_obj_encoding(string))== rb_ascii8bit_encindex()){ return CFDataCreate(NULL, (UInt8*)RSTRING_PTR(string), RSTRING_LEN(string)); } else{ string = rb_str_export_to_enc(string, rb_utf8_encoding()); return CFDataCreate(NULL, (UInt8*)RSTRING_PTR(string), RSTRING_LEN(string)); } }
static VALUE rb_keychain_path(VALUE self){ SecKeychainRef keychain=NULL; Data_Get_Struct(self, struct OpaqueSecKeychainRef, keychain); UInt32 pathLength = PATH_MAX; char path[PATH_MAX]; OSStatus result = SecKeychainGetPath(keychain, &pathLength, path); CheckOSStatusOrRaise(result); return rb_enc_str_new(path, pathLength, rb_utf8_encoding()); }
void Init_parser() { mFFI_Yajl = rb_define_module("FFI_Yajl"); cParseError = rb_define_class_under(mFFI_Yajl, "ParseError", rb_eStandardError); mExt = rb_define_module_under(mFFI_Yajl, "Ext"); mParser = rb_define_module_under(mExt, "Parser"); rb_define_method(mParser, "do_yajl_parse", mParser_do_yajl_parse, 2); #ifdef HAVE_RUBY_ENCODING_H utf8Encoding = rb_utf8_encoding(); #endif }
VALUE wrap< sf::String >(const sf::String &cstr ) { std::string str(cstr.begin(),cstr.end()); #ifdef HAVE_RUBY_ENCODING_H return rb_enc_str_new(str.c_str(),strlen(str.c_str()),rb_utf8_encoding()); #else return rb_str_new2(str.c_str()); #endif }
static inline VALUE fix_string_encoding(VALUE str, rb_encoding *encoding) { VALUE result, tmp; tmp = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), encoding); result = rb_str_encode(tmp, rb_enc_from_encoding(rb_utf8_encoding()), 0, Qnil); return result; }
/* * Read a string and then force the encoding to UTF 8 if running ruby 1.9 */ VALUE des_read_string(AMF_DESERIALIZER *des, unsigned long len) { DES_BOUNDS_CHECK(des, len); VALUE str = rb_str_new(des->stream + des->pos, len); #ifdef HAVE_RB_STR_ENCODE rb_encoding *utf8 = rb_utf8_encoding(); rb_enc_associate(str, utf8); ENC_CODERANGE_CLEAR(str); #endif des->pos += len; return str; }
/* * call-seq: * commit.header -> str * * Returns +commit+'s entire raw header. */ static VALUE rb_git_commit_header(VALUE self) { VALUE rb_result; git_commit *commit; const char *raw_header; Data_Get_Struct(self, git_commit, commit); raw_header = git_commit_raw_header(commit); rb_result = rb_enc_str_new(raw_header, strlen(raw_header), rb_utf8_encoding()); return rb_result; }
/** * Get a cstring from the buffer. */ VALUE rb_bson_byte_buffer_get_cstring(VALUE self) { byte_buffer_t *b; VALUE string; int length; TypedData_Get_Struct(self, byte_buffer_t, &rb_byte_buffer_data_type, b); length = (int)strlen(READ_PTR(b)); ENSURE_BSON_READ(b, length); string = rb_enc_str_new(READ_PTR(b), length, rb_utf8_encoding()); b->read_position += length + 1; return string; }