Commit b48514bd authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #2663 from iij/pr-fix-string-utf8-aref

adding mruby-string-utf8 breaks String#[float]
parents ea828944 5f68be71
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "mruby/class.h" #include "mruby/class.h"
#include "mruby/string.h" #include "mruby/string.h"
#include "mruby/range.h" #include "mruby/range.h"
#include "mruby/numeric.h"
#include "mruby/re.h" #include "mruby/re.h"
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
...@@ -257,6 +258,8 @@ mrb_str_aref(mrb_state *mrb, mrb_value str, mrb_value indx) ...@@ -257,6 +258,8 @@ mrb_str_aref(mrb_state *mrb, mrb_value str, mrb_value indx)
mrb_regexp_check(mrb, indx); mrb_regexp_check(mrb, indx);
switch (mrb_type(indx)) { switch (mrb_type(indx)) {
case MRB_TT_FLOAT:
indx = mrb_flo_to_fixnum(mrb, indx);
case MRB_TT_FIXNUM: case MRB_TT_FIXNUM:
idx = mrb_fixnum(indx); idx = mrb_fixnum(indx);
......
...@@ -9,6 +9,7 @@ assert('String#[]') do ...@@ -9,6 +9,7 @@ assert('String#[]') do
assert_equal "世界", "こんにちは世界"[-2..-1] assert_equal "世界", "こんにちは世界"[-2..-1]
assert_equal "んに", "こんにちは世界"[1,2] assert_equal "んに", "こんにちは世界"[1,2]
assert_equal "世", "こんにちは世界"["世"] assert_equal "世", "こんにちは世界"["世"]
assert_equal 'b', 'abc'[1.1]
end end
assert('String#reverse', '15.2.10.5.29') do assert('String#reverse', '15.2.10.5.29') do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment