PostGIS  2.2.8dev-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 434 of file lwgeom_in_gml.c.

References gml_lwpgerror().

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

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