当前位置: 首页>>代码示例>>C++>>正文


C++ Fixnum::to_native方法代码示例

本文整理汇总了C++中Fixnum::to_native方法的典型用法代码示例。如果您正苦于以下问题:C++ Fixnum::to_native方法的具体用法?C++ Fixnum::to_native怎么用?C++ Fixnum::to_native使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Fixnum的用法示例。


在下文中一共展示了Fixnum::to_native方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: matched_string

  String* MatchData::matched_string(STATE) {
    Fixnum* beg = try_as<Fixnum>(full_->at(state, 0));
    Fixnum* fin = try_as<Fixnum>(full_->at(state, 1));

    native_int max = source_->byte_size();
    native_int f = fin->to_native();
    native_int b = beg->to_native();

    String* string;

    if(!beg || !fin ||
        f > max || b > max || b < 0) {
      string = String::create(state, 0, 0);
    } else {
      const char* str = (char*)source_->byte_address();
      native_int sz = fin->to_native() - beg->to_native();

      string = String::create(state, str + beg->to_native(), sz);
    }

    source_->infect(state, string);
    string->encoding_from(state, source_);
    string->klass(state, source_->class_object(state));
    
    return string;
  }
开发者ID:Halfnhav,项目名称:rubinius,代码行数:26,代码来源:regexp.cpp

示例2: nth_capture

  Object* MatchData::nth_capture(STATE, native_int which) {
    if(region_->num_fields() <= which) return cNil;

    Tuple* sub = try_as<Tuple>(region_->at(state, which));
    if(!sub) return cNil;

    Fixnum* beg = try_as<Fixnum>(sub->at(state, 0));
    Fixnum* fin = try_as<Fixnum>(sub->at(state, 1));

    native_int b = beg->to_native();
    native_int f = fin->to_native();
    native_int max = source_->byte_size();

    if(!beg || !fin ||
        f > max ||
        b < 0) {
      return cNil;
    }

    const char* str = (char*)source_->byte_address();
    native_int sz = f - b;

    if(sz > max) sz = max;

    String* string = String::create(state, str + b, sz);
    string->encoding(state, source_->encoding());

    return string;
  }
开发者ID:DanielVartanov,项目名称:rubinius,代码行数:29,代码来源:regexp.cpp

示例3: pre_matched

  String* MatchData::pre_matched(STATE) {
    Fixnum* beg = try_as<Fixnum>(full_->at(state, 0));

    if(!beg || beg->to_native() <= 0) {
      return String::create(state, 0, 0);
    }

    const char* str = source_->c_str();
    native_int sz = beg->to_native();

    return String::create(state, str, sz);
  }
开发者ID:thiagopradi,项目名称:rubinius,代码行数:12,代码来源:regexp.cpp

示例4: post_matched

  String* MatchData::post_matched(STATE) {
    Fixnum* fin = try_as<Fixnum>(full_->at(state, 1));

    if(!fin || fin->to_native() >= source_->size()) {
      return String::create(state, 0, 0);
    }

    const char* str = source_->c_str();
    native_int sz = (native_int)source_->size() - fin->to_native();

    return String::create(state, str + fin->to_native(), sz);
  }
开发者ID:thiagopradi,项目名称:rubinius,代码行数:12,代码来源:regexp.cpp

示例5: matched_string

  String* MatchData::matched_string(STATE) {
    Fixnum* beg = try_as<Fixnum>(full_->at(state, 0));
    Fixnum* fin = try_as<Fixnum>(full_->at(state, 1));

    if(!beg || !fin ||
        fin->to_native() > source_->size() ||
        beg->to_native() < 0) {
      return String::create(state, 0, 0);
    }

    const char* str = source_->c_str();
    native_int sz = fin->to_native() - beg->to_native();

    return String::create(state, str + beg->to_native(), sz);
  }
开发者ID:thiagopradi,项目名称:rubinius,代码行数:15,代码来源:regexp.cpp

示例6: test_add

  void test_add() {
    Fixnum* one = Fixnum::from(1);
    Fixnum* two = as<Fixnum>(one->add(state, one));

    TS_ASSERT_EQUALS(Fixnum::from(2), two);
    TS_ASSERT_EQUALS(2, two->to_native());
  }
开发者ID:chuckremes,项目名称:rubinius,代码行数:7,代码来源:test_fixnum.hpp

示例7: test_sub

  void test_sub() {
    Fixnum* one = Fixnum::from(1);
    Fixnum* zero = as<Fixnum>(one->sub(state, one));

    TS_ASSERT_EQUALS(0, zero->to_native());
    TS_ASSERT_EQUALS(Fixnum::from(0), zero);
  }
开发者ID:chuckremes,项目名称:rubinius,代码行数:7,代码来源:test_fixnum.hpp

