[mapcode] 04/06: Stricter conversion to other alphabets
Stefan Fritsch
sf at moszumanska.debian.org
Wed Nov 2 23:28:06 UTC 2016
This is an automated email from the git hooks/post-receive script.
sf pushed a commit to tag v2.1.1
in repository mapcode.
commit b8c755205e1a2d238472cfed54a77c84a186df90
Author: Mapcode C Developer <pieter.geelen at mapcode.com>
Date: Sun Aug 23 21:19:49 2015 +0200
Stricter conversion to other alphabets
---
mapcodelib/mapcoder.c | 64 +++++++++++++++++++++++++++++++--------------------
1 file changed, 39 insertions(+), 25 deletions(-)
diff --git a/mapcodelib/mapcoder.c b/mapcodelib/mapcoder.c
index e5ebbe3..54d8799 100644
--- a/mapcodelib/mapcoder.c
+++ b/mapcodelib/mapcoder.c
@@ -2134,35 +2134,49 @@ int decodeMapcodeToLatLon(double *lat, double *lon, const char *input,
UWORD *convertToAlphabet(UWORD *unibuf, int maxlength, const char *mapcode, int alphabet) // 0=roman, 2=cyrillic
{
UWORD *startbuf = unibuf;
+ UWORD *lastspot = &unibuf[maxlength - 1];
+ if (maxlength>0) {
+ char u[MAX_MAPCODE_RESULT_LEN];
+
+ // skip leading spaces
+ while (*mapcode > 0 && *mapcode <= 32) { mapcode++; }
+
+ // straight-copy everything up to and including first space
+ {
+ char *e = strchr(mapcode, ' ');
+ if (e) {
+ while (mapcode <= e) {
+ if (unibuf == lastspot) { // buffer fully filled?
+ // zero-terminate and return
+ *unibuf = 0;
+ return startbuf;
+ }
+ *unibuf++ = *mapcode++;
+ }
+ }
+ }
- while (*mapcode > 0 && *mapcode < 32) { mapcode++; }
- { // skip lead
- char *e = strrchr(mapcode, ' ');
- if (e) {
- while (mapcode <= e) {
- *unibuf++ = *mapcode++;
- }
- }
- }
-
- if (asc2lan[alphabet][4] == 0x003f) { // alphabet has no letter E
- if (strchr(mapcode, 'E') || strchr(mapcode, 'U') || strchr(mapcode, 'e') ||
- strchr(mapcode, 'u')) // v1.50 get rid of E and U
- {
- // safely copy mapcode into temporary buffer u
- char u[MAX_MAPCODE_RESULT_LEN];
- int len = (int) strlen(mapcode);
- if (len >= MAX_MAPCODE_RESULT_LEN) {
- len = MAX_MAPCODE_RESULT_LEN - 1;
+ // re-pack E/U-voweled mapcodes when necessary:
+ if (asc2lan[alphabet][4] == 0x003f) { // alphabet has no letter E
+ if (strchr(mapcode, 'E') || strchr(mapcode, 'U') ||
+ strchr(mapcode, 'e') || strchr(mapcode, 'u'))
+ {
+ // copy trimmed mapcode into temporary buffer u
+ int len = (int) strlen(mapcode);
+ if (len > MAX_MAPCODE_RESULT_LEN - 1) {
+ len = MAX_MAPCODE_RESULT_LEN - 1;
+ }
+ while (len>0 && mapcode[len-1]>0 && mapcode[len-1]<=32) { len--; }
+ memcpy(u, mapcode, len);
+ u[len] = 0;
+ // re-pack into A-voweled mapcode
+ unpack_if_alldigits(u);
+ repack_if_alldigits(u, 1);
+ mapcode = u;
}
- memcpy(u, mapcode, len);
- u[len] = 0;
- unpack_if_alldigits(u);
- repack_if_alldigits(u, 1);
- mapcode = u;
}
+ encode_utf16(unibuf, 1 + (int)(lastspot - unibuf), mapcode, alphabet);
}
- encode_utf16(unibuf, maxlength, mapcode, alphabet);
return startbuf;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/mapcode.git
More information about the Pkg-grass-devel
mailing list