2009-12-07 09:06:06 -05:00
|
|
|
|
|
|
|
#include "v8.h"
|
2011-04-11 00:19:26 -04:00
|
|
|
#include "v8_handle.h"
|
2010-05-31 03:06:29 -04:00
|
|
|
#include "v8_value.h"
|
2011-04-11 10:34:25 -04:00
|
|
|
#include "v8_string.h"
|
2009-12-07 09:06:06 -05:00
|
|
|
|
|
|
|
using namespace v8;
|
|
|
|
|
2010-05-12 18:30:53 -04:00
|
|
|
namespace {
|
|
|
|
VALUE StringClass;
|
|
|
|
|
2011-04-11 00:19:26 -04:00
|
|
|
Persistent<String>& unwrap(VALUE value) {
|
|
|
|
return rr_v8_handle<String>(value);
|
2010-05-12 18:30:53 -04:00
|
|
|
}
|
2010-06-08 03:38:32 -04:00
|
|
|
VALUE New(VALUE string_class, VALUE data) {
|
2010-05-19 08:55:11 -04:00
|
|
|
HandleScope handles;
|
2010-05-12 18:30:53 -04:00
|
|
|
VALUE str = rb_funcall(data, rb_intern("to_s"), 0);
|
2011-04-11 00:19:26 -04:00
|
|
|
return rr_v8_handle_new(string_class, String::New(RSTRING_PTR(str), RSTRING_LEN(str)));
|
2010-05-12 18:30:53 -04:00
|
|
|
}
|
2010-06-08 03:38:32 -04:00
|
|
|
VALUE NewSymbol(VALUE string_class, VALUE data) {
|
2010-06-08 07:33:54 -04:00
|
|
|
HandleScope scope;
|
2010-06-08 00:44:30 -04:00
|
|
|
VALUE str = rb_funcall(data, rb_intern("to_s"), 0);
|
2011-04-11 00:19:26 -04:00
|
|
|
return rr_v8_handle_new(string_class, String::NewSymbol(RSTRING_PTR(str), RSTRING_LEN(str)));
|
2010-06-08 00:44:30 -04:00
|
|
|
}
|
2010-05-12 18:30:53 -04:00
|
|
|
VALUE Utf8Value(VALUE self) {
|
2010-05-19 08:55:11 -04:00
|
|
|
HandleScope handles;
|
2010-05-12 18:30:53 -04:00
|
|
|
return rb_str_new2(*String::Utf8Value(unwrap(self)));
|
|
|
|
}
|
|
|
|
VALUE Utf16Value(VALUE self) {
|
|
|
|
//How are UTF16 strings represented in ruby 1.8, 1.9
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
VALUE AsciiValue(VALUE self) {
|
2010-05-19 08:55:11 -04:00
|
|
|
HandleScope handles;
|
2010-05-12 18:30:53 -04:00
|
|
|
return rb_str_new2(*String::AsciiValue(unwrap(self)));
|
|
|
|
}
|
2010-05-10 08:56:52 -04:00
|
|
|
}
|
|
|
|
|
2010-05-12 18:30:53 -04:00
|
|
|
VALUE rr_reflect_v8_string(Handle<Value> value) {
|
2011-04-22 11:06:47 -04:00
|
|
|
return rr_v8_handle_new(StringClass, Handle<String>::Cast(value));
|
2009-12-07 09:06:06 -05:00
|
|
|
}
|
|
|
|
|
2011-04-11 10:34:25 -04:00
|
|
|
void rr_init_string() {
|
2011-04-11 14:32:14 -04:00
|
|
|
StringClass = rr_define_class("String", rr_v8_value_class());
|
2010-05-12 18:30:53 -04:00
|
|
|
rr_define_singleton_method(StringClass, "New", New, 1);
|
2010-06-08 03:38:32 -04:00
|
|
|
rr_define_singleton_method(StringClass, "NewSymbol", NewSymbol, 1);
|
2010-05-12 18:30:53 -04:00
|
|
|
rr_define_method(StringClass, "Utf8Value", Utf8Value, 0);
|
|
|
|
rr_define_method(StringClass, "Utf16Value", Utf16Value, 0);
|
|
|
|
rr_define_method(StringClass, "AsciiValue", AsciiValue, 0);
|
2009-12-07 09:06:06 -05:00
|
|
|
}
|