mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* object.c (rb_cstr_to_dbl): check for successive underscores.
[ruby-dev:33952] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8ba29591af
commit
b4b3180bfa
4 changed files with 23 additions and 12 deletions
|
@ -1,3 +1,8 @@
|
|||
Sun Mar 2 00:08:10 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* object.c (rb_cstr_to_dbl): check for successive underscores.
|
||||
[ruby-dev:33952]
|
||||
|
||||
Sat Mar 1 17:59:01 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* io.c (struct argf): packed ARGF stuffs.
|
||||
|
|
19
object.c
19
object.c
|
@ -2050,8 +2050,8 @@ rb_cstr_to_dbl(const char *p, int badcheck)
|
|||
errno = 0;
|
||||
}
|
||||
if (p == end) {
|
||||
bad:
|
||||
if (badcheck) {
|
||||
bad:
|
||||
rb_invalid_str(q, "Float()");
|
||||
}
|
||||
return d;
|
||||
|
@ -2060,19 +2060,24 @@ rb_cstr_to_dbl(const char *p, int badcheck)
|
|||
char buf[DBL_DIG * 4 + 10];
|
||||
char *n = buf;
|
||||
char *e = buf + sizeof(buf) - 1;
|
||||
char prev = 0;
|
||||
|
||||
while (p < end && n < e) *n++ = *p++;
|
||||
while (n < e && *p) {
|
||||
while (*p) {
|
||||
if (*p == '_') {
|
||||
/* remove underscores between digits */
|
||||
if (n == buf || !ISDIGIT(n[-1])) goto bad;
|
||||
if (badcheck) {
|
||||
if (n == buf || !ISDIGIT(prev)) goto bad;
|
||||
++p;
|
||||
if (!ISDIGIT(*p)) goto bad;
|
||||
}
|
||||
else {
|
||||
while (*++p == '_');
|
||||
if (!ISDIGIT(*p)) {
|
||||
if (badcheck) goto bad;
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
*n++ = *p++;
|
||||
prev = *p++;
|
||||
if (n < e) *n++ = prev;
|
||||
}
|
||||
*n = '\0';
|
||||
p = buf;
|
||||
|
|
|
@ -81,6 +81,7 @@ class TestFloat < Test::Unit::TestCase
|
|||
assert_raise(ArgumentError){Float("-")}
|
||||
assert_raise(ArgumentError){Float("-.")}
|
||||
assert_raise(ArgumentError){Float("1e")}
|
||||
assert_raise(ArgumentError){Float("1__1")}
|
||||
# add expected behaviour here.
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#define RUBY_VERSION "1.9.0"
|
||||
#define RUBY_RELEASE_DATE "2008-03-01"
|
||||
#define RUBY_RELEASE_DATE "2008-03-02"
|
||||
#define RUBY_VERSION_CODE 190
|
||||
#define RUBY_RELEASE_CODE 20080301
|
||||
#define RUBY_RELEASE_CODE 20080302
|
||||
#define RUBY_PATCHLEVEL 0
|
||||
|
||||
#define RUBY_VERSION_MAJOR 1
|
||||
|
@ -9,7 +9,7 @@
|
|||
#define RUBY_VERSION_TEENY 0
|
||||
#define RUBY_RELEASE_YEAR 2008
|
||||
#define RUBY_RELEASE_MONTH 3
|
||||
#define RUBY_RELEASE_DAY 1
|
||||
#define RUBY_RELEASE_DAY 2
|
||||
|
||||
#ifdef RUBY_EXTERN
|
||||
RUBY_EXTERN const char ruby_version[];
|
||||
|
|
Loading…
Reference in a new issue