PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 537 of file lwgeom_in_gml.c.

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

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: