39 {
"$Id: parser-util.cc 22703 2010-05-11 18:10:01Z jimg $" 55 double w32strtod(
const char *,
char **);
72 double w32strtod(
const char *val,
char **ptr)
75 string *sval =
new string(val);
76 string *snan =
new string(
"NaN");
80 if (stricmp(sval->c_str(), snan->c_str()) != 0)
81 return (strtod(val, ptr));
85 *ptr = (
char *) val + strlen(val);
86 return (std::numeric_limits < double >::quiet_NaN());
108 oss +=
"Error parsing the text on line ";
112 oss +=
"Parse error.";
116 oss += (string)
" at or near: " + context + (
string)
"\n" + msg
119 oss += (string)
"\n" + msg + (
string)
"\n";
125 parse_error(
const char *msg,
const int line_num,
const char *context)
135 oss +=
"Error parsing the text on line ";
139 oss +=
"Parse error.";
143 oss += (string)
" at or near: " + context + (
string)
"\n" + msg
146 oss += (string)
"\n" + msg + (
string)
"\n";
154 parse_error(
const string & msg,
const int line_num,
const char *context)
159 void save_str(
char *dst,
const char *src,
const int line_num)
161 if (strlen(src) >=
ID_MAX)
163 +
string(
"' is too long (it should be no longer than ")
166 strncpy(dst, src,
ID_MAX);
170 void save_str(
string & dst,
const char *src,
const int)
179 DBG(cerr <<
"is_keyword: " << keyword <<
" = " <<
id << endl);
180 return id == keyword;
186 long v = strtol(val, &ptr, 0);
188 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
192 DBG(cerr <<
"v: " << v << endl);
212 long v = strtol(val, &ptr, 0);
214 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
228 unsigned long v = strtol(val, &ptr, 0);
230 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
245 long v = strtol(val, &ptr, 0);
248 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
255 if (errno == ERANGE) {
274 while (c && isspace(*c)) {
277 if (c && (*c ==
'-')) {
283 unsigned long v = strtoul(val, &ptr, 0);
285 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
292 if (errno == ERANGE) {
315 double v = w32strtod(val, &ptr);
317 double v = strtod(val, &ptr);
320 DBG(cerr <<
"v: " << v <<
", ptr: " << ptr
321 <<
", errno: " << errno <<
", val==ptr: " << (val == ptr) << endl);
323 if (errno == ERANGE || (v == 0.0 && val == ptr) || *ptr !=
'\0')
326 if ((v == 0.0 && (val == ptr || errno == HUGE_VAL || errno == ERANGE))
332 DBG(cerr <<
"fabs(" << val <<
") = " << fabs(v) << endl);
333 double abs_val = fabs(v);
343 DBG(cerr <<
"val: " << val << endl);
348 double v = w32strtod(val, &ptr);
350 double v = strtod(val, &ptr);
353 DBG(cerr <<
"v: " << v <<
", ptr: " << ptr
354 <<
", errno: " << errno <<
", val==ptr: " << (val == ptr) << endl);
357 if (errno == ERANGE || (v == 0.0 && val == ptr) || *ptr !=
'\0')
360 if ((v == 0.0 && (val == ptr || errno == HUGE_VAL || errno == ERANGE))
365 DBG(cerr <<
"fabs(" << val <<
") = " << fabs(v) << endl);
366 double abs_val = fabs(v);
int check_float64(const char *val)
int check_int32(const char *val)
int check_int16(const char *val)
Is the value a valid integer?
string prune_spaces(const string &name)
#define unknown_error
Unknown error.
void set_status(int val=0)
int check_byte(const char *val)
Is the value a valid byte?
void append_long_to_string(long val, int base, string &str_val)
void set_error(Error *obj)
string long_to_string(long val, int base)
int check_url(const char *)
Is the value a valid URL?
void parse_error(parser_arg *arg, const char *msg, const int line_num, const char *context)
Pass parameters by reference to a parser.
bool is_keyword(string id, const string &keyword)
int check_uint32(const char *val)
A class for error processing.
int check_uint16(const char *val)
void save_str(char *dst, const char *src, const int line_num)
Save a string to a temporary variable during the parse.
int check_float32(const char *val)
Is the value a valid float?