summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2020-07-03 19:09:33 +0200
committerEike Rathke <erack@redhat.com>2020-07-06 08:59:38 +0200
commit7186541219599e1b51ad35601c2cd015a329f360 (patch)
tree3ea4c9f047e202d1052e0cd434f419d4fa339b2b /svl
parentb9cd758f719951fd1d11b00979ca85cc79a1c2eb (diff)
Resolves: tdf#131562 decimal separator may not be surrounded by blanks
1 . 1 .2 1 . 2 1. 2 . 2 . 2 are not numbers. But .2 is. Change-Id: Ie2e0775852e13eee733d0fed3399cbd3d065d9fe Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97895 Tested-by: Jenkins Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'svl')
-rw-r--r--svl/source/numbers/zforfind.cxx42
-rw-r--r--svl/source/numbers/zforfind.hxx2
2 files changed, 35 insertions, 9 deletions
diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx
index 5a81e68af7a1..75716dd57521 100644
--- a/svl/source/numbers/zforfind.cxx
+++ b/svl/source/numbers/zforfind.cxx
@@ -499,9 +499,10 @@ inline bool ImpSvNumberInputScan::SkipChar( sal_Unicode c, const OUString& rStri
/**
* Skips blanks
*/
-inline void ImpSvNumberInputScan::SkipBlanks( const OUString& rString,
+inline bool ImpSvNumberInputScan::SkipBlanks( const OUString& rString,
sal_Int32& nPos )
{
+ sal_Int32 nHere = nPos;
if ( nPos < rString.getLength() )
{
const sal_Unicode* p = rString.getStr() + nPos;
@@ -511,6 +512,7 @@ inline void ImpSvNumberInputScan::SkipBlanks( const OUString& rString,
p++;
}
}
+ return nHere < nPos;
}
@@ -2271,10 +2273,13 @@ bool ImpSvNumberInputScan::ScanStartString( const OUString& rString )
if (nSign && nPos == rString.getLength())
return true;
+ const sal_Int32 nStartBlanks = nPos;
if ( GetDecSep(rString, nPos) ) // decimal separator in start string
{
- nDecPos = 1;
- SkipBlanks(rString, nPos);
+ if (SkipBlanks(rString, nPos))
+ nPos = nStartBlanks; // `. 2` not a decimal separator
+ else
+ nDecPos = 1; // leading decimal separator
}
else if ( GetCurrency(rString, nPos) ) // currency (DM 1)?
{
@@ -2290,8 +2295,13 @@ bool ImpSvNumberInputScan::ScanStartString( const OUString& rString )
}
if ( GetDecSep(rString, nPos) ) // decimal separator follows currency
{
- nDecPos = 1;
- SkipBlanks(rString, nPos);
+ if (SkipBlanks(rString, nPos))
+ {
+ nPos = nStartBlanks; // `DM . 2` not a decimal separator
+ eScannedType = SvNumFormatType::UNDEFINED; // !!! it is NOT currency !!!
+ }
+ else
+ nDecPos = 1; // leading decimal separator
}
}
else
@@ -2442,7 +2452,8 @@ bool ImpSvNumberInputScan::ScanMidString( const OUString& rString, sal_uInt16 nS
}
}
- SkipBlanks(rString, nPos);
+ const sal_Int32 nStartBlanks = nPos;
+ const bool bBlanks = SkipBlanks(rString, nPos);
if (GetDecSep(rString, nPos)) // decimal separator?
{
if (nDecPos == 1 || nDecPos == 3) // .12.4 or 1.E2.1
@@ -2472,10 +2483,19 @@ bool ImpSvNumberInputScan::ScanMidString( const OUString& rString, sal_uInt16 nS
return MatchedReturn();
}
}
+ else if (bBlanks)
+ {
+ // `1 .2` or `1 . 2` not a decimal separator, reset
+ nPos = nStartBlanks;
+ }
+ else if (SkipBlanks(rString, nPos))
+ {
+ // `1. 2` not a decimal separator, reset
+ nPos = nStartBlanks;
+ }
else
{
nDecPos = 2; // . in mid string
- SkipBlanks(rString, nPos);
}
}
else if ( (eScannedType & SvNumFormatType::TIME) &&
@@ -2798,7 +2818,8 @@ bool ImpSvNumberInputScan::ScanEndString( const OUString& rString )
}
}
- SkipBlanks(rString, nPos);
+ const sal_Int32 nStartBlanks = nPos;
+ const bool bBlanks = SkipBlanks(rString, nPos);
if (GetDecSep(rString, nPos)) // decimal separator?
{
if (nDecPos == 1 || nDecPos == 3) // .12.4 or 12.E4.
@@ -2828,6 +2849,11 @@ bool ImpSvNumberInputScan::ScanEndString( const OUString& rString )
return MatchedReturn();
}
}
+ else if (bBlanks)
+ {
+ // not a decimal separator, reset
+ nPos = nStartBlanks;
+ }
else
{
nDecPos = 3; // . in end string
diff --git a/svl/source/numbers/zforfind.hxx b/svl/source/numbers/zforfind.hxx
index 332f0ef6ef94..0c66cb46f770 100644
--- a/svl/source/numbers/zforfind.hxx
+++ b/svl/source/numbers/zforfind.hxx
@@ -264,7 +264,7 @@ private:
sal_Int32& nPos );
// Skip blank
- static inline void SkipBlanks( const OUString& rString,
+ static inline bool SkipBlanks( const OUString& rString,
sal_Int32& nPos );
// Jump over rWhat in rString at nPos