Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add rb_str_length

  • Loading branch information...
commit acaddd20b09b93af4ff36cbf4855c2b492b103de 1 parent 03502d9
@dbussink dbussink authored
Showing with 9 additions and 0 deletions.
  1. +2 −0  vm/capi/19/include/ruby/ruby.h
  2. +7 −0 vm/capi/string.cpp
View
2  vm/capi/19/include/ruby/ruby.h
@@ -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
7 vm/capi/string.cpp
@@ -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();
Please sign in to comment.
Something went wrong with that request. Please try again.