51double w32strtod(
const char *,
char **);
69double w32strtod(
const char *val,
char **ptr) {
71 string *sval =
new string(val);
72 string *snan =
new string(
"NaN");
76 if (stricmp(sval->c_str(), snan->c_str()) != 0)
77 return (strtod(val, ptr));
81 *ptr = (
char *)val + strlen(val);
82 return (std::numeric_limits<double>::quiet_NaN());
101 oss +=
"Error parsing the text on line ";
104 oss +=
"Parse error.";
108 oss += (string)
" at or near: " + context + (
string)
"\n" + msg + (string)
"\n";
110 oss += (string)
"\n" + msg + (
string)
"\n";
115void parse_error(
const char *msg,
const int line_num,
const char *context) {
124 oss +=
"Error parsing the text on line ";
127 oss +=
"Parse error.";
131 oss += (string)
" at or near: " + context + (
string)
"\n" + msg + (string)
"\n";
133 oss += (string)
"\n" + msg + (
string)
"\n";
140void parse_error(
const string &msg,
const int line_num,
const char *context) {
147void save_str(
char *dst,
const char *src,
const int line_num)
149 if (strlen(src) >=
ID_MAX)
151 +
string(
"' is too long (it should be no longer than ")
154 strncpy(dst, src,
ID_MAX);
159void save_str(
string &dst,
const char *src,
const int) { dst = src; }
164 DBG(cerr <<
"is_keyword: " << keyword <<
" = " <<
id << endl);
165 return id == keyword;
180 long v = strtol(val, &ptr, 0);
182 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
186 DBG(cerr <<
"v: " << v << endl);
204 long v = strtol(val, &ptr, 0);
206 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
219 unsigned long v = strtol(val, &ptr, 0);
221 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
235 long v = strtol(val, &ptr, 0);
237 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
244 if (errno == ERANGE) {
261 while (c && isspace(*c)) {
264 if (c && (*c ==
'-')) {
270 unsigned long v = strtoul(val, &ptr, 0);
272 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
279 if (errno == ERANGE) {
293 long tmp = strtol(val, &ptr, 0);
295 if ((tmp == 0 && val == ptr) || *ptr !=
'\0') {
302 if (errno == ERANGE) {
320 while (c && isspace(*c)) {
323 if (c && (*c ==
'-')) {
329 unsigned long tmp = strtoul(val, &ptr, 0);
331 if ((tmp == 0 && val == ptr) || *ptr !=
'\0') {
338 if (errno == ERANGE) {
345 v = (
unsigned int)tmp;
353 long long v = strtoll(val, &ptr, 0);
355 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
362 if (errno == ERANGE) {
384 while (c && isspace(*c)) {
387 if (c && (*c ==
'-')) {
393 unsigned long long v = strtoull(val, &ptr, 0);
395 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
399 if (errno == ERANGE) {
418 double v = w32strtod(val, &ptr);
420 double v = strtod(val, &ptr);
423 DBG(cerr <<
"v: " << v <<
", ptr: " << ptr <<
", errno: " << errno <<
", val==ptr: " << (val == ptr) << endl);
425 if (errno == ERANGE || (v == 0.0 && val == ptr) || *ptr !=
'\0')
429 if ((v == 0.0 && (val == ptr || errno == HUGE_VAL || errno == ERANGE))
435 DBG(cerr <<
"fabs(" << val <<
") = " << fabs(v) << endl);
436 double abs_val = fabs(v);
444 DBG(cerr <<
"val: " << val << endl);
449 double v = w32strtod(val, &ptr);
451 double v = strtod(val, &ptr);
454 DBG(cerr <<
"v: " << v <<
", ptr: " << ptr <<
", errno: " << errno <<
", val==ptr: " << (val == ptr) << endl);
456 if (errno == ERANGE || (v == 0.0 && val == ptr) || *ptr !=
'\0')
459 if ((v == 0.0 && (val == ptr || errno == HUGE_VAL || errno == ERANGE))
464 DBG(cerr <<
"fabs(" << val <<
") = " << fabs(v) << endl);
465 double abs_val = fabs(v);
473 DBG(cerr <<
"val: " << val << endl);
478 v = w32strtod(val, &ptr);
480 v = strtod(val, &ptr);
483 DBG(cerr <<
"v: " << v <<
", ptr: " << ptr <<
", errno: " << errno <<
", val==ptr: " << (val == ptr) << endl);
485 if (errno == ERANGE || (v == 0.0 && val == ptr) || *ptr !=
'\0')
488 if ((v == 0.0 && (val == ptr || errno == HUGE_VAL || errno == ERANGE))
493 DBG(cerr <<
"fabs(" << val <<
") = " << fabs(v) << endl);
494 double abs_val = fabs(v);
504 long long v = strtoll(val, &ptr, 0);
506 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
507 throw Error(
"Expected a 64-bit integer, but found other characters.");
514 if (errno == ERANGE) {
515 throw Error(
"The 64-bit integer value is out of range.");
526 throw Error(
"The value '" +
string(val) +
"' is out of range.");
539 while (c && isspace(*c)) {
542 if (c && (*c ==
'-')) {
543 throw Error(
"Expected a valid array index.");
548 unsigned long long v = strtoull(val, &ptr, 0);
550 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
551 throw Error(
"Expected an unsigned 64-bit integer, but found other characters.");
554 if (errno == ERANGE) {
555 throw Error(
"The 64-bit integer value is out of range.");
560 throw Error(
"The value '" +
string(val) +
"' is out of range.");
571 int v = strtol(val, &ptr, 0);
573 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
574 throw Error(
"Expected a 32-bit integer, but found other characters.");
580 if (errno == ERANGE) {
581 throw Error(
"The 32-bit integer value is out of range.");
599 while (c && isspace(*c)) {
602 if (c && (*c ==
'-')) {
603 throw Error(
"Expected an unsigned 32-bit integer, but found other characters.");
608 unsigned int v = strtoul(val, &ptr, 0);
610 if ((v == 0 && val == ptr) || *ptr !=
'\0') {
611 throw Error(
"Expected an unsigned 32-bit integer, but found other characters.");
614 if (errno == ERANGE) {
615 throw Error(
"The 32-bit integer value is out of range.");
626 DBG(cerr <<
"val: " << val << endl);
631 double v = w32strtod(val, &ptr);
633 double v = strtod(val, &ptr);
636 if (errno == ERANGE || (v == 0.0 && val == ptr) || *ptr !=
'\0')
637 throw Error(
"The 64-bit floating point value is out of range.");
640 DBG(cerr <<
"fabs(" << val <<
") = " << fabs(v) << endl);
641 double abs_val = fabs(v);
643 throw Error(
"The 64-bit floating point value is out of range.");
#define unknown_error
Unknown error (the default code) (HTTP 400)
#define malformed_expr
(400)
A class for error processing.
#define DODS_MAX_ARRAY_INDEX
int check_float64(const char *val)
int check_uint64(const char *val)
int check_url(const char *)
Is the value a valid URL?
int check_uint16(const char *val)
int check_int64(const char *val)
int check_byte(const char *val)
Is the value a valid byte?
int check_uint32(const char *val)
int check_int16(const char *val)
int check_float32(const char *val)
int check_int32(const char *val)
double get_float64(const char *val)
long long get_int64(const char *val)
unsigned int get_uint32(const char *val)
int get_int32(const char *val)
unsigned long long get_uint64(const char *val)
top level DAP object to house generic methods
string long_to_string(long val, int base)
string prune_spaces(const string &name)
void save_str(string &dst, const char *src, const int)
Save a string to a temporary variable during the parse.
void append_long_to_string(long val, int base, string &str_val)
void parse_error(parser_arg *arg, const char *msg, const int line_num, const char *context)
bool is_keyword(string id, const string &keyword)
Pass parameters by reference to a parser.
void set_error(Error *obj)
void set_status(int val=0)