From f6e5f6eaf2eb958aa043440c8941b25339644360 Mon Sep 17 00:00:00 2001 From: Karim Pinter Date: Thu, 2 Feb 2017 14:16:16 +0200 Subject: Fix previous fix for trailing 0 handling The previous fix, 82c5cc6532ac5d0323ecda94b6767e1fdaef2639, wasn't handling properly double conversion to string, this change is rather going through the characters instead. It also adds new test cases. Task-number: QTBUG-58245 Change-Id: I1563d541b0c9fef1254b5fb728308fb2517ed3aa Reviewed-by: Andy Shaw Reviewed-by: Edward Welbourne --- src/xmlpatterns/schema/qxsdtypechecker.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/xmlpatterns/schema/qxsdtypechecker.cpp b/src/xmlpatterns/schema/qxsdtypechecker.cpp index d6b224f..d165a1f 100644 --- a/src/xmlpatterns/schema/qxsdtypechecker.cpp +++ b/src/xmlpatterns/schema/qxsdtypechecker.cpp @@ -150,14 +150,14 @@ static int totalDigitsForDecimal(const QString &lexicalValue) static int fractionDigitsForDecimal(const QString &lexicalValue) { - // we use the lexical value here, as the conversion to double might strip - // away decimal positions - bool ok = false; - double dbl = lexicalValue.toDouble(&ok); - if (!ok) + const int pos = lexicalValue.indexOf(QLatin1Char('.')); + if (pos == -1) return 0; - dbl = dbl - qFloor(dbl); - return QString::number(dbl).length() - 2; + const QStringRef fraction = QStringRef(&lexicalValue).mid(pos).trimmed(); + int i = fraction.length() - 1; // fraction[0] is '.' so fraction is not empty + while (fraction.at(i) == QLatin1Char('0')) + --i; + return i; // The significant fraction-digits are fraction[1 through i]. } XsdTypeChecker::XsdTypeChecker(const XsdSchemaContext::Ptr &context, const QVector &namespaceBindings, const QSourceLocation &location) -- cgit v1.2.1