Gps coordinates: be more graceful when parsing coordinates

Some Wikipedia pages use special (non-ASCII) unicode symbols for
representing the " and ' separators. Before parsing, replace these
by the ASCII symbols to enable copy & paste from Wikipedia (and
other sources?).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-02-04 10:37:00 +01:00 committed by Dirk Hohndel
parent 96a03b4b26
commit cf1e3524a1

View file

@ -237,10 +237,16 @@ bool parseGpsText(const QString &gps_text, double *latitude, double *longitude)
static const QString POS_LON = QString("+E") + gettextFromC::tr("E");
static const QString NEG_LON = QString("-W") + gettextFromC::tr("W");
//remove the useless spaces (but keep the ones separating numbers)
// Remove the useless spaces (but keep the ones separating numbers)
// and normalize different ways of writing separators.
static const QRegExp SPACE_CLEANER("\\s*([" + POS_LAT + NEG_LAT + POS_LON +
NEG_LON + degreeSigns() + "'\"\\s])\\s*");
const QString normalized = gps_text.trimmed().toUpper().replace(SPACE_CLEANER, "\\1");
const QString normalized = gps_text.trimmed().toUpper().
replace(SPACE_CLEANER, "\\1").
replace(QStringLiteral(""), "'").
replace(QStringLiteral(""), "'").
replace(QStringLiteral("''"), "\"").
replace(QStringLiteral(""), "\"");
if (normalized.isEmpty()) {
*latitude = 0.0;