Skip to content

Commit

Permalink
Simplify parse_double_float() in util/pcre.cc.
Browse files Browse the repository at this point in the history
Change-Id: Ie7e7b3f12f44471d3bed3062420e6dd5e15b1ea7
Reviewed-on: https://code-review.googlesource.com/c/re2/+/47590
Reviewed-by: Paul Wankadia <[email protected]>
  • Loading branch information
junyer committed Oct 29, 2019
1 parent ab12219 commit 1911d98
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions util/pcre.cc
Original file line number Diff line number Diff line change
Expand Up @@ -978,32 +978,7 @@ static bool parse_double_float(const char* str, size_t n, bool isfloat,
} else {
r = strtod(buf, &end);
}
if (end != buf + n) {
#ifdef _WIN32
// Microsoft's strtod() doesn't handle inf and nan, so we have to
// handle it explicitly. Speed is not important here because this
// code is only called in unit tests.
bool pos = true;
const char* i = buf;
if ('-' == *i) {
pos = false;
++i;
} else if ('+' == *i) {
++i;
}
if (0 == _stricmp(i, "inf") || 0 == _stricmp(i, "infinity")) {
r = std::numeric_limits<double>::infinity();
if (!pos)
r = -r;
} else if (0 == _stricmp(i, "nan")) {
r = std::numeric_limits<double>::quiet_NaN();
} else {
return false;
}
#else
return false; // Leftover junk
#endif
}
if (end != buf + n) return false; // Leftover junk
if (errno) return false;
if (dest == NULL) return true;
if (isfloat) {
Expand Down

0 comments on commit 1911d98

Please sign in to comment.