PostGIS  2.3.7dev-r@@SVN_REVISION@@
static double parse_gml_double ( char *  d,
bool  space_before,
bool  space_after 
)
static

Parse a string supposed to be a double.

Definition at line 448 of file lwgeom_in_gml.c.

References gml_lwpgerror().

Referenced by parse_gml_coord(), parse_gml_coordinates(), parse_gml_pos(), and parse_gml_poslist().

449 {
450  char *p;
451  int st;
452  enum states
453  {
454  INIT = 0,
455  NEED_DIG = 1,
456  DIG = 2,
457  NEED_DIG_DEC = 3,
458  DIG_DEC = 4,
459  EXP = 5,
460  NEED_DIG_EXP = 6,
461  DIG_EXP = 7,
462  END = 8
463  };
464 
465  /*
466  * Double pattern
467  * [-|\+]?[0-9]+(\.)?([0-9]+)?([Ee](\+|-)?[0-9]+)?
468  * We could also meet spaces before and/or after
469  * this pattern upon parameters
470  */
471 
472  if (space_before) while (isspace(*d)) d++;
473  for (st = INIT, p = d ; *p ; p++)
474  {
475 
476  if (isdigit(*p))
477  {
478  if (st == INIT || st == NEED_DIG) st = DIG;
479  else if (st == NEED_DIG_DEC) st = DIG_DEC;
480  else if (st == NEED_DIG_EXP || st == EXP) st = DIG_EXP;
481  else if (st == DIG || st == DIG_DEC || st == DIG_EXP);
482  else gml_lwpgerror("invalid GML representation", 7);
483  }
484  else if (*p == '.')
485  {
486  if (st == DIG) st = NEED_DIG_DEC;
487  else gml_lwpgerror("invalid GML representation", 8);
488  }
489  else if (*p == '-' || *p == '+')
490  {
491  if (st == INIT) st = NEED_DIG;
492  else if (st == EXP) st = NEED_DIG_EXP;
493  else gml_lwpgerror("invalid GML representation", 9);
494  }
495  else if (*p == 'e' || *p == 'E')
496  {
497  if (st == DIG || st == DIG_DEC) st = EXP;
498  else gml_lwpgerror("invalid GML representation", 10);
499  }
500  else if (isspace(*p))
501  {
502  if (!space_after) gml_lwpgerror("invalid GML representation", 11);
503  if (st == DIG || st == DIG_DEC || st == DIG_EXP)st = END;
504  else if (st == NEED_DIG_DEC) st = END;
505  else if (st == END);
506  else gml_lwpgerror("invalid GML representation", 12);
507  }
508  else gml_lwpgerror("invalid GML representation", 13);
509  }
510 
511  if (st != DIG && st != NEED_DIG_DEC && st != DIG_DEC && st != DIG_EXP && st != END)
512  gml_lwpgerror("invalid GML representation", 14);
513 
514  return atof(d);
515 }
static void gml_lwpgerror(char *msg, int error_code)
Definition: lwgeom_in_gml.c:81

Here is the call graph for this function:

Here is the caller graph for this function: