Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changed interface of full territory name
  • Loading branch information
rijnb committed Oct 29, 2016
commit 2c526c4996234977af33bb01529fd9dfe164bcc9
16 changes: 13 additions & 3 deletions mapcodelib/mapcoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -2951,7 +2951,8 @@ enum Alphabet recognizeAlphabetUtf8(const char *utf8) {
static int getFullTerritoryName_internal(
char *territoryName,
enum Territory territory,
int alternative, int alphabet,
int alternative,
int alphabet,
const char *namelist[]) {

if (!territoryName || !namelist || alternative < 0 ||
Expand All @@ -2964,7 +2965,7 @@ static int getFullTerritoryName_internal(
pipePtr = strstr(s, "|");

#ifndef NO_SUPPORT_ALPHABETS
if (alphabet >= 0) {
if ((int) _ALPHABET_MIN < alphabet && alphabet < (int) _ALPHABET_MAX) {
if (pipePtr) {
lengthCopy(territoryName, s, (int) (pipePtr - s), MAX_TERRITORY_FULLNAME_LEN);
} else {
Expand Down Expand Up @@ -3006,8 +3007,17 @@ int getFullTerritoryNameEnglish(char *territoryName, enum Territory territory, i

#ifndef NO_SUPPORT_ALPHABETS

int getFullTerritoryNameLocal(char *territoryName, enum Territory territory, int alternative, enum Alphabet alphabet) {
int getFullTerritoryNameLocalInAlphabet(char *territoryName, enum Territory territory, int alternative,
enum Alphabet alphabet) {
if ((alphabet <= _ALPHABET_MIN) || (alphabet >= _ALPHABET_MAX)) {
territoryName[0] = 0;
return 0;
}
return getFullTerritoryName_internal(territoryName, territory, alternative, (int) alphabet, localname_utf8);
}

int getFullTerritoryNameLocal(char *territoryName, enum Territory territory, int alternative) {
return getFullTerritoryName_internal(territoryName, territory, alternative, -1, localname_utf8);
}

#endif // NO_SUPPORT_ALPHABETS
13 changes: 8 additions & 5 deletions mapcodelib/mapcoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ int multipleBordersNearby(
* Return value:
* non-0 if more alternatives are available (call again with alternative + 1).
* 0 if no more alternatives are available.
*/
*/

int getFullTerritoryNameEnglish(char *territoryName, enum Territory territory, int alternative);

Expand All @@ -357,19 +357,22 @@ int getFullTerritoryNameEnglish(char *territoryName, enum Territory territory, i
#ifndef NO_SUPPORT_ALPHABETS

/**
* Returns territory names in the local language.
* Returns territory names in the local language. There are two variants of this call. One returns local
* territory names in a specified alphabet only. The other simply returns the local names, regardless
* of its alphabet.
*
* Arguments:
* territoryName - Target string, allocated by caller to be at least MAX_TERRITORY_NAME_LENGTH + 1 bytes.
* territory - Territory to get name for.
* alternative - Which name to get, must be >= 0 (0 = default, 1 = first alternative, 2 = second etc.).
* alphabet - Alphabet to use for territoryName.
* alphabet - Alphabet to use for territoryName. Must be a valid alphabet value.
*
* Return value:
* non-0 if more alternatives are available (call again with alternative + 1).
* 0 if no more alternatives are available.
*/
int getFullTerritoryNameLocal(char *territoryName, enum Territory territory, int alternative, enum Alphabet alphabet);
*/
int getFullTerritoryNameLocalInAlphabet(char *territoryName, enum Territory territory, int alternative, enum Alphabet alphabet);
int getFullTerritoryNameLocal(char *territoryName, enum Territory territory, int alternative);


/**
Expand Down
24 changes: 22 additions & 2 deletions unittest/unittest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1492,15 +1492,31 @@ static int test_single_encodes(void) {
}


static int check_full_territory_name(const char* expectedName, const char* gotName, int expectedCode, int gotCode) {
int nrTests = 0;
++nrTests;
if (strcmp(expectedName, gotName)) {
found_error();
printf("*** ERROR *** getFullTerritoryName error, expected name '%s', but got '%s'\n", expectedName, gotName);
}
++nrTests;
if (expectedCode != gotCode) {
found_error();
printf("*** ERROR *** getFullTerritoryName error, expected return code %d, but got %d\n", expectedCode, gotCode);
}
return nrTests;
}


int territory_full_name_tests(void) {
int nrTests = 0;
enum Territory territory;
int minNames;
int nrNames = 0;
int maxLength = 0;
char territoryName[2048];
for (territory = _TERRITORY_MIN + 1; territory < _TERRITORY_MAX; ++territory) {
int alternative = 0;
char territoryName[2048];
nrTests++;
for (alternative = 0;; alternative++) {
int len;
Expand All @@ -1524,7 +1540,7 @@ int territory_full_name_tests(void) {
for (alternative = 0;; alternative++) {
int len;
++nrNames;
if (!getFullTerritoryNameLocal(territoryName, territory, alternative, _ALPHABET_MIN)) {
if (!getFullTerritoryNameLocal(territoryName, territory, alternative)) {
break;
}
len = (int) strlen(territoryName);
Expand All @@ -1551,6 +1567,10 @@ int territory_full_name_tests(void) {
found_error();
printf("*** ERROR *** Didn't find enough territory names, found %d, expected >= %d\n", nrNames, minNames);
}

++nrTests;
check_full_territory_name("Nederland", territoryName, getFullTerritoryNameLocal(territoryName, TERRITORY_NLD, 0), 0);
// TODO Add many more tests here.
return nrTests;
}

Expand Down