2012-05-02 19:15:11 -04:00
|
|
|
#include "rr.h"
|
|
|
|
|
|
|
|
namespace rr {
|
|
|
|
namespace {
|
|
|
|
VALUE New(VALUE StringClass, VALUE string) {
|
2012-05-03 03:24:15 -04:00
|
|
|
v8::HandleScope h;
|
|
|
|
return String::ToRuby(v8::String::New(RSTRING_PTR(string), (int)RSTRING_LEN(string)));
|
2012-05-02 19:15:11 -04:00
|
|
|
}
|
2012-05-03 14:01:10 -04:00
|
|
|
VALUE Utf8Value(VALUE self) {
|
|
|
|
v8::HandleScope h;
|
|
|
|
String str(self);
|
|
|
|
return rb_str_new(*v8::String::Utf8Value(str), str->Utf8Length());
|
|
|
|
}
|
2012-05-02 19:15:11 -04:00
|
|
|
}
|
|
|
|
|
2012-05-03 03:24:15 -04:00
|
|
|
VALUE String::ToRuby(v8::Handle<v8::String> string) {
|
2012-05-03 14:01:10 -04:00
|
|
|
return String::create(string, String::Class);
|
2012-05-03 03:24:15 -04:00
|
|
|
}
|
|
|
|
|
2012-05-03 14:01:10 -04:00
|
|
|
String::operator v8::Handle<v8::Value>() {
|
|
|
|
return this->GetHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE String::Class;
|
|
|
|
|
2012-05-02 19:15:11 -04:00
|
|
|
void String::Init() {
|
2012-05-03 14:01:10 -04:00
|
|
|
rb_gc_register_address(&Class);
|
|
|
|
Class = defineClass("String");
|
|
|
|
RR_DEFINE_SINGLETON_METHOD(Class, "New", &New, 1);
|
|
|
|
RR_DEFINE_METHOD(Class, "Utf8Value", &Utf8Value, 0);
|
2012-05-02 19:15:11 -04:00
|
|
|
}
|
|
|
|
}
|