From aaae1507cda8a0a80d384099f3ab776765d6b81a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 12 Apr 2018 11:51:50 -0400 Subject: [PATCH] [locale] Convenience function for TZ splitting --- src/modules/locale/GeoIP.cpp | 17 +++++++++++++++++ src/modules/locale/GeoIP.h | 5 ++++- src/modules/locale/GeoIPFreeGeoIP.cpp | 10 +--------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/modules/locale/GeoIP.cpp b/src/modules/locale/GeoIP.cpp index 5ada6e10c..1bed7d3f4 100644 --- a/src/modules/locale/GeoIP.cpp +++ b/src/modules/locale/GeoIP.cpp @@ -18,6 +18,23 @@ #include "GeoIP.h" +#include "utils/Logger.h" + GeoIP::~GeoIP() { } + +GeoIP::RegionZonePair +GeoIP::splitTZString( const QString& timezoneString ) +{ + QStringList tzParts = timezoneString.split( '/', QString::SkipEmptyParts ); + if ( tzParts.size() >= 2 ) + { + cDebug() << "GeoIP reporting" << timezoneString; + QString region = tzParts.takeFirst(); + QString zone = tzParts.join( '/' ); + return qMakePair( region, zone ); + } + + return qMakePair( QString(), QString() ); +} diff --git a/src/modules/locale/GeoIP.h b/src/modules/locale/GeoIP.h index f05c4d383..b3d84c118 100644 --- a/src/modules/locale/GeoIP.h +++ b/src/modules/locale/GeoIP.h @@ -36,6 +36,8 @@ struct GeoIP { using RegionZonePair = QPair; + virtual ~GeoIP(); + /** @brief Handle a (successful) request by interpreting the data. * * Should return a ( , ) pair, e.g. @@ -47,7 +49,8 @@ struct GeoIP */ virtual RegionZonePair processReply( QNetworkReply* ) = 0; - virtual ~GeoIP(); + /** @brief Splits a region/zone string into a pair. */ + static RegionZonePair splitTZString( const QString& s ); } ; #endif diff --git a/src/modules/locale/GeoIPFreeGeoIP.cpp b/src/modules/locale/GeoIPFreeGeoIP.cpp index 354e6c011..d7e724145 100644 --- a/src/modules/locale/GeoIPFreeGeoIP.cpp +++ b/src/modules/locale/GeoIPFreeGeoIP.cpp @@ -44,15 +44,7 @@ FreeGeoIP::processReply( QNetworkReply* reply ) if ( map.contains( "time_zone" ) && !map.value( "time_zone" ).toString().isEmpty() ) { - QString timezoneString = map.value( "time_zone" ).toString(); - QStringList tzParts = timezoneString.split( '/', QString::SkipEmptyParts ); - if ( tzParts.size() >= 2 ) - { - cDebug() << "GeoIP reporting" << timezoneString; - QString region = tzParts.takeFirst(); - QString zone = tzParts.join( '/' ); - return qMakePair( region, zone ); - } + return splitTZString( map.value( "time_zone" ).toString() ); } } }