Permalink
Browse files

Add rb_str_length

  • Loading branch information...
1 parent 03502d9 commit acaddd20b09b93af4ff36cbf4855c2b492b103de @dbussink dbussink committed Sep 28, 2012
Showing with 9 additions and 0 deletions.
  1. +2 −0 vm/capi/19/include/ruby/ruby.h
  2. +7 −0 vm/capi/string.cpp
@@ -1765,6 +1765,8 @@ VALUE rb_uint2big(unsigned long number);
long rb_str_hash(VALUE str);
+ VALUE rb_str_length(VALUE self);
+
/** Raises an exception from the value of errno. */
NORETURN(void rb_sys_fail(const char* mesg));
View
@@ -460,6 +460,13 @@ extern "C" {
return string->byte_size();
}
+ VALUE rb_str_length(VALUE self) {
+ NativeMethodEnvironment* env = NativeMethodEnvironment::get();
+
+ String* string = capi_get_string(env, self);
+ return LONG2FIX(string->char_size(env->state()));
+ }
+
void rb_str_set_len(VALUE self, size_t len) {
NativeMethodEnvironment* env = NativeMethodEnvironment::get();

0 comments on commit acaddd2

Please sign in to comment.