[locale] Auto-clean up time zone data
- Some providers return weirdly escaped data; strip out useless escaping before splitting (there are no characters in correct time zone names that need escaping) - Add some tests for TZ splitting
This commit is contained in:
parent
fa5d40006c
commit
d04e243c4e
@ -30,8 +30,11 @@ GeoIP::~GeoIP()
|
||||
}
|
||||
|
||||
GeoIP::RegionZonePair
|
||||
GeoIP::splitTZString( const QString& timezoneString )
|
||||
GeoIP::splitTZString( const QString& tz )
|
||||
{
|
||||
QString timezoneString( tz );
|
||||
timezoneString.remove( '\\' );
|
||||
|
||||
QStringList tzParts = timezoneString.split( '/', QString::SkipEmptyParts );
|
||||
if ( tzParts.size() >= 2 )
|
||||
{
|
||||
|
@ -165,3 +165,27 @@ GeoIPTests::testXMLbad()
|
||||
QCOMPARE( tz.first, QString() );
|
||||
#endif
|
||||
}
|
||||
|
||||
void GeoIPTests::testSplitTZ()
|
||||
{
|
||||
auto tz = GeoIP::splitTZString( QLatin1String("Moon/Dark_side") );
|
||||
QCOMPARE( tz.first, QLatin1String("Moon") );
|
||||
QCOMPARE( tz.second, QLatin1String("Dark_side") );
|
||||
|
||||
// Some providers return weirdly escaped data
|
||||
tz = GeoIP::splitTZString( QLatin1String("America\\/NewYork") );
|
||||
QCOMPARE( tz.first, QLatin1String("America") );
|
||||
QCOMPARE( tz.second, QLatin1String("NewYork") ); // That's not actually the zone name
|
||||
|
||||
// Check that bogus data fails
|
||||
tz = GeoIP::splitTZString( QString() );
|
||||
QCOMPARE( tz.first, QString() );
|
||||
|
||||
tz = GeoIP::splitTZString( QLatin1String("America.NewYork") );
|
||||
QCOMPARE( tz.first, QString() );
|
||||
|
||||
// Check that three-level is split properly
|
||||
tz = GeoIP::splitTZString( QLatin1String("America/North Dakota/Beulah") );
|
||||
QCOMPARE( tz.first, QLatin1String("America") );
|
||||
QCOMPARE( tz.second, QLatin1String("North Dakota/Beulah") );
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ private Q_SLOTS:
|
||||
void testXML2();
|
||||
void testXMLalt();
|
||||
void testXMLbad();
|
||||
void testSplitTZ();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user