• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ rb_str_new函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中rb_str_new函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_str_new函数的具体用法?C++ rb_str_new怎么用?C++ rb_str_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了rb_str_new函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:asksandipd,项目名称:mongrel,代码行数:6,代码来源:http11.c


示例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;
}
开发者ID:JonMidhir,项目名称:ccsv,代码行数:101,代码来源:ccsv.c


示例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;
}
开发者ID:tricknotes,项目名称:rhebok,代码行数:72,代码来源:rhebok.c


示例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("");
}
开发者ID:Danylyuk,项目名称:first_app,代码行数:10,代码来源:generator.c


示例5: asn1str_to_str

/*
 * STRING conversion
 */
VALUE
asn1str_to_str(ASN1_STRING *str)
{
    return rb_str_new(str->data, str->length);
}
开发者ID:BCafairley,项目名称:rubyenterpriseedition187-248,代码行数:8,代码来源:ossl_asn1.c


示例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));
}
开发者ID:evan,项目名称:ruby,代码行数:5,代码来源:error.c


示例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("");
}
开发者ID:Danylyuk,项目名称:first_app,代码行数:10,代码来源:generator.c


示例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;
}
开发者ID:srijan,项目名称:ruby-dmtx,代码行数:72,代码来源:Rdmtx.c


示例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;
}
开发者ID:Arkham,项目名称:rinku,代码行数:101,代码来源:rinku.c


示例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));
}
开发者ID:adimitrov,项目名称:bson-ruby,代码行数:9,代码来源:bson_native.c


示例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));
}
开发者ID:jruby,项目名称:jruby,代码行数:4,代码来源:symbol_spec.c


示例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);
}
开发者ID:fsword,项目名称:nyara,代码行数:7,代码来源:hashes.c


示例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) {
//.........这里部分代码省略.........
开发者ID:Monishonline,项目名称:tiny_tds,代码行数:101,代码来源:result.c


示例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;
}
开发者ID:sween,项目名称:intersys,代码行数:69,代码来源:query.c


示例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;
  }
}
开发者ID:fjg,项目名称:zipruby,代码行数:84,代码来源:zipruby_archive.c


示例16: t_filter_html

/**
 * filter_html
 **/
