[locale] Convenience function for TZ splitting

This commit is contained in:
Adriaan de Groot 2018-04-12 11:51:50 -04:00
parent 3636226425
commit aaae1507cd
3 changed files with 22 additions and 10 deletions

View File

@ -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() );
}

View File

@ -36,6 +36,8 @@ struct GeoIP
{
using RegionZonePair = QPair<QString, QString>;
virtual ~GeoIP();
/** @brief Handle a (successful) request by interpreting the data.
*
* Should return a ( <zone>, <region> ) 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

View File

@ -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() );
}
}
}