From b4e4b691fdf2e9217de397f2d9edbc513985daa9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 17 Apr 2018 07:32:27 -0400 Subject: [PATCH] [locale] Accomodate more dodgy GeoIP providers - Force spaces to _ - Document the bits FIXES #933 --- src/modules/locale/GeoIP.cpp | 1 + src/modules/locale/GeoIP.h | 10 +++++++++- src/modules/locale/locale.conf | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/modules/locale/GeoIP.cpp b/src/modules/locale/GeoIP.cpp index 3001273bb..4c031f286 100644 --- a/src/modules/locale/GeoIP.cpp +++ b/src/modules/locale/GeoIP.cpp @@ -34,6 +34,7 @@ GeoIP::splitTZString( const QString& tz ) { QString timezoneString( tz ); timezoneString.remove( '\\' ); + timezoneString.replace( ' ', '_' ); QStringList tzParts = timezoneString.split( '/', QString::SkipEmptyParts ); if ( tzParts.size() >= 2 ) diff --git a/src/modules/locale/GeoIP.h b/src/modules/locale/GeoIP.h index 6088c8a45..41abd2042 100644 --- a/src/modules/locale/GeoIP.h +++ b/src/modules/locale/GeoIP.h @@ -50,7 +50,15 @@ public: */ virtual RegionZonePair processReply( const QByteArray& ) = 0; - /** @brief Splits a region/zone string into a pair. */ + /** @brief Splits a region/zone string into a pair. + * + * Cleans up the string by removing backslashes (\\) + * since some providers return silly-escaped names. Replaces + * spaces with _ since some providers return human-readable names. + * Splits on the first / in the resulting string, or returns a + * pair of empty QStrings if it can't. (e.g. America/North Dakota/Beulah + * will return "America", "North_Dakota/Beulah"). + */ static RegionZonePair splitTZString( const QString& s ); protected: diff --git a/src/modules/locale/locale.conf b/src/modules/locale/locale.conf index 262345c7e..ddd0bc97e 100644 --- a/src/modules/locale/locale.conf +++ b/src/modules/locale/locale.conf @@ -53,6 +53,11 @@ zone: "New_York" # Europe/Brussels # ``` # +# To accomodate providers of GeoIP timezone data with peculiar timezone +# naming conventions, the following cleanups are performed automatically: +# - backslashes are removed +# - spaces are replaced with _ +# #geoipUrl: "freegeoip.net" # GeoIP style. Leave commented out for the "legacy" interpretation.