static VALUE
t_filter_html(VALUE self, VALUE str)
{
    node root, now, ret;
    bool in_tag;
    char *text;
    const char* inner_tag;
    long i, head_i, tail_i, copy_head_i, total_len;
    VALUE change_str, url_base, word;
    rb_encoding *enc;

    change_str = rb_str_new2(EMPTY_STRING);
    enc = rb_enc_get(str);
    text = StringValuePtr(str);

    Data_Get_Struct(self, struct _node, root);
    url_base = rb_iv_get(self, LINK_URL_VARIABLE);
    if (url_base == Qnil) {
        url_base = rb_str_new2(DEAULT_LINK_URL);
    }

    now = root;
    total_len = strlen(text);
    head_i = -1;
    tail_i = -1;
    copy_head_i = 0;
    in_tag = false;
    inner_tag = NULL;

    for(i = 0; i <= total_len; i++) {
        if (!in_tag && text[i] == BEGIN_TAG) {
            in_tag = true;
            if (strncasecmp(&text[i + 1], A_TAG, strlen(A_TAG)) == 0) {
                inner_tag = A_TAG;
            } else if (strncasecmp(&text[i + 1], SCRIPT_TAG, strlen(SCRIPT_TAG)) == 0) {
                inner_tag = SCRIPT_TAG;
            } else if (strncasecmp(&text[i + 1], PRE_TAG, strlen(PRE_TAG)) == 0) {
                inner_tag = PRE_TAG;
            } else if (strncasecmp(&text[i + 1], IFRAME_TAG, strlen(IFRAME_TAG)) == 0) {
                inner_tag = IFRAME_TAG;
            } else if (strncasecmp(&text[i + 1], OBJECT_TAG, strlen(OBJECT_TAG)) == 0) {
                inner_tag = OBJECT_TAG;
            }
            continue;
        }

        if (in_tag && !inner_tag && text[i] == END_TAG) {
            in_tag = false;
            continue;
        }

        if (inner_tag && text[i] == BEGIN_TAG) {
            if (strncasecmp(&text[i + 2], inner_tag, strlen(inner_tag)) == 0) {
                inner_tag = NULL;
                continue;
            }
        }

        if (in_tag) {
            continue;
        }

        ret = search_child(now, text[i]);

        if (ret && i != total_len) {
            if (head_i == -1) {
                head_i = i;
            }

            if (ret->end_flag) {
                tail_i = i;
            }
            now = ret;
        } else {
            if (head_i != -1) {
                if (tail_i != -1) {
                    if (copy_head_i < head_i) {
                        rb_funcall(
                            change_str, 
                            rb_intern("concat"),
                            1,
                            add_encode(rb_str_new(&text[copy_head_i], (head_i - copy_head_i)), enc)
                        );
                    }

                    word = rb_str_new(&text[head_i], (tail_i - head_i + 1));
                    rb_funcall(
                        change_str,
                        rb_intern("concat"),
                        1,
                        add_encode(rb_funcall(url_base, rb_intern("%"), 1, rb_assoc_new(word, word)), enc)
                    );
                    i = tail_i;
                    copy_head_i = tail_i + 1;
                    tail_i = -1;
                } else {
                    i = head_i;
//.........这里部分代码省略.........
开发者ID:tsukasaoishi,项目名称:word_scoop,代码行数:101,代码来源:word_scoop.c


示例17: rb_exc_new

VALUE
rb_exc_new(VALUE etype, const char *ptr, long len)
{
    return rb_funcall(etype, id_new, 1, rb_str_new(ptr, len));
}
开发者ID:0x00evil,项目名称:ruby,代码行数:5,代码来源:error.c


示例18: get_value

static VALUE get_value(const char* buffer, int* position, int type) {
    VALUE value;
    switch (type) {
    case -1:
        {
            value = rb_class_new_instance(0, NULL, MinKey);
            break;
        }
    case 1:
        {
            double d;
            memcpy(&d, buffer + *position, 8);
            value = rb_float_new(d);
            *position += 8;
            break;
        }
    case 2:
    case 13:
        {
            int value_length;
            value_length = *(int*)(buffer + *position) - 1;
            *position += 4;
            value = STR_NEW(buffer + *position, value_length);
            *position += value_length + 1;
            break;
        }
    case 3:
        {
            int size;
            memcpy(&size, buffer + *position, 4);
            if (strcmp(buffer + *position + 5, "$ref") == 0) { // DBRef
                int offset = *position + 10;
                VALUE argv[2];
                int collection_length = *(int*)(buffer + offset) - 1;
                char id_type;
                offset += 4;

                argv[0] = STR_NEW(buffer + offset, collection_length);
                offset += collection_length + 1;
                id_type = buffer[offset];
                offset += 5;
                argv[1] = get_value(buffer, &offset, (int)id_type);
                value = rb_class_new_instance(2, argv, DBRef);
            } else {
                value = elements_to_hash(buffer + *position + 4, size - 5);
            }
            *position += size;
            break;
        }
    case 4:
        {
            int size, end;
            memcpy(&size, buffer + *position, 4);
            end = *position + size - 1;
            *position += 4;

            value = rb_ary_new();
            while (*position < end) {
                int type = (int)buffer[(*position)++];
                int key_size = (int)strlen(buffer + *position);
                VALUE to_append;

                *position += key_size + 1; // just skip the key, they're in order.
                to_append = get_value(buffer, position, type);
                rb_ary_push(value, to_append);
            }
            (*position)++;
            break;
        }
    case 5:
        {
            int length, subtype;
            VALUE data, st;
            VALUE argv[2];
            memcpy(&length, buffer + *position, 4);
            subtype = (unsigned char)buffer[*position + 4];
            if (subtype == 2) {
                data = rb_str_new(buffer + *position + 9, length - 4);
            } else {
                data = rb_str_new(buffer + *position + 5, length);
            }
            st = INT2FIX(subtype);
            argv[0] = data;
            argv[1] = st;
            value = rb_class_new_instance(2, argv, Binary);
            *position += length + 5;
            break;
        }
    case 6:
        {
            value = Qnil;
            break;
        }
    case 7:
        {
            VALUE str = rb_str_new(buffer + *position, 12);
            VALUE oid = rb_funcall(str, unpack_method, 1, rb_str_new2("C*"));
            value = rb_class_new_instance(1, &oid, ObjectId);
            *position += 12;
            break;
//.........这里部分代码省略.........
开发者ID:DanPatey,项目名称:TeleSign-QA,代码行数:101,代码来源:cbson.c


示例19: find_file

static VALUE find_file(VALUE fname)
{
    VALUE res = 0;
    int nOK = 0;

    //RAWLOG_INFO1("find_file: fname: %s", RSTRING_PTR(fname));
#ifdef RHODES_EMULATOR
    if ( strncmp(RSTRING_PTR(fname), rho_simconf_getRhodesPath(), strlen(rho_simconf_getRhodesPath())) == 0 )
        res = fname;
    else
#endif

    if ( strncmp(RSTRING_PTR(fname), rho_native_rhopath(), strlen(rho_native_rhopath())) == 0 ){
        res = rb_str_dup(fname);
        rb_str_cat(res,RHO_RB_EXT,strlen(RHO_RB_EXT));
        //RAWLOG_INFO1("find_file: res: %s", RSTRING_PTR(res));
    } else if ( strncmp(RSTRING_PTR(fname), rho_native_reruntimepath(), strlen(rho_native_reruntimepath())) == 0 ){
        res = rb_str_dup(fname);
        rb_str_cat(res,RHO_RB_EXT,strlen(RHO_RB_EXT));
        //RAWLOG_INFO1("find_file: res: %s", RSTRING_PTR(res));
    }else{
        int i = 0;
        VALUE load_path = GET_VM()->load_path;
        //VALUE dir;
        VALUE fname1 = checkRhoBundleInPath(fname);
        //RAWLOG_INFO1("find_file: fname after checkRhoBundleInPath: %s", RSTRING_PTR(fname));

        //TODO: support document relative require in case of multiple apps
        if (RARRAY_LEN(load_path)>1){
            for( ; i < RARRAY_LEN(load_path); i++ ){
                VALUE dir = RARRAY_PTR(load_path)[i];

#ifdef RHODES_EMULATOR
                res = check_app_file_exist(dir, fname1, rho_simconf_getString("platform"));
#endif
                if ( !res )
                    res = check_app_file_exist(dir, fname1, 0 );

                if (res)
                {
                    nOK = 1;
                    break;
                }
            }
            if ( !nOK )
            {
#ifdef RHODES_EMULATOR
                //check for extensions
/*                res = rb_str_new2(rho_simconf_getRhodesPath() );
                rb_str_cat2(res,"/lib/extensions/");

                res = check_extension(res, fname, 1);
                if ( !res )
                {
                    res = rb_str_new2(rho_native_rhopath() );
                    rb_str_cat2(res,"/extensions/");

                    res = check_extension(res, fname,1);
                }

                if ( !res )
                {
                    res = rb_str_new2( rho_simconf_getString("ext_path") );
                    res = check_extension(res, fname, 0);
                }
*/
                const char* szPaths = rho_simconf_getString("ext_path");
                const char* szPath = szPaths;
                const char* szSep = strchr(szPath, ';');
                res = 0;
                for( ; szSep; szSep = strchr(szPath, ';') )
                {
                    res = rb_str_new( szPath, szSep-szPath);
                    rb_str_cat2(res,"/");
                    rb_str_append(res,fname);
                    rb_str_cat2(res,RHO_RB_EXT);

                    if ( eaccess(RSTRING_PTR(res), R_OK) == 0 )
                        break;

                    res = rb_str_new( szPath, szSep-szPath);
                    rb_str_cat2(res,"/app/");
                    rb_str_append(res,fname);
                    rb_str_cat2(res,RHO_RB_EXT);

                    if ( eaccess(RSTRING_PTR(res), R_OK) == 0 )
                        break;

                    res = 0;
                    szPath = szSep+1;
                }

                if( res )
                    nOK = 1;
                else
                    return 0;
#else
                return 0;
#endif
                
//.........这里部分代码省略.........
开发者ID:4nkh,项目名称:rhodes,代码行数:101,代码来源:rhosupport.c


示例20: rb_mysql_result_fetch_row

static VALUE rb_mysql_result_fetch_row(int argc, VALUE * argv, VALUE self) {
  VALUE rowHash, opts, block;
  mysql2_result_wrapper * wrapper;
  MYSQL_ROW row;
  MYSQL_FIELD * fields = NULL;
  unsigned int i = 0, symbolizeKeys = 0;
  unsigned long * fieldLengths;
  void * ptr;
#ifdef HAVE_RUBY_ENCODING_H
  rb_encoding *default_internal_enc = rb_default_internal_encoding();
  rb_encoding *conn_enc = rb_to_encoding(rb_iv_get(self, "@encoding"));
#endif

  GetMysql2Result(self, wrapper);

  if (rb_scan_args(argc, argv, "01&", &opts, &block) == 1) {
    Check_Type(opts, T_HASH);
    if (rb_hash_aref(opts, sym_symbolize_keys) == Qtrue) {
        symbolizeKeys = 1;
    }
  }

  ptr = wrapper->result;
  row = (MYSQL_ROW)rb_thread_blocking_region(nogvl_fetch_row, ptr, RUBY_UBF_IO, 0);
  if (row == NULL) {
    return Qnil;
  }

  rowHash = rb_hash_new();
  fields = mysql_fetch_fields(wrapper->result);
  fieldLengths = mysql_fetch_lengths(wrapper->result);
  if (wrapper->fields == Qnil) {
    wrapper->numberOfFields = mysql_num_fields(wrapper->result);
    wrapper->fields = rb_ary_new2(wrapper->numberOfFields);
  }

  for (i = 0; i < wrapper->numberOfFields; i++) {
    VALUE field = rb_mysql_result_fetch_field(self, i, symbolizeKeys);
    if (row[i]) {
      VALUE val;
      switch(fields[i].type) {
        case MYSQL_TYPE_NULL:       // NULL-type field
          val = Qnil;
          break;
        case MYSQL_TYPE_BIT:        // BIT field (MySQL 5.0.3 and up)
          val = rb_str_new(row[i], fieldLengths[i]);
          break;
        case MYSQL_TYPE_TINY:       // TINYINT field
        case MYSQL_TYPE_SHORT:      // SMALLINT field
        case MYSQL_TYPE_LONG:       // INTEGER field
        case MYSQL_TYPE_INT24:      // MEDIUMINT field
        case MYSQL_TYPE_LONGLONG:   // BIGINT field
        case MYSQL_TYPE_YEAR:       // YEAR field
          val = rb_cstr2inum(row[i], 10);
          break;
        case MYSQL_TYPE_DECIMAL:    // DECIMAL or NUMERIC field
        case MYSQL_TYPE_NEWDECIMAL: // Precision math DECIMAL or NUMERIC field (MySQL 5.0.3 and up)
          val = rb_funcall(cBigDecimal, intern_new, 1, rb_str_new(row[i], fieldLengths[i]));
          break;
        case MYSQL_TYPE_FLOAT:      // FLOAT field
        case MYSQL_TYPE_DOUBLE:     // DOUBLE or REAL field
          val = rb_float_new(strtod(row[i], NULL));
          break;
        case MYSQL_TYPE_TIME: {     // TIME field
          int hour, min, sec, tokens;
          tokens = sscanf(row[i], "%2d:%2d:%2d", &hour, &min, &sec);
          val = rb_funcall(rb_cTime, intern_utc, 6, INT2NUM(0), INT2NUM(1), INT2NUM(1), INT2NUM(hour), INT2NUM(min), INT2NUM(sec));
          break;
        }
        case MYSQL_TYPE_TIMESTAMP:  // TIMESTAMP field
        case MYSQL_TYPE_DATETIME: { // DATETIME field
          int year, month, day, hour, min, sec, tokens;
          tokens = sscanf(row[i], "%4d-%2d-%2d %2d:%2d:%2d", &year, &month, &day, &hour, &min, &sec);
          if (year+month+day+hour+min+sec == 0) {
            val = Qnil;
          } else {
            if (month < 1 || day < 1) {
              rb_raise(cMysql2Error, "Invalid date: %s", row[i]);
              val = Qnil;
            } else {
              val = rb_funcall(rb_cTime, intern_utc, 6, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), INT2NUM(sec));
            }
          }
          break;
        }
        case MYSQL_TYPE_DATE:       // DATE field
        case MYSQL_TYPE_NEWDATE: {  // Newer const used > 5.0
          int year, month, day, tokens;
          tokens = sscanf(row[i], "%4d-%2d-%2d", &year, &month, &day);
          if (year+month+day == 0) {
            val = Qnil;
          } else {
            if (month < 1 || day < 1) {
              rb_raise(cMysql2Error, "Invalid date: %s", row[i]);
              val = Qnil;
            } else {
              val = rb_funcall(cDate, intern_new, 3, INT2NUM(year), INT2NUM(month), INT2NUM(day));
            }
          }
          break;
//.........这里部分代码省略.........
开发者ID:orghub,项目名称:mysql2,代码行数:101,代码来源:result.c



注:本文中的rb_str_new函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ rb_str_new2函数代码示例发布时间:2022-05-30
下一篇:
C++ rb_str_export_to_enc函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap