PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ parse_gml_double()

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 455 of file lwgeom_in_gml.c.

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

References gml_lwpgerror().

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

Here is the call graph for this function:
Here is the caller graph for this function: