diff options
author | Damjan Jovanovic <damjan@apache.org> | 2016-04-04 04:11:07 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-04-05 20:24:51 +0100 |
commit | 00cf864e5d317016d7224c199aa982d07bd70113 (patch) | |
tree | 9369746a0b67485dfd6aa4fd36c31886f428604c /sc | |
parent | dd46727b99d4bb5135451aa7e5e1bdb197373843 (diff) |
Resolves: #i126901# CSV import: values with + or - followed by...
thousand separator and 3 digits (eg. +,123) are imported as a number
Do not allow numbers parsed from CVS files when "Detect special numbers" is
off, to contain thousand separators before digits, even if after a +/- sign
(eg. -,123 or +,789). Treat these as strings instead.
Also added unit tests for this.
Patch by: me
(cherry picked from commit 10458a24f4e6cc311e65fb80ce576fed39937be2)
Change-Id: Ic946fc6a11326861f238157ddb651bc5a5b28edd
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/tool/stringutil.cxx | 12 |
2 files changed, 11 insertions, 5 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index fb78981ac426..f46cd76808ff 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -1815,7 +1815,9 @@ void Test::testCSV() { "1.0 ", European, false, 0.0 }, { "1.000", European, true, 1000.0 }, { "1137.999", English, true, 1137.999 }, - { "1.000.00", European, false, 0.0 } + { "1.000.00", European, false, 0.0 }, + { "+,123", English, false, 0.0 }, + { "-,123", English, false, 0.0 } }; for (sal_uInt32 i = 0; i < SAL_N_ELEMENTS(aTests); i++) { OUString aStr(aTests[i].pStr, strlen (aTests[i].pStr), RTL_TEXTENCODING_UTF8); diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx index 70313ffbaad1..606c0797e1fa 100644 --- a/sc/source/core/tool/stringutil.cxx +++ b/sc/source/core/tool/stringutil.cxx @@ -69,6 +69,7 @@ bool ScStringUtil::parseSimpleNumber( const sal_Unicode* pLast = p + (n-1); sal_Int32 nPosDSep = -1, nPosGSep = -1; sal_uInt32 nDigitCount = 0; + bool haveSeenDigit = false; sal_Int32 nPosExponent = -1; // Skip preceding spaces. @@ -106,6 +107,7 @@ bool ScStringUtil::parseSimpleNumber( { // this is a digit. aBuf.append(c); + haveSeenDigit = true; ++nDigitCount; } else if (c == dsep) @@ -130,8 +132,8 @@ bool ScStringUtil::parseSimpleNumber( { // this is a group (thousand) separator. - if (i == 0) - // not allowed as the first character. + if (!haveSeenDigit) + // not allowed before digits. return false; if (nPosDSep >= 0) @@ -216,6 +218,7 @@ bool ScStringUtil::parseSimpleNumber( const char* pLast = p + (n-1); sal_Int32 nPosDSep = -1, nPosGSep = -1; sal_uInt32 nDigitCount = 0; + bool haveSeenDigit = false; sal_Int32 nPosExponent = -1; // Skip preceding spaces. @@ -250,6 +253,7 @@ bool ScStringUtil::parseSimpleNumber( { // this is a digit. aBuf.append(c); + haveSeenDigit = true; ++nDigitCount; } else if (c == dsep) @@ -274,8 +278,8 @@ bool ScStringUtil::parseSimpleNumber( { // this is a group (thousand) separator. - if (i == 0) - // not allowed as the first character. + if (!haveSeenDigit) + // not allowed before digits. return false; if (nPosDSep >= 0) |