PostGIS  2.5.0dev-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 449 of file lwgeom_in_gml.c.

References gml_lwpgerror().

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

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