mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-25 12:04:47 +00:00
mg_dtoa, mg_atod, mg_lld made static
This commit is contained in:
1 parent
d2a27d3d91
commit
6b69bef2ef
6 files changed
+106
-113
No files matched your search
+46
@@ -28,6 +28,52 @@ static int mg_pass_string(const char *s, int len) {
|
||||
return MG_JSON_INVALID;
|
||||
}
|
||||
|
||||
static double mg_atod(const char *p, int len, int *numlen) {
|
||||
double d = 0.0;
|
||||
int i = 0, sign = 1;
|
||||
|
||||
// Sign
|
||||
if (i < len && *p == '-') {
|
||||
sign = -1, i++;
|
||||
} else if (i < len && *p == '+') {
|
||||
i++;
|
||||
}
|
||||
|
||||
// Decimal
|
||||
for (; i < len && p[i] >= '0' && p[i] <= '9'; i++) {
|
||||
d *= 10.0;
|
||||
d += p[i] - '0';
|
||||
}
|
||||
d *= sign;
|
||||
|
||||
// Fractional
|
||||
if (i < len && p[i] == '.') {
|
||||
double frac = 0.0, base = 0.1;
|
||||
i++;
|
||||
for (; i < len && p[i] >= '0' && p[i] <= '9'; i++) {
|
||||
frac += base * (p[i] - '0');
|
||||
base /= 10.0;
|
||||
}
|
||||
d += frac * sign;
|
||||
}
|
||||
|
||||
// Exponential
|
||||
if (i < len && (p[i] == 'e' || p[i] == 'E')) {
|
||||
int j, exp = 0, minus = 0;
|
||||
i++;
|
||||
if (i < len && p[i] == '-') minus = 1, i++;
|
||||
if (i < len && p[i] == '+') i++;
|
||||
while (i < len && p[i] >= '0' && p[i] <= '9' && exp < 308)
|
||||
exp = exp * 10 + (p[i++] - '0');
|
||||
if (minus) exp = -exp;
|
||||
for (j = 0; j < exp; j++) d *= 10.0;
|
||||
for (j = 0; j < -exp; j++) d /= 10.0;
|
||||
}
|
||||
|
||||
if (numlen != NULL) *numlen = i;
|
||||
return d;
|
||||
}
|
||||
|
||||
int mg_json_get(struct mg_str json, const char *path, int *toklen) {
|
||||
const char *s = json.ptr;
|
||||
int len = (int) json.len;
|
||||
|
||||
Reference in new issue
Block a user