From ca214981553eb21a4276d07c76db0c37c234a11c Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Fri, 27 Oct 2017 15:27:07 +0200 Subject: Handle decimalSeparatorAlternative in ScColumn::ParseString(), tdf#81671 Change-Id: I9f708b28ee5fdb23217e75386a64ab86dacfd3c4 --- sc/inc/stringutil.hxx | 3 ++- sc/qa/unit/ucalc.cxx | 1 + sc/source/core/data/column3.cxx | 6 ++++-- sc/source/core/tool/stringutil.cxx | 6 +++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx index bf4c519ab014..b28867f7f361 100644 --- a/sc/inc/stringutil.hxx +++ b/sc/inc/stringutil.hxx @@ -122,12 +122,13 @@ public: * @param rStr string to parse * @param dsep decimal separator * @param gsep group separator (aka thousands separator) + * @param dsepa decimal separator alternative, usually 0 * @param rVal value of successfully parsed number * * @return true if the string is a valid number, false otherwise. */ static bool parseSimpleNumber( - const OUString& rStr, sal_Unicode dsep, sal_Unicode gsep, double& rVal); + const OUString& rStr, sal_Unicode dsep, sal_Unicode gsep, sal_Unicode dsepa, double& rVal); static bool parseSimpleNumber( const char* p, size_t n, char dsep, char gsep, double& rVal); diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index db7bb49bff27..f03bb90fd470 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -1641,6 +1641,7 @@ void Test::testCSV() bool bResult = ScStringUtil::parseSimpleNumber (aStr, aTests[i].eSep == English ? '.' : ',', aTests[i].eSep == English ? ',' : '.', + 0, nValue); CPPUNIT_ASSERT_EQUAL_MESSAGE ("CSV numeric detection failure", aTests[i].bResult, bResult); CPPUNIT_ASSERT_EQUAL_MESSAGE ("CSV numeric value failure", aTests[i].nValue, nValue); diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 001d8d320485..646210a8e679 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -1806,13 +1806,15 @@ bool ScColumn::ParseString( const LocaleDataItem2& aLocaleItem = pLocale->getLocaleItem(); const OUString& rDecSep = aLocaleItem.decimalSeparator; const OUString& rGroupSep = aLocaleItem.thousandSeparator; - if (rDecSep.getLength() != 1 || rGroupSep.getLength() != 1) + const OUString& rDecSepAlt = aLocaleItem.decimalSeparatorAlternative; + if (rDecSep.getLength() != 1 || rGroupSep.getLength() != 1 || rDecSepAlt.getLength() > 1) break; sal_Unicode dsep = rDecSep[0]; sal_Unicode gsep = rGroupSep[0]; + sal_Unicode dsepa = rDecSepAlt.toChar(); - if (!ScStringUtil::parseSimpleNumber(rString, dsep, gsep, nVal)) + if (!ScStringUtil::parseSimpleNumber(rString, dsep, gsep, dsepa, nVal)) break; rCell.set(nVal); diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx index 94f49e0fef70..8ac5a3a6a0d0 100644 --- a/sc/source/core/tool/stringutil.cxx +++ b/sc/source/core/tool/stringutil.cxx @@ -49,7 +49,7 @@ void ScSetStringParam::setNumericInput() } bool ScStringUtil::parseSimpleNumber( - const OUString& rStr, sal_Unicode dsep, sal_Unicode gsep, double& rVal) + const OUString& rStr, sal_Unicode dsep, sal_Unicode gsep, sal_Unicode dsepa, double& rVal) { // Actually almost the entire pre-check is unnecessary and we could call // rtl::math::stringToDouble() just after having exchanged ascii space with @@ -110,7 +110,7 @@ bool ScStringUtil::parseSimpleNumber( haveSeenDigit = true; ++nDigitCount; } - else if (c == dsep) + else if (c == dsep || (dsepa && c == dsepa)) { // this is a decimal separator. @@ -125,7 +125,7 @@ bool ScStringUtil::parseSimpleNumber( nPosDSep = i; nPosGSep = -1; - aBuf.append(c); + aBuf.append(dsep); // append the separator that is parsed in stringToDouble() below nDigitCount = 0; } else if (c == gsep) -- cgit v1.2.3