示例8: post_matched

  String* MatchData::post_matched(STATE) {
    Fixnum* fin = try_as<Fixnum>(full_->at(state, 1));

    native_int f = fin->to_native();
    native_int max = source_->byte_size();

    String* string;

    if(!fin || f >= max) {
      string = String::create(state, 0, 0);
    } else {
      const char* str = (char*)source_->byte_address();
      native_int sz = max - f;

      if(sz > max) sz = max;

      string = String::create(state, str + f, sz);
    }

    source_->infect(state, string);
    string->encoding_from(state, source_);
    string->klass(state, source_->class_object(state));

    return string;
  }
开发者ID:Halfnhav,项目名称:rubinius,代码行数:25,代码来源:regexp.cpp

示例9: packed_ivar_delete

  Object* PackedObject::packed_ivar_delete(STATE, Symbol* sym, bool* removed) {
    LookupTable* tbl = this->reference_class()->packed_ivar_info();
    bool found = false;

    Fixnum* which = try_as<Fixnum>(tbl->fetch(state, sym, &found));
    if(!found) {
      return del_table_ivar(state, sym, removed);
    }

    if(removed) *removed = true;

    Object* val = body_as_array()[which->to_native()];
    body_as_array()[which->to_native()] = Qundef;

    return val;
  }
开发者ID:AndreMeira,项目名称:rubinius,代码行数:16,代码来源:packed_object.cpp

示例10: matched_string

  String* MatchData::matched_string(STATE) {
    Fixnum* beg = try_as<Fixnum>(full_->at(state, 0));
    Fixnum* fin = try_as<Fixnum>(full_->at(state, 1));

    native_int max = source_->size();
    native_int f = fin->to_native();
    native_int b = beg->to_native();

    if(!beg || !fin ||
        f > max || b > max || b < 0) {
      return String::create(state, 0, 0);
    }

    const char* str = (char*)source_->byte_address();
    native_int sz = fin->to_native() - beg->to_native();

    return String::create(state, str + beg->to_native(), sz);
  }
开发者ID:Gimi,项目名称:rubinius,代码行数:18,代码来源:regexp.cpp

示例11: test_div

  void test_div() {
    Fixnum* one = as<Fixnum>(Fixnum::from(4));

    Fixnum* two = as<Fixnum>(one->div(state, one));
    TS_ASSERT_EQUALS(two->to_native(), 1);

    Fixnum* zero = Fixnum::from(0);
    TS_ASSERT_THROWS_ASSERT(one->div(state, zero), const RubyException &e,
                            TS_ASSERT(Exception::zero_division_error_p(state, e.exception)));
  }
开发者ID:chuckremes,项目名称:rubinius,代码行数:10,代码来源:test_fixnum.hpp

示例12: test_control_tells_current_position

 /** @todo Is it a valid assumption that the position always increases? */
 void test_control_tells_current_position() {
   char *dir = make_directory();
   String* path = String::create(state, dir);
   d->open(state, path);
   Fixnum* pos = (Fixnum*)d->control(state, Fixnum::from(2), Fixnum::from(0));
   d->read(state);
   Fixnum* pos2 = (Fixnum*)d->control(state, Fixnum::from(2), Fixnum::from(0));
   TS_ASSERT_LESS_THAN(pos->to_native(), pos2->to_native());
   remove_directory(dir);
 }
开发者ID:marnen,项目名称:rubinius,代码行数:11,代码来源:test_dir.hpp

示例13: nth_capture

  Object* MatchData::nth_capture(STATE, native_int which) {
    if(region_->num_fields() <= which) return Qnil;

    Tuple* sub = try_as<Tuple>(region_->at(state, which));
    if(!sub) return Qnil;

    Fixnum* beg = try_as<Fixnum>(sub->at(state, 0));
    Fixnum* fin = try_as<Fixnum>(sub->at(state, 1));

    if(!beg || !fin ||
        fin->to_native() > source_->size() ||
        beg->to_native() < 0) {
      return Qnil;
    }

    const char* str = source_->c_str();
    native_int sz = fin->to_native() - beg->to_native();

    return String::create(state, str + beg->to_native(), sz);
  }
开发者ID:thiagopradi,项目名称:rubinius,代码行数:20,代码来源:regexp.cpp

示例14: get_packed_ivar

  Object* PackedObject::get_packed_ivar(STATE, Symbol* sym) {
    LookupTable* tbl = this->reference_class()->packed_ivar_info();
    assert(tbl && !tbl->nil_p());

    Fixnum* which = try_as<Fixnum>(tbl->fetch(state, sym));
    if(!which) {
      return get_table_ivar(state, sym);
    }

    Object* obj = body_as_array()[which->to_native()];
    if(obj == Qundef) return Qnil;
    return obj;
  }
开发者ID:atoulme,项目名称:rubinius,代码行数:13,代码来源:packed_object.cpp

示例15: immediate

    virtual Object* immediate() {
      native_int id = id_->to_native();

      if(id & TAG_REF_MASK) {
        Object* obj = reinterpret_cast<Object*>(id);

        // Be sure to not leak a bad reference leak out here.
        if(obj->reference_p()) return cNil;
        return obj;
      }

      return 0;
    }
开发者ID:Azzurrio,项目名称:rubinius,代码行数:13,代码来源:find_object.cpp


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