Sha256: 2eb0e4df83c1fc6de81267b3b1a638454a0af3d1bb3549f934b45aaa89ad161b

Contents?: true

Size: 1.36 KB

Versions: 37

Compression:

Stored size: 1.36 KB

Contents

#include "rr.h"

namespace rr {

void String::Init() {
  ClassBuilder("String", Primitive::Class).
    defineSingletonMethod("New", &New).
    defineSingletonMethod("NewSymbol", &NewSymbol).
    defineSingletonMethod("Concat", &Concat).
    defineMethod("Utf8Value", &Utf8Value).
    store(&Class);
}

VALUE String::New(VALUE StringClass, VALUE string) {
  return String(v8::String::New(RSTRING_PTR(string), (int)RSTRING_LEN(string)));
}

VALUE String::NewSymbol(VALUE self, VALUE string) {
  return String(v8::String::NewSymbol(RSTRING_PTR(string), (int)RSTRING_LEN(string)));
}

VALUE String::Utf8Value(VALUE self) {
  String str(self);
  #ifdef HAVE_RUBY_ENCODING_H
  return rb_enc_str_new(*v8::String::Utf8Value(*str), str->Utf8Length(), rb_enc_find("utf-8"));
  #else
  return rb_str_new(*v8::String::Utf8Value(*str), str->Utf8Length());
  #endif
}

VALUE String::Concat(VALUE self, VALUE left, VALUE right) {
  return String(v8::String::Concat(String(left), String(right)));
}

String::operator v8::Handle<v8::String>() const {
  switch (TYPE(value)) {
  case T_STRING:
    return v8::String::New(RSTRING_PTR(value), (int)RSTRING_LEN(value));
  case T_DATA:
    return Ref<v8::String>::operator v8::Handle<v8::String>();
  default:
    VALUE string = rb_funcall(value, rb_intern("to_s"), 0);
    return v8::String::New(RSTRING_PTR(string), (int)RSTRING_LEN(string));
  }
}

} //namespace rr

Version data entries

37 entries across 37 versions & 8 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/therubyracer-0.12.2/ext/v8/string.cc
therubyracer-0.12.3 ext/v8/string.cc
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/therubyracer-0.11.4/ext/v8/string.cc
therubyracer-xcode-0.12.3 ext/v8/string.cc
therubyracer-xcode-0.12.2 ext/v8/string.cc
therubyracer-tmpfork-0.12.2 ext/v8/string.cc
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/therubyracer-0.12.2/ext/v8/string.cc
therubyracer-0.12.2 ext/v8/string.cc
therubyracer-0.12.1 ext/v8/string.cc
therubyracer-discourse-0.12.0 ext/v8/string.cc
therubyracer-0.12.0 ext/v8/string.cc
therubyracer-0.11.4 ext/v8/string.cc
therubyracer-0.11.3 ext/v8/string.cc
therubyracer-0.11.2 ext/v8/string.cc
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/therubyracer-0.11.0/ext/v8/string.cc
therubyracer-0.11.1 ext/v8/string.cc
therubyracer-0.11.1beta1 ext/v8/string.cc
therubyracer-0.11.0 ext/v8/string.cc
therubyracer-0.11.0beta8-x86-freebsd-9 ext/v8/string.cc
therubyracer-0.11.0beta8-x86_64-linux ext/v8/string.cc