PostGIS  2.1.10dev-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 439 of file lwgeom_in_gml.c.

References gml_lwerror().

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

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

Here is the call graph for this function:

Here is the caller graph for this function: