PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ is_literal_valid()

static int is_literal_valid ( const char *  literal)
static

Shortest allowed literal: containing cardinal direction > cardinal direction + degree with 3 digits no cardinal direction > degree with 3 digits

The variable "coord_start" stores the position where the coordinates start (0 or 1), so that the script can identify where each literal element begins to validate its content.

The first three characters represent the degrees and they must be numeric.

Decimal degrees are encoded with after the 3rd character with either a dot or a comma. Only one decimal separator is allowed.

Definition at line 94 of file lwgeom_in_marc21.c.

94  {
95 
96  int num_dec_sep;
97  int coord_start;
98  int literal_length;
99 
100  if(literal == NULL) return LW_FALSE;
101 
102  literal_length = strlen(literal);
103 
104  POSTGIS_DEBUGF(2, "is_literal_valid called (%s)", literal);
105 
106  if (literal_length < 3) return LW_FALSE;
107 
108  coord_start = 0;
109  num_dec_sep = 0;
110 
120  if (literal[0] == 'N' || literal[0] == 'E' || literal[0] == 'S' || literal[0] == 'W' || literal[0] == '+' || literal[0] == '-') {
121 
122  if (literal_length < 4) {
123  POSTGIS_DEBUGF(3, " invalid literal length (%d): \"%s\"", literal_length, literal);
124  return LW_FALSE;
125  }
126 
127  coord_start = 1;
128  }
129 
130  for (int j = coord_start; j < literal_length; j++) {
131 
132  if (!isdigit(literal[j])) {
133 
134 
135  if (j < 3) {
136 
141  POSTGIS_DEBUGF(3," invalid character '%c' at the degrees section: \"%s\"", literal[j], literal);
142  return LW_FALSE;
143 
144  }
145 
150  if (literal[j] == '.' || literal[j] == ',') {
151 
152  num_dec_sep++;
153 
154  if (num_dec_sep > 1) return LW_FALSE;
155 
156  } else {
157  POSTGIS_DEBUGF(3, " invalid character '%c' in %d: \"%s\"", literal[j], j, literal);
158  return LW_FALSE;
159 
160  }
161 
162  }
163 
164  }
165 
166  POSTGIS_DEBUGF(2, "=> is_literal_valid returns LW_TRUE for \"%s\"", literal);
167  return LW_TRUE;
168 
169 }
#define LW_FALSE
Definition: liblwgeom.h:94
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93

References LW_FALSE, and LW_TRUE.

Referenced by parse_marc21().

Here is the caller graph for this function: