diff options
| author | Thomas Knudsen <busstoptaktik@users.noreply.github.com> | 2017-11-28 20:57:02 +1300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-28 20:57:02 +1300 |
| commit | 3ca8752d7226b441df5c98a2e489f913a01b6273 (patch) | |
| tree | b7bf9a72f1cf4f14fd2f183ed32cfcf8d365e848 | |
| parent | 97cff4b7a721a614a7e9603020701c05e2579525 (diff) | |
| parent | e51a6c255822d0a1b1320a2f519610f8802a5e27 (diff) | |
| download | PROJ-3ca8752d7226b441df5c98a2e489f913a01b6273.tar.gz PROJ-3ca8752d7226b441df5c98a2e489f913a01b6273.zip | |
Merge pull request #691 from busstoptaktik/make_assignments_greedy
Free formatting of PROJ key=value pairs
| -rw-r--r-- | src/proj_4D_api.c | 44 | ||||
| -rw-r--r-- | test/gie/GDA.gie | 15 |
2 files changed, 38 insertions, 21 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 */ diff --git a/test/gie/GDA.gie b/test/gie/GDA.gie index 7ccf6b58..3fe0f3e3 100644 --- a/test/gie/GDA.gie +++ b/test/gie/GDA.gie @@ -18,7 +18,7 @@ directly - I believe it should come from official AU sources. Thomas Knudsen, thokn@sdfe.dk, 2017-11-27 ----------------------------------------------------------------------------------- -BEGIN +<gie> ----------------------------------------------------------------------------------- GDA94 to GDA2020 ----------------------------------------------------------------------------------- @@ -52,11 +52,12 @@ ITRF2014@2018 to GDA2020 ----------------------------------------------------------------------------------- Just the Helmert transformation, to verify that we are within 100 um ----------------------------------------------------------------------------------- -operation proj=helmert x=0 y=0 z=0 s=0 rx=0 ry=0 rz=0 \ - dx=0 dy=0 dz=0 \ - drx=0.00150379 dry=0.00118346 drz=0.00120716 \ - ds=0 \ - epoch=2020.0 +operation proj = helmert; \ + x = 0; rx = 0; dx = 0; drx = 0.00150379; \ + y = 0; ry = 0; dy = 0; dry = 0.00118346; \ + z = 0; rz = 0; dz = 0; drz = 0.00120716; \ + \ + ds = 0; epoch=2020.0; ----------------------------------------------------------------------------------- tolerance 50 um @@ -66,4 +67,4 @@ accept -4052052.6588 4212835.9938 -2545104.6946 2018.0 # Alice Springs GDA2020 expect -4052052.7373 4212835.9835 -2545104.5867 -END +</gie> |
