mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
@@ -163,6 +163,12 @@ mrb_str_end_with(mrb_state *mrb, mrb_value self)
|
||||
return mrb_false_value();
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
mrb_str_hex(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
return mrb_str_to_inum(mrb, self, 16, FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
mrb_mruby_string_ext_gem_init(mrb_state* mrb)
|
||||
{
|
||||
@@ -176,6 +182,7 @@ mrb_mruby_string_ext_gem_init(mrb_state* mrb)
|
||||
mrb_define_method(mrb, s, "<<", mrb_str_concat2, MRB_ARGS_REQ(1));
|
||||
mrb_define_method(mrb, s, "start_with?", mrb_str_start_with, MRB_ARGS_REST());
|
||||
mrb_define_method(mrb, s, "end_with?", mrb_str_end_with, MRB_ARGS_REST());
|
||||
mrb_define_method(mrb, s, "hex", mrb_str_hex, MRB_ARGS_NONE());
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -133,3 +133,13 @@ assert('String#rpartition') do
|
||||
assert_equal ["", "b", "aaaa"], "baaaa".rpartition("b")
|
||||
assert_equal ["", "", ""], "".rpartition("a")
|
||||
end
|
||||
|
||||
assert('String#hex') do
|
||||
assert_equal 16, "10".hex
|
||||
assert_equal 255, "ff".hex
|
||||
assert_equal 16, "0x10".hex
|
||||
assert_equal (-16), "-0x10".hex
|
||||
assert_equal 0, "xyz".hex
|
||||
assert_equal 16, "10z".hex
|
||||
assert_equal 0, "".hex
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user