PostGIS  3.4.0dev-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 501 of file lwgeom_in_gml.c.

502 {
503  char *p;
504  int st;
505  enum states
506  {
507  INIT = 0,
508  NEED_DIG = 1,
509  DIG = 2,
510  NEED_DIG_DEC = 3,
511  DIG_DEC = 4,
512  EXP = 5,
513  NEED_DIG_EXP = 6,
514  DIG_EXP = 7,
515  END = 8
516  };
517 
518  /*
519  * Double pattern
520  * [-|\+]?[0-9]+(\.)?([0-9]+)?([Ee](\+|-)?[0-9]+)?
521  * We could also meet spaces before and/or after
522  * this pattern upon parameters
523  */
524 
525  if (space_before) while (isspace(*d)) d++;
526  for (st = INIT, p = d ; *p ; p++)
527  {
528 
529  if (isdigit(*p))
530  {
531  if (st == INIT || st == NEED_DIG) st = DIG;
532  else if (st == NEED_DIG_DEC) st = DIG_DEC;
533  else if (st == NEED_DIG_EXP || st == EXP) st = DIG_EXP;
534  else if (st == DIG || st == DIG_DEC || st == DIG_EXP);
535  else gml_lwpgerror("invalid GML representation", 7);
536  }
537  else if (*p == '.')
538  {
539  if (st == DIG) st = NEED_DIG_DEC;
540  else gml_lwpgerror("invalid GML representation", 8);
541  }
542  else if (*p == '-' || *p == '+')
543  {
544  if (st == INIT) st = NEED_DIG;
545  else if (st == EXP) st = NEED_DIG_EXP;
546  else gml_lwpgerror("invalid GML representation", 9);
547  }
548  else if (*p == 'e' || *p == 'E')
549  {
550  if (st == DIG || st == DIG_DEC) st = EXP;
551  else gml_lwpgerror("invalid GML representation", 10);
552  }
553  else if (isspace(*p))
554  {
555  if (!space_after) gml_lwpgerror("invalid GML representation", 11);
556  if (st == DIG || st == DIG_DEC || st == DIG_EXP)st = END;
557  else if (st == NEED_DIG_DEC) st = END;
558  else if (st == END);
559  else gml_lwpgerror("invalid GML representation", 12);
560  }
561  else gml_lwpgerror("invalid GML representation", 13);
562  }
563 
564  if (st != DIG && st != NEED_DIG_DEC && st != DIG_DEC && st != DIG_EXP && st != END)
565  gml_lwpgerror("invalid GML representation", 14);
566 
567  return atof(d);
568 }
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: