diff --git a/autotests/addresstest.h b/autotests/addresstest.h --- a/autotests/addresstest.h +++ b/autotests/addresstest.h @@ -42,6 +42,7 @@ void shouldParseAddressVCard4(); void shouldExportVCard4WithGeoPosition(); void shouldParseAddressVCard4WithGeoPosition(); + void countryToISOTest(); }; #endif diff --git a/autotests/addresstest.cpp b/autotests/addresstest.cpp --- a/autotests/addresstest.cpp +++ b/autotests/addresstest.cpp @@ -426,3 +426,13 @@ "END:VCARD\r\n\r\n"); QCOMPARE(ba, expected); } + +void AddressTest::countryToISOTest() +{ + using namespace KContacts; + QCOMPARE(Address::countryToISO(QStringLiteral("France")), QLatin1String("fr")); + QCOMPARE(Address::countryToISO(QStringLiteral("Frankreich")), QLatin1String("fr")); + QCOMPARE(Address::countryToISO(QStringLiteral("Germany")), QLatin1String("de")); + QCOMPARE(Address::countryToISO(QStringLiteral("Österreich")), QLatin1String("at")); + QCOMPARE(Address::countryToISO(QStringLiteral("Disneyland")), QString()); +} diff --git a/src/address.h b/src/address.h --- a/src/address.h +++ b/src/address.h @@ -303,10 +303,10 @@ /** Returns ISO code for a localized country name. Only localized country - names will be understood. This might be replaced by a KLocale method in - the future. + names will be understood. @param cname name of the country - @return two digit ISO code + @return two digit ISO code, empty string if the country was not + recognized */ static QString countryToISO(const QString &cname); diff --git a/src/address.cpp b/src/address.cpp --- a/src/address.cpp +++ b/src/address.cpp @@ -672,10 +672,7 @@ file.close(); } - // fall back to system country - QString systemCountry = QLocale().bcp47Name(); - sISOMap->insert(cname, systemCountry); - return systemCountry; + return {}; } QString Address::ISOtoCountry(const QString &ISOname)