Commit d83d2ba2 authored by abolz's avatar abolz

Trim all zeros from input

If the buffer only contains zeros, return 0.
parent c59ecc85
...@@ -242,17 +242,21 @@ inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t ...@@ -242,17 +242,21 @@ inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t
RAPIDJSON_ASSERT(dExp <= INT_MAX - dLen); RAPIDJSON_ASSERT(dExp <= INT_MAX - dLen);
// Trim leading zeros // Trim leading zeros
while (*decimals == '0' && dLen > 1) { while (dLen > 0 && *decimals == '0') {
dLen--; dLen--;
decimals++; decimals++;
} }
// Trim trailing zeros // Trim trailing zeros
while (decimals[dLen - 1] == '0' && dLen > 1) { while (dLen > 0 && decimals[dLen - 1] == '0') {
dLen--; dLen--;
dExp++; dExp++;
} }
if (dLen == 0) { // Buffer only contains zeros.
return 0.0;
}
// Trim right-most digits // Trim right-most digits
const int kMaxDecimalDigit = 780; const int kMaxDecimalDigit = 780;
if (dLen > kMaxDecimalDigit) { if (dLen > kMaxDecimalDigit) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment