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

◆ 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 115 of file lwgeom_in_marc21.c.

115 {
116
117 int num_dec_sep;
118 int coord_start;
119 int literal_length;
120
121 if(literal == NULL) return LW_FALSE;
122
123 literal_length = strlen(literal);
124
125 POSTGIS_DEBUGF(2, "is_literal_valid called (%s)", literal);
126
127 if (literal_length < 3) return LW_FALSE;
128
129 coord_start = 0;
130 num_dec_sep = 0;
131
141 if (literal[0] == 'N' || literal[0] == 'E' || literal[0] == 'S' || literal[0] == 'W' || literal[0] == '+' || literal[0] == '-') {
142
143 if (literal_length < 4) {
144 POSTGIS_DEBUGF(3, " invalid literal length (%d): \"%s\"", literal_length, literal);
145 return LW_FALSE;
146 }
147
148 coord_start = 1;
149 }
150
151 for (int j = coord_start; j < literal_length; j++) {
152
153 if (!isdigit(literal[j])) {
154
155
156 if (j < 3) {
157
162 POSTGIS_DEBUGF(3," invalid character '%c' at the degrees section: \"%s\"", literal[j], literal);
163 return LW_FALSE;
164
165 }
166
171 if (literal[j] == '.' || literal[j] == ',') {
172
173 num_dec_sep++;
174
175 if (num_dec_sep > 1) return LW_FALSE;
176
177 } else {
178 POSTGIS_DEBUGF(3, " invalid character '%c' in %d: \"%s\"", literal[j], j, literal);
179 return LW_FALSE;
180
181 }
182
183 }
184
185 }
186
187 POSTGIS_DEBUGF(2, "=> is_literal_valid returns LW_TRUE for \"%s\"", literal);
188 return LW_TRUE;
189
190}
#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: