Skip to content

Commit

Permalink
Add rb_str_length
Browse files Browse the repository at this point in the history
  • Loading branch information
dbussink committed Sep 28, 2012
1 parent 03502d9 commit acaddd2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions vm/capi/19/include/ruby/ruby.h
Expand Up @@ -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));

Expand Down
7 changes: 7 additions & 0 deletions vm/capi/string.cpp
Expand Up @@ -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();

Expand Down

0 comments on commit acaddd2

Please sign in to comment.