本文整理汇总了C++中Converter::get_converter方法的典型用法代码示例。如果您正苦于以下问题:C++ Converter::get_converter方法的具体用法?C++ Converter::get_converter怎么用?C++ Converter::get_converter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Converter
的用法示例。
在下文中一共展示了Converter::get_converter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: primitive_convert
Symbol* Converter::primitive_convert(STATE, Object* source, String* target,
Fixnum* offset, Fixnum* size, Fixnum* options) {
String* src = 0;
if(!source->nil_p()) {
if(!(src = try_as<String>(source))) {
return force_as<Symbol>(Primitives::failure());
}
}
Converter* self = this;
OnStack<4> os(state, self, source, src, target);
const unsigned char* source_ptr = 0;
const unsigned char* source_end = 0;
native_int byte_offset = offset->to_native();
native_int byte_size = size->to_native();
retry:
if(!self->converter_) {
size_t num_converters = self->converters()->size();
self->set_converter(rb_econv_alloc(num_converters));
for(size_t i = 0; i < num_converters; i++) {
Transcoding* transcoding = as<Transcoding>(self->converters()->get(state, i));
rb_transcoder* tr = transcoding->get_transcoder();
if(rb_econv_add_transcoder_at(self->converter_, tr, i) == -1) {
rb_econv_free(self->get_converter());
self->set_converter(NULL);
return force_as<Symbol>(Primitives::failure());
}
}
}
/* It would be nice to have a heuristic that avoids having to reconvert
* after growing the destination buffer. This is complicated, however, as
* a converter may contain more than one transcoder. So, the heuristic
* would need to be transitive. This requires getting the encoding objects
* for every stage of the converter to check the min/max byte values.
*/
if(byte_size == -1) {
byte_size = src ? src->byte_size() : 4096;
}
int flags = self->converter_->flags = options->to_native();
if(!self->replacement()->nil_p() && !self->converter_->replacement_str) {
// First check the array's whether they exist so we don't
// leak memory or create badly initialized C structures
size_t num_converters = self->replacement_converters()->size();
for(size_t i = 0, k = 0; i < num_converters; k++, i += 2) {
as<String>(self->replacement_converters()->get(state, i));
as<Array>(self->replacement_converters()->get(state, i + 1));
}
native_int byte_size = self->replacement()->byte_size();
char* buf = (char*)XMALLOC(byte_size + 1);
strncpy(buf, self->replacement()->c_str(state), byte_size + 1);
self->converter_->replacement_str = (const unsigned char*)buf;
self->converter_->replacement_len = self->replacement()->byte_size();
String* name = self->replacement()->encoding()->name();
byte_size = name->byte_size();
buf = (char*)XMALLOC(byte_size + 1);
strncpy(buf, name->c_str(state), byte_size + 1);
self->converter_->replacement_enc = (const char*)buf;
self->converter_->replacement_allocated = 1;
rb_econv_alloc_replacement_converters(self->converter_, num_converters / 2);
for(size_t i = 0, k = 0; i < num_converters; k++, i += 2) {
rb_econv_replacement_converters* repl_converter;
repl_converter = self->converter_->replacement_converters + k;
// We can use force_as here since we know type has been checked above
name = force_as<String>(self->replacement_converters()->get(state, i));
byte_size = name->byte_size();
buf = (char*)XMALLOC(byte_size + 1);
strncpy(buf, name->c_str(state), byte_size + 1);
repl_converter->destination_encoding_name = (const char*)buf;
Array* trs = force_as<Array>(replacement_converters()->get(state, i + 1));
size_t num_transcoders = trs->size();
repl_converter->num_transcoders = num_transcoders;
repl_converter->transcoders = ALLOC_N(rb_transcoder*, num_transcoders);
for(size_t j = 0; j < num_transcoders; j++) {
Transcoding* transcoding = as<Transcoding>(trs->get(state, j));
rb_transcoder* tr = transcoding->get_transcoder();
repl_converter->transcoders[j] = tr;
}
//.........这里部分代码省略.........