PostGIS  3.0.6dev-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 533 of file lwgeom_in_gml.c.

534 {
535  char *p;
536  int st;
537  enum states
538  {
539  INIT = 0,
540  NEED_DIG = 1,
541  DIG = 2,
542  NEED_DIG_DEC = 3,
543  DIG_DEC = 4,
544  EXP = 5,
545  NEED_DIG_EXP = 6,
546  DIG_EXP = 7,
547  END = 8
548  };
549 
550  /*
551  * Double pattern
552  * [-|\+]?[0-9]+(\.)?([0-9]+)?([Ee](\+|-)?[0-9]+)?
553  * We could also meet spaces before and/or after
554  * this pattern upon parameters
555  */
556 
557  if (space_before) while (isspace(*d)) d++;
558  for (st = INIT, p = d ; *p ; p++)
559  {
560 
561  if (isdigit(*p))
562  {
563  if (st == INIT || st == NEED_DIG) st = DIG;
564  else if (st == NEED_DIG_DEC) st = DIG_DEC;
565  else if (st == NEED_DIG_EXP || st == EXP) st = DIG_EXP;
566  else if (st == DIG || st == DIG_DEC || st == DIG_EXP);
567  else gml_lwpgerror("invalid GML representation", 7);
568  }
569  else if (*p == '.')
570  {
571  if (st == DIG) st = NEED_DIG_DEC;
572  else gml_lwpgerror("invalid GML representation", 8);
573  }
574  else if (*p == '-' || *p == '+')
575  {
576  if (st == INIT) st = NEED_DIG;
577  else if (st == EXP) st = NEED_DIG_EXP;
578  else gml_lwpgerror("invalid GML representation", 9);
579  }
580  else if (*p == 'e' || *p == 'E')
581  {
582  if (st == DIG || st == DIG_DEC) st = EXP;
583  else gml_lwpgerror("invalid GML representation", 10);
584  }
585  else if (isspace(*p))
586  {
587  if (!space_after) gml_lwpgerror("invalid GML representation", 11);
588  if (st == DIG || st == DIG_DEC || st == DIG_EXP)st = END;
589  else if (st == NEED_DIG_DEC) st = END;
590  else if (st == END);
591  else gml_lwpgerror("invalid GML representation", 12);
592  }
593  else gml_lwpgerror("invalid GML representation", 13);
594  }
595 
596  if (st != DIG && st != NEED_DIG_DEC && st != DIG_DEC && st != DIG_EXP && st != END)
597  gml_lwpgerror("invalid GML representation", 14);
598 
599  return atof(d);
600 }
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: