Kaydet (Commit) ca214981 authored tarafından Eike Rathke's avatar Eike Rathke

Handle decimalSeparatorAlternative in ScColumn::ParseString(), tdf#81671

Change-Id: I9f708b28ee5fdb23217e75386a64ab86dacfd3c4
üst c1a47f1a
...@@ -122,12 +122,13 @@ public: ...@@ -122,12 +122,13 @@ public:
* @param rStr string to parse * @param rStr string to parse
* @param dsep decimal separator * @param dsep decimal separator
* @param gsep group separator (aka thousands separator) * @param gsep group separator (aka thousands separator)
* @param dsepa decimal separator alternative, usually 0
* @param rVal value of successfully parsed number * @param rVal value of successfully parsed number
* *
* @return true if the string is a valid number, false otherwise. * @return true if the string is a valid number, false otherwise.
*/ */
static bool parseSimpleNumber( 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( static bool parseSimpleNumber(
const char* p, size_t n, char dsep, char gsep, double& rVal); const char* p, size_t n, char dsep, char gsep, double& rVal);
......
...@@ -1641,6 +1641,7 @@ void Test::testCSV() ...@@ -1641,6 +1641,7 @@ void Test::testCSV()
bool bResult = ScStringUtil::parseSimpleNumber bool bResult = ScStringUtil::parseSimpleNumber
(aStr, aTests[i].eSep == English ? '.' : ',', (aStr, aTests[i].eSep == English ? '.' : ',',
aTests[i].eSep == English ? ',' : '.', aTests[i].eSep == English ? ',' : '.',
0,
nValue); nValue);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("CSV numeric detection failure", aTests[i].bResult, bResult); CPPUNIT_ASSERT_EQUAL_MESSAGE ("CSV numeric detection failure", aTests[i].bResult, bResult);
CPPUNIT_ASSERT_EQUAL_MESSAGE ("CSV numeric value failure", aTests[i].nValue, nValue); CPPUNIT_ASSERT_EQUAL_MESSAGE ("CSV numeric value failure", aTests[i].nValue, nValue);
......
...@@ -1806,13 +1806,15 @@ bool ScColumn::ParseString( ...@@ -1806,13 +1806,15 @@ bool ScColumn::ParseString(
const LocaleDataItem2& aLocaleItem = pLocale->getLocaleItem(); const LocaleDataItem2& aLocaleItem = pLocale->getLocaleItem();
const OUString& rDecSep = aLocaleItem.decimalSeparator; const OUString& rDecSep = aLocaleItem.decimalSeparator;
const OUString& rGroupSep = aLocaleItem.thousandSeparator; 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; break;
sal_Unicode dsep = rDecSep[0]; sal_Unicode dsep = rDecSep[0];
sal_Unicode gsep = rGroupSep[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; break;
rCell.set(nVal); rCell.set(nVal);
......
...@@ -49,7 +49,7 @@ void ScSetStringParam::setNumericInput() ...@@ -49,7 +49,7 @@ void ScSetStringParam::setNumericInput()
} }
bool ScStringUtil::parseSimpleNumber( 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 // Actually almost the entire pre-check is unnecessary and we could call
// rtl::math::stringToDouble() just after having exchanged ascii space with // rtl::math::stringToDouble() just after having exchanged ascii space with
...@@ -110,7 +110,7 @@ bool ScStringUtil::parseSimpleNumber( ...@@ -110,7 +110,7 @@ bool ScStringUtil::parseSimpleNumber(
haveSeenDigit = true; haveSeenDigit = true;
++nDigitCount; ++nDigitCount;
} }
else if (c == dsep) else if (c == dsep || (dsepa && c == dsepa))
{ {
// this is a decimal separator. // this is a decimal separator.
...@@ -125,7 +125,7 @@ bool ScStringUtil::parseSimpleNumber( ...@@ -125,7 +125,7 @@ bool ScStringUtil::parseSimpleNumber(
nPosDSep = i; nPosDSep = i;
nPosGSep = -1; nPosGSep = -1;
aBuf.append(c); aBuf.append(dsep); // append the separator that is parsed in stringToDouble() below
nDigitCount = 0; nDigitCount = 0;
} }
else if (c == gsep) else if (c == gsep)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment