Skip to content

Commit a648a18

Browse files
committed
Added parseMapcodeString
1 parent 24ba835 commit a648a18

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

mapcodelib/mapcoder.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ static int decoderEngine(decodeRec *dec) {
15571557
dec->context = ccode;
15581558
dec->mapcode = dec->mapcodeFormat.properMapcode;
15591559
dec->extension = dec->mapcodeFormat.precisionExtension;
1560-
codex = dec->mapcodeFormat.indexOfDot * 9 + dec->mapcodeFormat.properMapcodeLength - 1;
1560+
codex = dec->mapcodeFormat.indexOfDot * 9 + (int) strlen(dec->mapcodeFormat.properMapcode) - 1;
15611561
s = dec->mapcodeFormat.properMapcode;
15621562

15631563
if (strchr(s, 'A') || strchr(s, 'E') || strchr(s, 'U')) {
@@ -2060,9 +2060,9 @@ int parseMapcodeString(MapcodeElements *mapcodeFormat, const char *asciiString,
20602060
}
20612061
// end of proper mapcode
20622062
if (mapcodeFormat) {
2063-
mapcodeFormat->properMapcodeLength = (int) (asciiString - mcStart);
2064-
memcpy(mapcodeFormat->properMapcode, mcStart, mapcodeFormat->properMapcodeLength);
2065-
mapcodeFormat->properMapcode[mapcodeFormat->properMapcodeLength] = 0;
2063+
int properMapcodeLength = (int) (asciiString - mcStart);
2064+
memcpy(mapcodeFormat->properMapcode, mcStart, properMapcodeLength);
2065+
mapcodeFormat->properMapcode[properMapcodeLength] = 0;
20662066
makeupper(mapcodeFormat->properMapcode);
20672067
}
20682068
} else if (newstate >= 64) { // end of territory
@@ -2089,7 +2089,7 @@ int parseMapcodeString(MapcodeElements *mapcodeFormat, const char *asciiString,
20892089
} else {
20902090
mapcodeFormat->territoryCode = territoryCode;
20912091
}
2092-
if (mapcodeFormat->territoryCode == (ccode_mex + 1) && (mapcodeFormat->properMapcodeLength < 8)) {
2092+
if (mapcodeFormat->territoryCode == (ccode_mex + 1) && (strlen(mapcodeFormat->properMapcode) < 8)) {
20932093
mapcodeFormat->territoryCode = getTerritoryCode("5MX", -1);
20942094
}
20952095
}

mapcodelib/mapcoder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ typedef struct {
5454
char territoryISO[MAX_ISOCODE_LEN + 1]; // The (trimmed and uppercased) candidate territory.
5555
int territoryCode; // The territory, as recognised and disambiguated, same as from getTerritoryCode().
5656
char properMapcode[MAX_PROPER_MAPCODE_LEN + 1]; // The (trimmed and uppercased) proper mapcode (excluding territory and precision extension).
57-
int properMapcodeLength; // Length of proper mapcode.
5857
int indexOfDot; // Position of dot in properMapcode (a value between 2 and 5).
5958
char precisionExtension[MAX_PRECISION_DIGITS + 1]; // The (trimmed and uppercased) precision extension including hyphen; empty if precision 0.
6059
} MapcodeElements;
@@ -180,7 +179,8 @@ int compareWithMapcodeFormat(
180179
int includesTerritory);
181180

182181
/**
183-
* Parses a string into its mapcode components (returns nonzero in case the string is not a valid mapcode).
182+
* Parses a string into its mapcode components, separating the territory, the 'proper' mapcode (without the
183+
* territory and the precision extension) and the precision extension.
184184
*
185185
* Arguments:
186186
* mapcodeFormat - If not NULL, filled with analysis of the 'check' string if it was a correct mapcode.

unittest/unittest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ static int test_mapcode_formats(void) {
399399
mapcodeFormat.properMapcode,
400400
*mapcodeFormat.precisionExtension ? "-" : "",
401401
mapcodeFormat.precisionExtension,
402-
(mapcodeFormat.indexOfDot * 9) + mapcodeFormat.properMapcodeLength - 1);
402+
(mapcodeFormat.indexOfDot * 9) + (int) strlen(mapcodeFormat.properMapcode) - 1);
403403
if (strcmp(str, testpairs[i + 1]) != 0) {
404404
found_error();
405405
printf("*** ERROR *** compareWithMapcodeFormat(\"%s\") succeeded with \"%s\"\n", testpairs[i], str);

0 commit comments

Comments
 (0)