Skip to content

Commit 234ca99

Browse files
committed
Improve string breaking
1 parent fee9b12 commit 234ca99

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/gmt_gdalcall.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ GMT_LOCAL GDALDatasetH gdal_vector (struct GMT_CTRL *GMT, char *fname) {
108108

109109
/* ------------------------------------------------------------------------------------------------------------ */
110110
GMT_LOCAL char ** breakMe(struct GMT_CTRL *GMT, char *in) {
111-
/* Breake a string "-aa -bb -cc dd" into tokens "-aa" "-bb" "-cc" "dd" */
111+
/* Break a string "-mo TIFFTAG_XRESOLUTION=300 -a_srs '+proj=stere +lat_0=90'" into tokens */
112112
/* Based on GMT_Create_Options() */
113113
unsigned int pos = 0, k, n_args = 0;
114114
bool quoted;
@@ -122,11 +122,11 @@ GMT_LOCAL char ** breakMe(struct GMT_CTRL *GMT, char *in) {
122122
txt_in = strdup (in);
123123
args = gmt_M_memory (GMT, NULL, n_alloc, char *);
124124

125-
/* txt_in can contain options that take multi-word text strings, e.g., -B+t"My title". We avoid the problem of splitting
126-
* these items by temporarily replacing spaces inside quoted strings with ASCII 31 US (Unit Separator), do the strtok on
125+
/* txt_in can contain options that take multi-word text strings, e.g., '+proj=stere +lat_0=90'. We avoid the problem of splitting
126+
* these items by temporarily replacing spaces inside single quoted strings with ASCII 31 US (Unit Separator), do the strtok on
127127
* space, and then replace all ASCII 31 with space at the end (we do the same for tab using ASCII 29 GS (group separator) */
128128
for (k = 0, quoted = false; txt_in[k]; k++) {
129-
if (txt_in[k] == '\"') quoted = !quoted; /* Initially false, becomes true at start of quote, then false when exit quote */
129+
if (txt_in[k] == '\'') quoted = !quoted; /* Initially false, becomes true at start of quote, then false when exit quote */
130130
else if (quoted && txt_in[k] == '\t') txt_in[k] = GMT_ASCII_GS;
131131
else if (quoted && txt_in[k] == ' ') txt_in[k] = GMT_ASCII_US;
132132
}
@@ -139,7 +139,7 @@ GMT_LOCAL char ** breakMe(struct GMT_CTRL *GMT, char *in) {
139139
p[k] = ' '; /* Replace spaces and tabs masked above */
140140
}
141141
for (i = o = 0; p[i]; i++)
142-
if (p[i] != '\"') p[o++] = p[i]; /* Ignore double quotes */
142+
if (p[i] != '\"') p[o++] = p[i]; /* Ignore any double quotes */
143143
p[o] = '\0';
144144
args[n_args++] = strdup(p);
145145

@@ -148,7 +148,7 @@ GMT_LOCAL char ** breakMe(struct GMT_CTRL *GMT, char *in) {
148148
args = gmt_M_memory(GMT, args, n_alloc, char *);
149149
}
150150
}
151-
for (k = 0; txt_in[k]; k++) /* Restore input string to prestine condition */
151+
for (k = 0; txt_in[k]; k++) /* Restore input string to pristine condition */
152152
if (txt_in[k] == GMT_ASCII_GS) txt_in[k] = '\t';
153153
else if (txt_in[k] == GMT_ASCII_US) txt_in[k] = ' '; /* Replace spaces and tabs masked above */
154154

0 commit comments

Comments
 (0)