本文整理汇总了C++中rb_str_new函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_str_new函数的具体用法?C++ rb_str_new怎么用?C++ rb_str_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_str_new函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: http_version
void http_version(void *data, const char *at, size_t length)
{
VALUE req = (VALUE)data;
VALUE val = rb_str_new(at, length);
rb_hash_aset(req, global_http_version, val);
}
示例2: foreach
//.........这里部分代码省略.........
len+=len2-1;
nobackslash=start;
free(line);
free(line2);
continue;
}
}
break;
}
/* chomp! */
if(line[len]==EOL){
if(line[len-1]==CR)
len-=1;
line[len]='\0';
}
/* skip empty line */
if(len<2)
continue;
ary = rb_ary_new();
start=line;
nobackslash=line;
idx = 0;
flag=1;
while (nobackslash != NULL) {
/* get full field */
while(token=strstr(nobackslash, DELIM)){
count=0;
t2=token-1;
while((t2>=line) && (*t2=='\\'))
{++count;--t2;}
if(count%2 ==1){ /* backslashed! skip */
nobackslash=token;
continue;
}
break;
}
if(token)
*token='\0';
else
token=start+strlen(start);
if(searchfield==idx){
flag=0;
/* do check! */
sscanf(start,"%ld",&check);
for(i=0;i<pairs_count;++i){
/*rb_warn("check %ld: [%ld .. %ld]",check,pairs[i].low,pairs[i].high);*/
if(pairs[i].low<check && pairs[i].high>check){
/*rb_warn("check passed");*/
flag=1; /* yahooo! */
break;
}
}
}
/* not in ranges! */
if(flag==0)
break;
rb_ary_store(ary, idx, rb_str_new(start, token-start));
idx++;
nobackslash=start=token+strlen(DELIM);
while(token=strstr(nobackslash, DELIM)){
count=0;
t2=token-1;
while((t2>=line) && (*t2=='\\'))
{++count;--t2;}
if(count%2 ==1){ /* backslashed! skip */
nobackslash=token+strlen(DELIM);
continue;
}
break;
}
nobackslash=token;
}
if(flag==0)
continue;
/* last item */
rb_ary_store(ary, idx, rb_str_new(start, strlen(start)));
/* OBJ_FREEZE(ary); */
rb_yield(ary);
/* FL_UNSET((ary), FL_FREEZE); */
/* for(idx = 0; idx < RARRAY_LEN(ary); idx ++) {
rb_ary_store(ary, idx, Qnil);
} */
}
fclose(file);
free(line);
return Qnil;
}
示例3: rhe_accept
static
VALUE rhe_accept(VALUE self, VALUE fileno, VALUE timeoutv, VALUE tcp, VALUE env) {
struct sockaddr_in cliaddr;
unsigned int len;
char read_buf[MAX_HEADER_SIZE];
VALUE req;
int flag = 1;
ssize_t rv = 0;
ssize_t buf_len;
ssize_t reqlen;
int fd;
double timeout = NUM2DBL(timeoutv);
len = sizeof(cliaddr);
fd = _accept(NUM2INT(fileno), (struct sockaddr *)&cliaddr, len);
/* endif */
if (fd < 0) {
goto badexit;
}
rv = _read_timeout(fd, timeout, &read_buf[0], MAX_HEADER_SIZE);
if ( rv <= 0 ) {
close(fd);
goto badexit;
}
if ( IMMEDIATE_P(tcp) ) {
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char*)&flag, sizeof(int));
rb_hash_aset(env, remote_addr_key, rb_str_new2(inet_ntoa(cliaddr.sin_addr)));
rb_hash_aset(env, remote_port_key, rb_String(rb_int_new(ntohs(cliaddr.sin_port))));
}
else {
rb_hash_aset(env, remote_addr_key, rb_str_new("",0));
rb_hash_aset(env, remote_port_key, rb_String(rb_int_new(0)));
}
buf_len = rv;
while (1) {
reqlen = _parse_http_request(&read_buf[0],buf_len,env);
if ( reqlen >= 0 ) {
break;
}
else if ( reqlen == -1 ) {
/* error */
close(fd);
goto badexit;
}
if ( MAX_HEADER_SIZE - buf_len == 0 ) {
/* too large header */
char* badreq;
badreq = BAD_REQUEST;
rv = _write_timeout(fd, timeout, badreq, sizeof(BAD_REQUEST) - 1);
close(fd);
goto badexit;
}
/* request is incomplete */
rv = _read_timeout(fd, timeout, &read_buf[buf_len], MAX_HEADER_SIZE - buf_len);
if ( rv <= 0 ) {
close(fd);
goto badexit;
}
buf_len += rv;
}
req = rb_ary_new2(3);
rb_ary_push(req, rb_int_new(fd));
rb_ary_push(req, rb_str_new(&read_buf[reqlen],buf_len - reqlen));
return req;
badexit:
return Qnil;
}
示例4: cState_array_nl
/*
* call-seq: array_nl()
*
* This string is put at the end of a line that holds a JSON array.
*/
static VALUE cState_array_nl(VALUE self)
{
GET_STATE(self);
return state->array_nl ? rb_str_new(state->array_nl, state->array_nl_len) : rb_str_new2("");
}
示例5: asn1str_to_str
/*
* STRING conversion
*/
VALUE
asn1str_to_str(ASN1_STRING *str)
{
return rb_str_new(str->data, str->length);
}
示例6: rb_exc_new
VALUE
rb_exc_new(VALUE etype, const char *ptr, long len)
{
return rb_funcall(etype, rb_intern("new"), 1, rb_str_new(ptr, len));
}
示例7: cState_indent
/*
* call-seq: indent()
*
* This string is used to indent levels in the JSON text.
*/
static VALUE cState_indent(VALUE self)
{
GET_STATE(self);
return state->indent ? rb_str_new(state->indent, state->indent_len) : rb_str_new2("");
}
示例8: rdmtx_encode
static VALUE rdmtx_encode(int argc, VALUE * argv, VALUE self) {
VALUE string, margin, module, size;
VALUE safeString;
VALUE magickImageClass;
VALUE outputImage;
int safeMargin, safeModule, safeSize;
int width;
int height;
DmtxEncode * enc;
rb_scan_args(argc, argv, "13", &string,
&margin, &module, &size);
safeString = StringValue(string);
if(NIL_P(margin)) {
safeMargin = 5;
} else {
safeMargin = NUM2INT(margin);
}
if(NIL_P(module)) {
safeModule = 5;
} else {
safeModule = NUM2INT(module);
}
if(NIL_P(size)) {
safeSize = DmtxSymbolSquareAuto;
} else {
safeSize = NUM2INT(size);
}
// printf("Margin = %d, Module = %d, Size = %d\n", safeMargin, safeModule, safeSize);
/* Create and initialize libdmtx structures */
enc = dmtxEncodeCreate();
dmtxEncodeSetProp(enc, DmtxPropPixelPacking, DmtxPack24bppRGB);
dmtxEncodeSetProp(enc, DmtxPropSizeRequest, safeSize);
dmtxEncodeSetProp(enc, DmtxPropMarginSize, safeMargin);
dmtxEncodeSetProp(enc, DmtxPropModuleSize, safeModule);
/* Create barcode image */
if (dmtxEncodeDataMatrix(enc, RSTRING_LEN(safeString),
(unsigned char *)RSTRING_PTR(safeString)) == DmtxFail) {
// printf("Fatal error !\n");
dmtxEncodeDestroy(&enc);
return Qnil;
}
width = dmtxImageGetProp(enc->image, DmtxPropWidth);
height = dmtxImageGetProp(enc->image, DmtxPropHeight);
magickImageClass = rb_path2class("Magick::Image");
outputImage = rb_funcall(magickImageClass, rb_intern("new"), 2, INT2NUM(width), INT2NUM(height));
rb_funcall(outputImage, rb_intern("import_pixels"), 7,
INT2NUM(0),
INT2NUM(0),
INT2NUM(width),
INT2NUM(height),
rb_str_new("RGB", 3),
rb_str_new((char *)enc->image->pxl, 3*width*height),
// rb_const_get("Magick" ,rb_intern("CharPixel"))
rb_eval_string("Magick::CharPixel"));
/* Clean up */
dmtxEncodeDestroy(&enc);
return outputImage;
}
示例9: rb_rinku_autolink
//.........这里部分代码省略.........
* This string can be autogenerated from a hash using the Rails `tag_options` helper.
*
* - `skip_tags` is a list of strings with the names of HTML tags that will be skipped
* when autolinking. If `nil`, this defaults to the value of the global `Rinku.skip_tags`,
* which is initially `["a", "pre", "code", "kbd", "script"]`.
*
* - `flag` is an optional boolean value specifying whether to recognize
* 'http://foo' as a valid domain, or require at least one '.'. It defaults to false.
*
* - `&block` is an optional block argument. If a block is passed, it will
* be yielded for each found link in the text, and its return value will be used instead
* of the name of the link. E.g.
*
* ~~~~~ruby
* auto_link('Check it out at http://www.pokemon.com') do |url|
* "THE POKEMAN WEBSITEZ"
* end
* # => 'Check it out at <a href="http://www.pokemon.com">THE POKEMAN WEBSITEZ</a>'
* ~~~~~~
*/
static VALUE
rb_rinku_autolink(int argc, VALUE *argv, VALUE self)
{
static const char *SKIP_TAGS[] = {"a", "pre", "code", "kbd", "script", NULL};
VALUE result, rb_text, rb_mode, rb_html, rb_skip, rb_flags, rb_block;
struct buf *output_buf;
int link_mode, count;
unsigned int link_flags = 0;
const char *link_attr = NULL;
const char **skip_tags = NULL;
ID mode_sym;
rb_scan_args(argc, argv, "14&", &rb_text, &rb_mode,
&rb_html, &rb_skip, &rb_flags, &rb_block);
Check_Type(rb_text, T_STRING);
if (!NIL_P(rb_mode)) {
Check_Type(rb_mode, T_SYMBOL);
mode_sym = SYM2ID(rb_mode);
} else {
mode_sym = rb_intern("all");
}
if (!NIL_P(rb_html)) {
Check_Type(rb_html, T_STRING);
link_attr = RSTRING_PTR(rb_html);
}
if (NIL_P(rb_skip))
rb_skip = rb_iv_get(self, "@skip_tags");
if (NIL_P(rb_skip)) {
skip_tags = SKIP_TAGS;
} else {
skip_tags = rinku_load_tags(rb_skip);
}
if (!NIL_P(rb_flags)) {
Check_Type(rb_flags, T_FIXNUM);
link_flags = FIX2INT(rb_flags);
}
output_buf = bufnew(32);
if (mode_sym == rb_intern("all"))
link_mode = AUTOLINK_ALL;
else if (mode_sym == rb_intern("email_addresses"))
link_mode = AUTOLINK_EMAILS;
else if (mode_sym == rb_intern("urls"))
link_mode = AUTOLINK_URLS;
else
rb_raise(rb_eTypeError,
"Invalid linking mode (possible values are :all, :urls, :email_addresses)");
count = rinku_autolink(
output_buf,
RSTRING_PTR(rb_text),
RSTRING_LEN(rb_text),
link_mode,
link_flags,
link_attr,
skip_tags,
RTEST(rb_block) ? &autolink_callback : NULL,
(void*)rb_block);
if (count == 0)
result = rb_text;
else {
result = rb_str_new(output_buf->data, output_buf->size);
rb_enc_copy(result, rb_text);
}
if (skip_tags != SKIP_TAGS)
xfree(skip_tags);
bufrelease(output_buf);
return result;
}
示例10: rb_bson_byte_buffer_to_s
/**
* Convert the buffer to a string.
*/
VALUE rb_bson_byte_buffer_to_s(VALUE self)
{
byte_buffer_t *b;
TypedData_Get_Struct(self, byte_buffer_t, &rb_byte_buffer_data_type, b);
return rb_str_new(READ_PTR(b), READ_SIZE(b));
}
示例11: symbol_spec_rb_id2name
VALUE symbol_spec_rb_id2name(VALUE self, VALUE symbol) {
const char* c_str = rb_id2name(SYM2ID(symbol));
return rb_str_new(c_str, strlen(c_str));
}
示例12: nyara_parse_query
// do not raise error
void nyara_parse_query(VALUE output, const char* s, long len) {
volatile VALUE str = rb_str_new(s, len);
_tmp_str = str;
int err = 0;
rb_protect(_parse_query_func, output, &err);
}
示例13: rb_tinytds_result_fetch_row
static VALUE rb_tinytds_result_fetch_row(VALUE self, ID timezone, int symbolize_keys, int as_array) {
VALUE row;
/* Storing Values */
unsigned int i;
/* Wrapper And Local Vars */
GET_RESULT_WRAPPER(self);
/* Create Empty Row */
row = as_array ? rb_ary_new2(rwrap->number_of_fields) : rb_hash_new();
for (i = 0; i < rwrap->number_of_fields; i++) {
VALUE val = Qnil;
int col = i+1;
int coltype = dbcoltype(rwrap->client, col);
BYTE *data = dbdata(rwrap->client, col);
DBINT data_len = dbdatlen(rwrap->client, col);
int null_val = ((data == NULL) && (data_len == 0));
if (!null_val) {
switch(coltype) {
case SYBINT1:
val = INT2FIX(*(DBTINYINT *)data);
break;
case SYBINT2:
val = INT2FIX(*(DBSMALLINT *)data);
break;
case SYBINT4:
val = INT2NUM(*(DBINT *)data);
break;
case SYBINT8:
val = LL2NUM(*(DBBIGINT *)data);
break;
case SYBBIT:
val = *(int *)data ? Qtrue : Qfalse;
break;
case SYBNUMERIC:
case SYBDECIMAL: {
DBTYPEINFO *data_info = dbcoltypeinfo(rwrap->client, col);
int data_slength = (int)data_info->precision + (int)data_info->scale + 1;
char converted_decimal[data_slength];
dbconvert(rwrap->client, coltype, data, data_len, SYBVARCHAR, (BYTE *)converted_decimal, -1);
val = rb_funcall(cBigDecimal, intern_new, 1, rb_str_new2((char *)converted_decimal));
break;
}
case SYBFLT8: {
double col_to_double = *(double *)data;
val = (col_to_double == 0.000000) ? opt_float_zero : rb_float_new(col_to_double);
break;
}
case SYBREAL: {
float col_to_float = *(float *)data;
val = (col_to_float == 0.0) ? opt_float_zero : rb_float_new(col_to_float);
break;
}
case SYBMONEY: {
DBMONEY *money = (DBMONEY *)data;
char converted_money[25];
long long money_value = ((long long)money->mnyhigh << 32) | money->mnylow;
sprintf(converted_money, "%" LONG_LONG_FORMAT, money_value);
val = rb_funcall(cBigDecimal, intern_new, 2, rb_str_new2(converted_money), opt_four);
val = rb_funcall(val, intern_divide, 1, opt_tenk);
break;
}
case SYBMONEY4: {
DBMONEY4 *money = (DBMONEY4 *)data;
char converted_money[20];
sprintf(converted_money, "%f", money->mny4 / 10000.0);
val = rb_funcall(cBigDecimal, intern_new, 1, rb_str_new2(converted_money));
break;
}
case SYBBINARY:
case SYBIMAGE:
val = rb_str_new((char *)data, (long)data_len);
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate(val, binaryEncoding);
#endif
break;
case 36: { // SYBUNIQUE
char converted_unique[37];
dbconvert(rwrap->client, coltype, data, 37, SYBVARCHAR, (BYTE *)converted_unique, -1);
val = ENCODED_STR_NEW2(converted_unique);
break;
}
case SYBDATETIME4: {
DBDATETIME new_data;
dbconvert(rwrap->client, coltype, data, data_len, SYBDATETIME, (BYTE *)&new_data, sizeof(new_data));
data = (BYTE *)&new_data;
data_len = sizeof(new_data);
}
case SYBDATETIME: {
DBDATEREC dr;
dbdatecrack(rwrap->client, &dr, (DBDATETIME *)data);
if (dr.year + dr.month + dr.day + dr.hour + dr.minute + dr.second + dr.millisecond != 0) {
val = rb_funcall(rb_cTime, timezone, 7, INT2NUM(dr.year), INT2NUM(dr.month), INT2NUM(dr.day), INT2NUM(dr.hour), INT2NUM(dr.minute), INT2NUM(dr.second), INT2NUM(dr.millisecond*1000));
}
break;
}
case 40: // SYBMSDATE
case 41: // SYBMSTIME
case 42: // SYBMSDATETIME2
case 43: { // SYBMSDATETIMEOFFSET
#ifdef DBVERSION_73
if (dbtds(rwrap->client) >= DBTDS_7_3) {
//.........这里部分代码省略.........
示例14: intersys_query_get_data
VALUE intersys_query_get_data(VALUE self, VALUE index) {
struct rbQuery* query;
int type = 0;
VALUE ret = Qnil;
bool_t is_null;
Data_Get_Struct(self, struct rbQuery, query);
RUN(cbind_query_get_col_sql_type(query->query, FIX2INT(index), &type));
switch(type) {
case SQL_WCHAR:
case SQL_WVARCHAR:
case SQL_WLONGVARCHAR:
case SQL_CHAR:
case SQL_VARCHAR:
case SQL_LONGVARCHAR:
{
wchar_t buf[32767];
int size;
RUN(cbind_query_get_uni_str_data(query->query, buf, sizeof(buf), &size, &is_null));
if (is_null) {
return Qnil;
}
return FROMWCSTR(buf);
}
case SQL_BINARY:
case SQL_LONGVARBINARY:
case SQL_VARBINARY:
{
char buf[32767];
int size;
RUN(cbind_query_get_bin_data(query->query, buf, sizeof(buf), &size, &is_null));
if (is_null) {
return Qnil;
}
return rb_str_new(buf, size);
}
case SQL_TINYINT:
case SQL_SMALLINT:
case SQL_INTEGER:
case SQL_BIGINT:
case SQL_BIT:
{
int res;
RUN(cbind_query_get_int_data(query->query, &res, &is_null));
if (is_null) {
return Qnil;
}
return INT2NUM(res);
}
case SQL_FLOAT:
case SQL_DOUBLE:
case SQL_REAL:
case SQL_NUMERIC:
case SQL_DECIMAL:
{
double res;
RUN(cbind_query_get_double_data(query->query, &res, &is_null));
if (is_null) {
return Qnil;
}
return rb_float_new(res);
}
}
return ret;
}
示例15: zipruby_archive_s_open_buffer
static VALUE zipruby_archive_s_open_buffer(int argc, VALUE *argv, VALUE self) {
VALUE buffer, flags, comp_level;
VALUE archive;
struct zipruby_archive *p_archive;
void *data = NULL;
int len = 0, i_flags = 0;
int errorp;
int i_comp_level = Z_BEST_COMPRESSION;
int buffer_is_temporary = 0;
rb_scan_args(argc, argv, "03", &buffer, &flags, &comp_level);
if (FIXNUM_P(buffer) && NIL_P(comp_level)) {
comp_level = flags;
flags = buffer;
buffer = Qnil;
}
if (!NIL_P(flags)) {
i_flags = NUM2INT(flags);
}
if (!NIL_P(comp_level)) {
i_comp_level = NUM2INT(comp_level);
if (i_comp_level != Z_DEFAULT_COMPRESSION && i_comp_level != Z_NO_COMPRESSION && (i_comp_level < Z_BEST_SPEED || Z_BEST_COMPRESSION < i_comp_level)) {
rb_raise(rb_eArgError, "Wrong compression level %d", i_comp_level);
}
}
if (i_flags & ZIP_CREATE) {
if (!NIL_P(buffer)) {
Check_Type(buffer, T_STRING);
} else {
buffer = rb_str_new("", 0);
buffer_is_temporary = 1;
}
i_flags = (i_flags | ZIP_TRUNCATE);
} else if (TYPE(buffer) == T_STRING) {
data = RSTRING_PTR(buffer);
len = RSTRING_LEN(buffer);
} else if (rb_obj_is_instance_of(buffer, rb_cProc)) {
data = (void *) buffer;
len = -1;
} else {
rb_raise(rb_eTypeError, "wrong argument type %s (expected String or Proc)", rb_class2name(CLASS_OF(buffer)));
}
archive = rb_funcall(Archive, rb_intern("new"), 0);
Data_Get_Struct(archive, struct zipruby_archive, p_archive);
if ((p_archive->tmpfilnam = zipruby_tmpnam(data, len)) == NULL) {
rb_raise(Error, "Open archive failed: Failed to create temporary file");
}
if ((p_archive->archive = zip_open(p_archive->tmpfilnam, i_flags, &errorp)) == NULL) {
char errstr[ERRSTR_BUFSIZE];
zip_error_to_str(errstr, ERRSTR_BUFSIZE, errorp, errno);
rb_raise(Error, "Open archive failed: %s", errstr);
}
// p_archive->archive->comp_level = i_comp_level;
p_archive->path = rb_str_new2(p_archive->tmpfilnam);
p_archive->flags = i_flags;
p_archive->buffer = buffer;
p_archive->sources = rb_ary_new();
if (rb_block_given_p()) {
VALUE retval;
int status;
retval = rb_protect(rb_yield, archive, &status);
zipruby_archive_close(archive);
if (status != 0) {
rb_jump_tag(status);
}
return buffer_is_temporary ? buffer : retval;
} else {
return archive;
}
}