PostGIS  3.1.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 585 of file lwgeom_in_gml.c.

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