mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* bignum.c (str2big_scan_digits): Extracted from rb_cstr_to_inum.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
736f97b278
commit
c048ad23b6
2 changed files with 55 additions and 32 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Tue Sep 3 12:03:02 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* bignum.c (str2big_scan_digits): Extracted from rb_cstr_to_inum.
|
||||||
|
|
||||||
Tue Sep 3 11:23:57 2013 NAKAMURA Usaku <usa@ruby-lang.org>
|
Tue Sep 3 11:23:57 2013 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* win32/win32.c (rb_w32_select_with_thread): rounding up the fraction of
|
* win32/win32.c (rb_w32_select_with_thread): rounding up the fraction of
|
||||||
|
|
83
bignum.c
83
bignum.c
|
@ -3571,6 +3571,48 @@ rb_quad_unpack(const char *buf, int signed_p)
|
||||||
|
|
||||||
#define conv_digit(c) (ruby_digit36_to_number_table[(unsigned char)(c)])
|
#define conv_digit(c) (ruby_digit36_to_number_table[(unsigned char)(c)])
|
||||||
|
|
||||||
|
static void
|
||||||
|
str2big_scan_digits(const char *s, const char *str, int base, int badcheck, size_t *num_digits_p, size_t *len_p)
|
||||||
|
{
|
||||||
|
char nondigit = 0;
|
||||||
|
size_t num_digits = 0;
|
||||||
|
const char *digits_start = str;
|
||||||
|
const char *digits_end = str;
|
||||||
|
|
||||||
|
int c;
|
||||||
|
|
||||||
|
if (badcheck && *str == '_') goto bad;
|
||||||
|
|
||||||
|
while ((c = *str++) != 0) {
|
||||||
|
if (c == '_') {
|
||||||
|
if (nondigit) {
|
||||||
|
if (badcheck) goto bad;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nondigit = (char) c;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if ((c = conv_digit(c)) < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (c >= base) break;
|
||||||
|
nondigit = 0;
|
||||||
|
num_digits++;
|
||||||
|
digits_end = str;
|
||||||
|
}
|
||||||
|
if (badcheck) {
|
||||||
|
str--;
|
||||||
|
if (s+1 < str && str[-1] == '_') goto bad;
|
||||||
|
while (*str && ISSPACE(*str)) str++;
|
||||||
|
if (*str) {
|
||||||
|
bad:
|
||||||
|
rb_invalid_str(s, "Integer()");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*num_digits_p = num_digits;
|
||||||
|
*len_p = digits_end - digits_start;
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
str2big_poweroftwo(
|
str2big_poweroftwo(
|
||||||
int sign,
|
int sign,
|
||||||
|
@ -3743,7 +3785,7 @@ VALUE
|
||||||
rb_cstr_to_inum(const char *str, int base, int badcheck)
|
rb_cstr_to_inum(const char *str, int base, int badcheck)
|
||||||
{
|
{
|
||||||
const char *s = str;
|
const char *s = str;
|
||||||
char sign = 1, nondigit = 0;
|
char sign = 1;
|
||||||
int c;
|
int c;
|
||||||
VALUE z;
|
VALUE z;
|
||||||
|
|
||||||
|
@ -3752,9 +3794,13 @@ rb_cstr_to_inum(const char *str, int base, int badcheck)
|
||||||
const char *digits_start, *digits_end;
|
const char *digits_start, *digits_end;
|
||||||
size_t num_digits;
|
size_t num_digits;
|
||||||
size_t num_bdigits;
|
size_t num_bdigits;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
if (!str) {
|
if (!str) {
|
||||||
if (badcheck) goto bad;
|
if (badcheck) {
|
||||||
|
bad:
|
||||||
|
rb_invalid_str(s, "Integer()");
|
||||||
|
}
|
||||||
return INT2FIX(0);
|
return INT2FIX(0);
|
||||||
}
|
}
|
||||||
while (ISSPACE(*str)) str++;
|
while (ISSPACE(*str)) str++;
|
||||||
|
@ -3868,36 +3914,9 @@ rb_cstr_to_inum(const char *str, int base, int badcheck)
|
||||||
}
|
}
|
||||||
|
|
||||||
bigparse:
|
bigparse:
|
||||||
if (badcheck && *str == '_') goto bad;
|
digits_start = str;
|
||||||
|
str2big_scan_digits(s, str, base, badcheck, &num_digits, &len);
|
||||||
num_digits = 0;
|
digits_end = digits_start + len;
|
||||||
digits_start = digits_end = str;
|
|
||||||
while ((c = *str++) != 0) {
|
|
||||||
if (c == '_') {
|
|
||||||
if (nondigit) {
|
|
||||||
if (badcheck) goto bad;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
nondigit = (char) c;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if ((c = conv_digit(c)) < 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (c >= base) break;
|
|
||||||
nondigit = 0;
|
|
||||||
num_digits++;
|
|
||||||
digits_end = str;
|
|
||||||
}
|
|
||||||
if (badcheck) {
|
|
||||||
str--;
|
|
||||||
if (s+1 < str && str[-1] == '_') goto bad;
|
|
||||||
while (*str && ISSPACE(*str)) str++;
|
|
||||||
if (*str) {
|
|
||||||
bad:
|
|
||||||
rb_invalid_str(s, "Integer()");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (POW2_P(base)) {
|
if (POW2_P(base)) {
|
||||||
z = str2big_poweroftwo(sign, digits_start, digits_end, num_digits,
|
z = str2big_poweroftwo(sign, digits_start, digits_end, num_digits,
|
||||||
|
|
Loading…
Reference in a new issue