TCX Parser: Strtod is locale specific

When parsing in locale's where numbers use a
',' as a decimal point, strtod fails to parse
lon/lat values.

Thanks to Horst Huschauer for the fix.

Fixes #365.
This commit is contained in:
Mark Liversedge
2012-12-03 21:51:05 +00:00
parent 0b478e79bb
commit af119ff710

View File

@@ -104,9 +104,20 @@ TcxParser::endElement( const QString&, const QString&, const QString& qName)
else if (qName == "Value") { hr = buffer.toDouble(); }
else if (qName == "Cadence") { cadence = buffer.toDouble(); }
else if (qName == "AltitudeMeters") { alt = buffer.toDouble(); }
else if (qName == "LongitudeDegrees") { char *p; lon = strtod(buffer.toLatin1(), &p); }
else if (qName == "LatitudeDegrees") { char *p; lat = strtod(buffer.toLatin1(), &p); }
else if (qName == "Trackpoint") {
else if (qName == "LongitudeDegrees") {
char *p;
setlocale(LC_NUMERIC,"C"); // strtod is locale dependent!
lon = strtod(buffer.toLatin1(), &p);
setlocale(LC_NUMERIC,"");
} else if (qName == "LatitudeDegrees") {
char *p;
setlocale(LC_NUMERIC,"C"); // strtod is locale dependent!
lat = strtod(buffer.toLatin1(), &p);
setlocale(LC_NUMERIC,"");
} else if (qName == "Trackpoint") {
// Some TCX files have Speed, some have Distance
// Lets derive Speed from Distance or vice-versa