aboutsummaryrefslogtreecommitdiffstats
path: root/bignum.c
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-15 07:19:43 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-15 07:19:43 +0000
commit2cfc5b03dac80a92de2dc7a17be4b3cfff92adf7 (patch)
tree2f73938d92adf528407d46046d28b961f2d16aab /bignum.c
parent4691daccc156f290ca09effdd2558cd6dd0cec70 (diff)
downloadruby-2cfc5b03dac80a92de2dc7a17be4b3cfff92adf7.tar.gz
Add `exception:` keyword in Kernel#Integer()
Support `exception:` keyword argument in Kernel#Integer(). If `exception:` is `false`, `Kernel#Integer()` returns `nil` if the given value cannot be interpreted as an integer value. The default value of `exception:` is `true`. This is part of [Feature #12732]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/bignum.c b/bignum.c
index 6c40c778de..b4c7560034 100644
--- a/bignum.c
+++ b/bignum.c
@@ -4230,7 +4230,7 @@ rb_cstr_parse_inum(const char *str, ssize_t len, char **endp, int base)
}
VALUE
-rb_str_to_inum(VALUE str, int base, int badcheck)
+rb_str_convert_to_inum(VALUE str, int base, int badcheck, int raise_exception)
{
VALUE ret;
const char *s;
@@ -4242,13 +4242,22 @@ rb_str_to_inum(VALUE str, int base, int badcheck)
RSTRING_GETMEM(str, s, len);
ret = rb_cstr_parse_inum(s, len, (badcheck ? NULL : &end), base);
if (NIL_P(ret)) {
- if (badcheck) invalid_integer(str);
- ret = INT2FIX(0);
+ if (badcheck) {
+ if (!raise_exception) return Qnil;
+ invalid_integer(str);
+ }
+ ret = INT2FIX(0);
}
return ret;
}
VALUE
+rb_str_to_inum(VALUE str, int base, int badcheck)
+{
+ return rb_str_convert_to_inum(str, base, badcheck, TRUE);
+}
+
+VALUE
rb_str2big_poweroftwo(VALUE arg, int base, int badcheck)
{
int positive_p = 1;