PostGIS  3.3.9dev-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 580 of file lwgeom_in_gml.c.

581 {
582  char *p;
583  int st;
584  enum states
585  {
586  INIT = 0,
587  NEED_DIG = 1,
588  DIG = 2,
589  NEED_DIG_DEC = 3,
590  DIG_DEC = 4,
591  EXP = 5,
592  NEED_DIG_EXP = 6,
593  DIG_EXP = 7,
594  END = 8
595  };
596 
597  /*
598  * Double pattern
599  * [-|\+]?[0-9]+(\.)?([0-9]+)?([Ee](\+|-)?[0-9]+)?
600  * We could also meet spaces before and/or after
601  * this pattern upon parameters
602  */
603 
604  if (space_before) while (isspace(*d)) d++;
605  for (st = INIT, p = d ; *p ; p++)
606  {
607 
608  if (isdigit(*p))
609  {
610  if (st == INIT || st == NEED_DIG) st = DIG;
611  else if (st == NEED_DIG_DEC) st = DIG_DEC;
612  else if (st == NEED_DIG_EXP || st == EXP) st = DIG_EXP;
613  else if (st == DIG || st == DIG_DEC || st == DIG_EXP);
614  else gml_lwpgerror("invalid GML representation", 7);
615  }
616  else if (*p == '.')
617  {
618  if (st == DIG) st = NEED_DIG_DEC;
619  else gml_lwpgerror("invalid GML representation", 8);
620  }
621  else if (*p == '-' || *p == '+')
622  {
623  if (st == INIT) st = NEED_DIG;
624  else if (st == EXP) st = NEED_DIG_EXP;
625  else gml_lwpgerror("invalid GML representation", 9);
626  }
627  else if (*p == 'e' || *p == 'E')
628  {
629  if (st == DIG || st == DIG_DEC) st = EXP;
630  else gml_lwpgerror("invalid GML representation", 10);
631  }
632  else if (isspace(*p))
633  {
634  if (!space_after) gml_lwpgerror("invalid GML representation", 11);
635  if (st == DIG || st == DIG_DEC || st == DIG_EXP)st = END;
636  else if (st == NEED_DIG_DEC) st = END;
637  else if (st == END);
638  else gml_lwpgerror("invalid GML representation", 12);
639  }
640  else gml_lwpgerror("invalid GML representation", 13);
641  }
642 
643  if (st != DIG && st != NEED_DIG_DEC && st != DIG_DEC && st != DIG_EXP && st != END)
644  gml_lwpgerror("invalid GML representation", 14);
645 
646  return atof(d);
647 }
static void gml_lwpgerror(char *msg, __attribute__((__unused__)) int error_code)
Definition: lwgeom_in_gml.c:81

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: