MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / gmt_get_modifier

Function gmt_get_modifier

src/gmt_common_string.c:268–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266}
267
268unsigned int gmt_get_modifier (const char *string, char modifier, char *token) {
269 /* Looks for modifier string in the form +<modifier>[arg] and if found
270 returns 1 and places arg in token, else return 0. Must ignore any
271 +<modifier> found inside quotes as part of text. If token is NULL
272 then we only return 1 or 0 and no string.
273 */
274 bool quoted = false;
275 size_t k, len, start = 0;
276
277 if (!string || string[0] == 0) return 0; /* No hope */
278 len = strlen (string);
279 for (k = 0; start == 0 && k < (len-1); k++) {
280 if (string[k] == '\"' || string[k] == '\'') quoted = !quoted; /* Initially false, becomes true at start of quote, then false when exit quote */
281 if (quoted) continue; /* Not look inside quoted strings */
282 if (string[k] == '+' && string[k+1] == modifier) /* Found the start */
283 start = k+2;
284 }
285 if (start == 0) return 0; /* Not found */
286 for (k = start; k < len; k++) {
287 if (string[k] == '\"' || string[k] == '\'') quoted = !quoted; /* Initially false, becomes true at start of quote, then false when exit quote */
288 if (quoted) continue; /* Not look inside quoted strings */
289 if (string[k] == '+') /* Found the end */
290 break;
291 }
292 len = k - start;
293 if (token) { /* Only pass back when token is not NULL */
294 if (len) strncpy (token, &string[start], len);
295 token[len] = '\0';
296 }
297 return 1;
298}
299
300#ifdef WIN32
301/* Turn '/c/dir/...' paths into 'c:/dir/...'

Callers 15

parseFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85
gmt_getinsetFunction · 0.85
gmt_getscaleFunction · 0.85
gmt_getroseFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85
movie_get_item_defaultFunction · 0.85
movie_get_item_two_pensFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected