本文整理汇总了C++中rb_str_buf_new函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_str_buf_new函数的具体用法?C++ rb_str_buf_new怎么用?C++ rb_str_buf_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_str_buf_new函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: mHash_to_json
/*
* call-seq: to_json(state = nil, depth = 0)
*
* Returns a JSON string containing a JSON object, that is unparsed from
* this Hash instance.
* _state_ is a JSON::State object, that can also be used to configure the
* produced JSON string output further.
* _depth_ is used to find out nesting depth, to indent accordingly.
*/
static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self)
{
VALUE Vstate, Vdepth, result;
long depth;
rb_scan_args(argc, argv, "02", &Vstate, &Vdepth);
depth = NIL_P(Vdepth) ? 0 : FIX2LONG(Vdepth);
if (NIL_P(Vstate)) {
long len = RHASH_SIZE(self);
result = rb_str_buf_new(len);
rb_str_buf_cat2(result, "{");
rb_hash_foreach(self, hash_to_json_i, result);
rb_str_buf_cat2(result, "}");
} else {
GET_STATE(Vstate);
check_max_nesting(state, depth);
if (state->check_circular) {
VALUE self_id = rb_obj_id(self);
if (RTEST(rb_hash_aref(state->seen, self_id))) {
rb_raise(eCircularDatastructure,
"circular data structures not supported!");
}
rb_hash_aset(state->seen, self_id, Qtrue);
result = mHash_json_transfrom(self, Vstate, LONG2FIX(depth));
rb_hash_delete(state->seen, self_id);
} else {
result = mHash_json_transfrom(self, Vstate, LONG2FIX(depth));
}
}
OBJ_INFECT(result, self);
FORCE_UTF8(result);
return result;
}
开发者ID:AdamDotCom,项目名称:my-rvm,代码行数:42,代码来源:generator.c
示例2: mArray_to_json
/*
* call-seq: to_json(state = nil, depth = 0)
*
* Returns a JSON string containing a JSON array, that is unparsed from
* this Array instance.
* _state_ is a JSON::State object, that can also be used to configure the
* produced JSON string output further.
* _depth_ is used to find out nesting depth, to indent accordingly.
*/
static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self) {
VALUE Vstate, Vdepth, result;
rb_scan_args(argc, argv, "02", &Vstate, &Vdepth);
if (NIL_P(Vstate)) {
long i, len = RARRAY_LEN(self);
result = rb_str_buf_new(2 + 2 * len);
rb_str_buf_cat2(result, "[");
OBJ_INFECT(result, self);
for (i = 0; i < len; i++) {
VALUE element = RARRAY_PTR(self)[i];
OBJ_INFECT(result, element);
if (i > 0) rb_str_buf_cat2(result, ",");
element = rb_funcall(element, i_to_json, 0);
Check_Type(element, T_STRING);
rb_str_buf_append(result, element);
}
rb_str_buf_cat2(result, "]");
} else {
result = mArray_json_transfrom(self, Vstate, Vdepth);
}
OBJ_INFECT(result, self);
FORCE_UTF8(result);
return result;
}
开发者ID:AdamDotCom,项目名称:my-rvm,代码行数:34,代码来源:generator.c
示例3: rb_rdiscount_toc_content
static VALUE
rb_rdiscount_toc_content(int argc, VALUE *argv, VALUE self)
{
char *res;
int szres;
int flags = rb_rdiscount__get_flags(self);
/* grab char pointer to markdown input text */
VALUE text = rb_funcall(self, rb_intern("text"), 0);
Check_Type(text, T_STRING);
/* allocate a ruby string buffer and wrap it in a stream */
VALUE buf = rb_str_buf_new(4096);
MMIOT *doc = mkd_string(RSTRING_PTR(text), RSTRING_LEN(text), flags);
if ( mkd_compile(doc, flags) ) {
szres = mkd_toc(doc, &res);
if ( szres != EOF ) {
rb_str_cat(buf, res, szres);
rb_str_cat(buf, "\n", 1);
}
}
mkd_cleanup(doc);
return buf;
}
开发者ID:AhmedSoliman,项目名称:rdiscount,代码行数:29,代码来源:rdiscount.c
示例4: _msgpack_buffer_read_from_io_to_string
size_t _msgpack_buffer_read_from_io_to_string(msgpack_buffer_t* b, VALUE string, size_t length)
{
if(RSTRING_LEN(string) == 0) {
/* direct read */
VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, LONG2NUM(length), string);
if(ret == Qnil) {
return 0;
}
return RSTRING_LEN(string);
}
/* copy via io_buffer */
if(b->io_buffer == Qnil) {
b->io_buffer = rb_str_buf_new(0);
}
VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, LONG2NUM(length), b->io_buffer);
if(ret == Qnil) {
return 0;
}
size_t rl = RSTRING_LEN(b->io_buffer);
rb_str_buf_cat(string, (const void*)RSTRING_PTR(b->io_buffer), rl);
return rl;
}
开发者ID:CodeMonkeySteve,项目名称:msgpack-ruby,代码行数:25,代码来源:buffer.c
示例5: MessagePack_Unpacker_initialize
/**
* Document-method: MessagePack::Unpacker#initialize
*
* call-seq:
* MessagePack::Unpacker.new(stream = nil)
*
* Creates instance of MessagePack::Unpacker.
*
* You can specify a _stream_ for input stream.
* It is required to implement *sysread* or *readpartial* method.
*
* With the input stream, buffers will be feeded into the deserializer automatically.
*
* Without the input stream, use *feed* method manually. Or you can manage the buffer manually
* with *execute*, *finished?*, *data* and *reset* methods.
*/
static VALUE MessagePack_Unpacker_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE stream;
switch(argc) {
case 0:
stream = Qnil;
break;
case 1:
stream = argv[0];
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
}
UNPACKER(self, mp);
template_init(mp);
mp->user.finished = 0;
mp->user.offset = 0;
mp->user.buffer.size = 0;
mp->user.buffer.free = 0;
mp->user.buffer.ptr = NULL;
mp->user.stream = stream;
mp->user.streambuf = rb_str_buf_new(MSGPACK_UNPACKER_BUFFER_RESERVE_SIZE);
mp->user.stream_append_method = append_method_of(stream);
return self;
}
开发者ID:bcg,项目名称:msgpack,代码行数:42,代码来源:unpack.c
示例6: sedna_read
// Read one record completely and return it as a Ruby String object.
static VALUE sedna_read(SC *conn, int strip_n)
{
int bytes_read = 0;
char buffer[RESULT_BUF_LEN];
VALUE str = rb_str_buf_new(0);
OBJ_TAINT(str);
do {
bytes_read = SEgetData(conn, buffer, RESULT_BUF_LEN - 1);
if(bytes_read == SEDNA_ERROR) {
sedna_err(conn, SEDNA_ERROR);
} else {
if(bytes_read > 0) {
if(strip_n) {
// Strange bug adds newlines to beginning of every result
// except the first. Strip them! This a known issue in the
// network protocol and serialization mechanism.
// See: http://sourceforge.net/mailarchive/forum.php?thread_name=3034886f0812030132v3bbd8e2erd86480d3dc640664%40mail.gmail.com&forum_name=sedna-discussion
STR_CAT(str, buffer + 1, bytes_read - 1);
// Do not strip newlines from subsequent buffer reads.
strip_n = 0;
} else {
STR_CAT(str, buffer, bytes_read);
}
}
}
} while(bytes_read > 0);
return str;
}
开发者ID:rolftimmermans,项目名称:sedna-ruby,代码行数:31,代码来源:sedna.c
示例7: rb_rdiscount_to_html
static VALUE
rb_rdiscount_to_html(int argc, VALUE *argv, VALUE self)
{
/* grab char pointer to markdown input text */
char *res;
int szres;
VALUE encoding;
VALUE text = rb_funcall(self, rb_intern("text"), 0);
VALUE buf = rb_str_buf_new(1024);
Check_Type(text, T_STRING);
int flags = rb_rdiscount__get_flags(self);
MMIOT *doc = mkd_string(RSTRING_PTR(text), RSTRING_LEN(text), flags);
if ( mkd_compile(doc, flags) ) {
szres = mkd_document(doc, &res);
if ( szres != EOF ) {
rb_str_cat(buf, res, szres);
rb_str_cat(buf, "\n", 1);
}
}
mkd_cleanup(doc);
/* force the input encoding */
if ( rb_respond_to(text, rb_intern("encoding")) ) {
encoding = rb_funcall(text, rb_intern("encoding"), 0);
rb_funcall(buf, rb_intern("force_encoding"), 1, encoding);
}
return buf;
}
开发者ID:jdpace,项目名称:hubbub,代码行数:34,代码来源:rdiscount.c
示例8: rb_enc_vsprintf
VALUE
rb_enc_vsprintf(rb_encoding *enc, const char *fmt, va_list ap)
{
rb_printf_buffer_extra buffer;
#define f buffer.base
VALUE result;
f._flags = __SWR | __SSTR;
f._bf._size = 0;
f._w = 120;
result = rb_str_buf_new(f._w);
if (enc) {
if (rb_enc_mbminlen(enc) > 1) {
/* the implementation deeply depends on plain char */
rb_raise(rb_eArgError, "cannot construct wchar_t based encoding string: %s",
rb_enc_name(enc));
}
rb_enc_associate(result, enc);
}
f._bf._base = (unsigned char *)result;
f._p = (unsigned char *)RSTRING_PTR(result);
RBASIC(result)->klass = 0;
f.vwrite = ruby__sfvwrite;
f.vextra = ruby__sfvextra;
buffer.value = 0;
BSD_vfprintf(&f, fmt, ap);
RBASIC(result)->klass = rb_cString;
rb_str_resize(result, (char *)f._p - RSTRING_PTR(result));
#undef f
return result;
}
开发者ID:MercerHall,项目名称:editorial,代码行数:32,代码来源:sprintf.c
示例9: dnssd_tr_encode
static VALUE
dnssd_tr_encode(VALUE self)
{
long i;
VALUE buf;
/* Declare ary volatile to prevent it from being reclaimed when:
* buf is allocated later, key/values are converted to strings */
volatile VALUE ary = rb_funcall2(self, rb_intern("to_a"), 0, 0);
/* array of key, value pairs */
VALUE *ptr = RARRAY(ary)->ptr;
buf = rb_str_buf_new(dnssd_tr_convert_pairs(ary));
for(i=0; i<RARRAY(ary)->len; i++) {
uint8_t len;
VALUE key = RARRAY(ptr[i])->ptr[0];
VALUE value = RARRAY(ptr[i])->ptr[1];
if (!NIL_P(value)) {
len = (uint8_t)(RSTRING(key)->len + RSTRING(value)->len + 1);
rb_str_buf_cat(buf, &len, 1);
rb_str_buf_append(buf, key);
rb_str_buf_cat(buf, "=", 1);
rb_str_buf_append(buf, value);
} else {
len = (uint8_t)RSTRING(key)->len;
rb_str_buf_cat(buf, &len, 1);
rb_str_buf_append(buf, key);
}
}
return buf;
}
开发者ID:lachie,项目名称:zeroconf,代码行数:30,代码来源:rdnssd_tr.c
示例10: create_mustache_ruby_context
mustache_ruby_context_t* create_mustache_ruby_context()
{
mustache_ruby_context_t* r_ctx = mustache_malloc(sizeof(mustache_ruby_context_t));
r_ctx->buffer = rb_str_buf_new(INITIAL_BUFFER_SIZE);
r_ctx->buffer_length = 0;
return r_ctx;
}
开发者ID:jpcummins,项目名称:stash,代码行数:7,代码来源:types.c
示例11: mString_to_json
/*
* call-seq: to_json(*)
*
* This string should be encoded with UTF-8 A call to this method
* returns a JSON string encoded with UTF16 big endian characters as
* \u????.
*/
static VALUE mString_to_json(int argc, VALUE *argv, VALUE self)
{
VALUE result = rb_str_buf_new(RSTRING_LEN(self));
rb_str_buf_cat2(result, "\"");
JSON_convert_UTF8_to_JSON(result, self, strictConversion);
rb_str_buf_cat2(result, "\"");
return result;
}
开发者ID:Sophrinix,项目名称:iphone-macruby,代码行数:15,代码来源:generator.c
示例12: rb_fairy_string_buffer_initialize
static VALUE
rb_fairy_string_buffer_initialize(VALUE self)
{
fairy_string_buffer_t *sb;
GetFairyStringBufferPtr(self, sb);
sb->string_sizes = rb_fairy_fixnum_buffer_new();
sb->buffer = rb_str_buf_new(STRING_BUFFER_CAPA);
return self;
}
开发者ID:fairy-prj,项目名称:fairy,代码行数:10,代码来源:string-buffer.c
示例13: string_spec_rb_str_buf_new
VALUE string_spec_rb_str_buf_new(VALUE self, VALUE len, VALUE str) {
VALUE buf;
buf = rb_str_buf_new(NUM2LONG(len));
if(RTEST(str)) {
snprintf(RSTRING_PTR(buf), NUM2LONG(len), "%s", RSTRING_PTR(str));
}
return buf;
}
开发者ID:jeremyz,项目名称:rubinius,代码行数:11,代码来源:string_spec.c
示例14: MessagePack_pack
/**
* Document-method: MessagePack.pack
*
* call-seq:
* MessagePack.pack(object, out = '') -> String
*
* Serializes the object into raw bytes. The encoding of the string is ASCII-8BIT on Ruby 1.9.
* This method is same as object.to_msgpack(out = '').
*
* _out_ is an object that implements *<<* method like String or IO.
*/
static VALUE MessagePack_pack(int argc, VALUE* argv, VALUE self)
{
VALUE out;
if(argc == 1) {
out = rb_str_buf_new(0);
} else if(argc == 2) {
out = argv[1];
} else {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
}
return rb_funcall(argv[0], s_to_msgpack, 1, out);
}
开发者ID:vincentdephily,项目名称:msgpack,代码行数:23,代码来源:pack.c
示例15: ext_escape
// escape for uri path ('/', '+' are not changed)
// or component ('/', '+' are changed)
static VALUE ext_escape(VALUE _, VALUE s, VALUE v_ispath) {
Check_Type(s, T_STRING);
long len = RSTRING_LEN(s);
const char* ptr = RSTRING_PTR(s);
volatile VALUE res = rb_str_buf_new(len);
bool ispath = RTEST(v_ispath);
for (long i = 0; i < len; i++) {
_concat_char(res, ptr[i], ispath);
}
rb_enc_associate(res, u8_encoding);
return res;
}
开发者ID:huacnlee,项目名称:nyara,代码行数:14,代码来源:url_encoded.c
示例16: _msgpack_buffer_skip_from_io
size_t _msgpack_buffer_skip_from_io(msgpack_buffer_t* b, size_t length)
{
if(b->io_buffer == Qnil) {
b->io_buffer = rb_str_buf_new(0);
}
VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, LONG2NUM(length), b->io_buffer);
if(ret == Qnil) {
return 0;
}
return RSTRING_LEN(b->io_buffer);
}
开发者ID:CodeMonkeySteve,项目名称:msgpack-ruby,代码行数:12,代码来源:buffer.c
示例17: _msgpack_buffer_chunk_as_string
static inline VALUE _msgpack_buffer_chunk_as_string(msgpack_buffer_chunk_t* c)
{
size_t chunk_size = c->last - c->first;
if(chunk_size == 0) {
return rb_str_buf_new(0);
}
if(c->mapped_string != NO_MAPPED_STRING) {
return rb_str_dup(c->mapped_string);
}
return rb_str_new(c->first, chunk_size);
}
开发者ID:CodeMonkeySteve,项目名称:msgpack-ruby,代码行数:13,代码来源:buffer.c
示例18: _msgpack_buffer_head_chunk_as_string
static inline VALUE _msgpack_buffer_head_chunk_as_string(msgpack_buffer_t* b)
{
size_t length = b->head->last - b->read_buffer;
if(length == 0) {
return rb_str_buf_new(0);
}
if(b->head->mapped_string != NO_MAPPED_STRING) {
return _msgpack_buffer_refer_head_mapped_string(b, length);
}
return rb_str_new(b->read_buffer, length);
}
开发者ID:CodeMonkeySteve,项目名称:msgpack-ruby,代码行数:13,代码来源:buffer.c
示例19: read_bytes
/**
* Reads from buffer given number of bytes and shifts the pointer.
*
* buffer - pointer to the buffer pointer
* buffer_size - pointer to the buffer size
* count - number of bytes to read
*
* Returns ruby string with bytes.
*
*/
static inline VALUE read_bytes( uint8_t **buffer, long *buffer_size, long count )
{
if ( *buffer_size < count )
rb_raise( rb_eProtobufCoderDecodingError, "can't read %ld bytes: buffer contains only %ld bytes", count, *buffer_size );
// Copy slice to ruby string
VALUE result = rb_str_buf_new( count );
rb_str_resize( result, count );
MEMCPY( RSTRING_PTR( result ), *buffer, uint8_t, count );
*buffer = *buffer + count;
*buffer_size = *buffer_size - count;
return result;
}
开发者ID:ddiachkov,项目名称:protobuf_coder,代码行数:25,代码来源:decoder.c
示例20: fast_pack
static VALUE fast_pack(VALUE self)
{
VALUE res;
long i;
char c;
res = rb_str_buf_new(0);
for (i = 0; i < RARRAY_LEN(self); i++) {
c = FIX2LONG(RARRAY_PTR(self)[i]);
rb_str_buf_cat(res, &c, sizeof(char));
}
return res;
}
开发者ID:omgitsads,项目名称:mongo-ruby-driver,代码行数:15,代码来源:cbson.c
注:本文中的rb_str_buf_new函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论