aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Knudsen <busstoptaktik@users.noreply.github.com>2017-11-28 20:57:02 +1300
committerGitHub <noreply@github.com>2017-11-28 20:57:02 +1300
commit3ca8752d7226b441df5c98a2e489f913a01b6273 (patch)
treeb7bf9a72f1cf4f14fd2f183ed32cfcf8d365e848 /src
parent97cff4b7a721a614a7e9603020701c05e2579525 (diff)
parente51a6c255822d0a1b1320a2f519610f8802a5e27 (diff)
downloadPROJ-3ca8752d7226b441df5c98a2e489f913a01b6273.tar.gz
PROJ-3ca8752d7226b441df5c98a2e489f913a01b6273.zip
Merge pull request #691 from busstoptaktik/make_assignments_greedy
Free formatting of PROJ key=value pairs
Diffstat (limited to 'src')
-rw-r--r--src/proj_4D_api.c44
1 files changed, 30 insertions, 14 deletions
diff --git a/src/proj_4D_api.c b/src/proj_4D_api.c
index 9a576997..5f4bf334 100644
--- a/src/proj_4D_api.c
+++ b/src/proj_4D_api.c
@@ -381,40 +381,60 @@ PJ *proj_create (PJ_CONTEXT *ctx, const char *definition) {
Create a new PJ object in the context ctx, using the given definition. If ctx==0,
the default context is used, if definition==0, or invalid, a null-pointer is
returned. The definition may use '+' as argument start indicator, as in
- "+proj=utm +zone=32", or leave it out, as in "proj=utm zone=32"
+ "+proj=utm +zone=32", or leave it out, as in "proj=utm zone=32".
+
+ It may even use free formatting "proj = utm; zone =32 ellps= GRS80".
+ Note that the semicolon separator is allowed, but not required.
**************************************************************************************/
PJ *P;
char *args, **argv;
- int argc, i, j, n;
+ int argc, i, j, last, n;
if (0==ctx)
ctx = pj_get_default_ctx ();
- /* make a copy that we can manipulate */
+ /* Make a copy that we can manipulate */
n = (int) strlen (definition);
args = (char *) malloc (n + 1);
if (0==args)
return 0;
strcpy (args, definition);
- /* all-in-one: count args, eliminate superfluous whitespace, 0-terminate substrings */
- for (i = j = argc = 0; i < n; ) {
- /* skip prefix whitespace */
+ /* All-in-one: count args, eliminate superfluous whitespace, 0-terminate substrings */
+ for (i = j = argc = last = 0; i < n; ) {
+
+ /* Skip prefix whitespace */
while (isspace (args[i]))
i++;
- /* skip at most one prefix '+' */
+ /* Skip at most one prefix '+' */
if ('+'==args[i])
i++;
- /* whitespace after a '+' is a syntax error - but by Postel's prescription, we ignore and go on */
+ /* Whitespace after a '+' is a syntax error - but by Postel's prescription, we ignore and go on */
if (isspace (args[i]))
continue;
- /* move a whitespace delimited text string to the left, skipping over superfluous whitespace */
- while ((0!=args[i]) && (!isspace (args[i])))
+ /* Move a whitespace delimited text string to the left, skipping over superfluous whitespace */
+ while ((0!=args[i]) && (!isspace (args[i])) && (';'!=args[i]))
args[j++] = args[i++];
+ /* Skip postfix whitespace */
+ while (isspace (args[i]) || ';'==args[i])
+ i++;
+
+ /* Greedy assignment operator: turn "a = b" into "a=b" */
+ if ('='==args[i]) {
+ args[j++] = '=';
+ i++;
+ while (isspace (args[i]))
+ i++;
+ while ((0!=args[i]) && (!isspace (args[i])) && (';'!=args[i]))
+ args[j++] = args[i++];
+ while (isspace (args[i]) || ';'==args[i])
+ i++;
+ }
+
/* terminate string - if that makes j pass i (often the case for first arg), let i catch up */
args[j++] = 0;
if (i < j)
@@ -422,10 +442,6 @@ PJ *proj_create (PJ_CONTEXT *ctx, const char *definition) {
/* we finished another arg */
argc++;
-
- /* skip postfix whitespace */
- while (isspace (args[i]))
- i++;
}
/* turn the massaged input into an array of strings */