19#ifndef PROTOCORE_NUMPARSE_H
20#define PROTOCORE_NUMPARSE_H
24 return c ==
' ' || c ==
'\t' || c ==
'\n' || c ==
'\r' || c ==
'\f' || c ==
'\v';
28 return c >=
'0' && c <=
'9';
32inline long pc_strtol(
const char *s,
const char **end)
40 if (*p ==
'+' || *p ==
'-')
48 v = v * 10UL + (
unsigned long)(*p++ -
'0');
52 *end = (p == ds) ? s : p;
54 return neg ? (long)(0UL - v) : (long)v;
58inline unsigned long pc_strtoul(
const char *s,
const char **end)
73 v = v * 10UL + (
unsigned long)(*p++ -
'0');
77 *end = (p == ds) ? s : p;
90 val += (double)(*p++ -
'0') / scale;
100 if (*p ==
'+' || *p ==
'-')
102 eneg = (*p++ ==
'-');
107 ex = (ex < 400) ? ex * 10 + (*p -
'0') : ex;
111 for (
int k = 0; k < ex; k++)
115 val = eneg ? val / m : val * m;
127 if (*p ==
'+' || *p ==
'-')
135 val = val * 10.0 + (*p++ -
'0');
142 if (any && (*p ==
'e' || *p ==
'E'))
150 return neg ? -val : val;
void pc_strtod_exp(const char *&p, double &val)
unsigned long pc_strtoul(const char *s, const char **end)
Parse a base-10 unsigned long; sets end past the digits (or to s).
long pc_strtol(const char *s, const char **end)
Parse a base-10 long; sets end past the digits (or to s if none).
float pc_strtof(const char *s, const char **end)
Parse a float (integer[.frac][e[+/-]exp]); sets end (or to s if none).
double pc_strtod(const char *s, const char **end)
Parse a double (integer[.frac][e[+/-]exp]); sets end (or to s if none).
void pc_strtod_frac(const char *&p, double &val, bool &any)