summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatteo Casalin <matteo.casalin@yahoo.com>2018-11-21 23:33:52 +0100
committerMatteo Casalin <matteo.casalin@yahoo.com>2019-01-03 16:13:05 +0100
commitb39ee3f45db25fb689574a17210daa16cc511f6b (patch)
treea05630044397fd23edbc280fcdab6fd5b8d07fba
parent920f9155a79120611acface4dc64f2ac0cc081f0 (diff)
Avoid getTokenCount
Change-Id: I66d6e8d91924b2dcca9ab8ab499fb94bfb1dc723 Reviewed-on: https://gerrit.libreoffice.org/65658 Tested-by: Jenkins Reviewed-by: Matteo Casalin <matteo.casalin@yahoo.com>
-rw-r--r--svl/source/numbers/zformat.cxx27
1 files changed, 23 insertions, 4 deletions
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 191024238308..903fd9960200 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -2038,6 +2038,27 @@ void SvNumberformat::ImpGetOutputStandard(double& fNumber, OUString& rOutString)
}
}
+namespace
+{
+
+template<typename T>
+bool checkForAll0s(const T& rString, sal_Int32 nIdx=0)
+{
+ if (nIdx>=rString.getLength())
+ return false;
+
+ do
+ {
+ if (rString[nIdx]!='0')
+ return false;
+ }
+ while (++nIdx<rString.getLength());
+
+ return true;
+}
+
+}
+
void SvNumberformat::ImpGetOutputStdToPrecision(double& rNumber, OUString& rOutString, sal_uInt16 nPrecision) const
{
// Make sure the precision doesn't go over the maximum allowable precision.
@@ -2051,8 +2072,7 @@ void SvNumberformat::ImpGetOutputStdToPrecision(double& rNumber, OUString& rOutS
rOutString = ::rtl::math::doubleToUString( rNumber,
rtl_math_StringFormat_F, nPrecision /*2*/,
GetFormatter().GetNumDecimalSep()[0], true );
- if (rOutString[0] == '-' &&
- comphelper::string::getTokenCount(rOutString, '0') == rOutString.getLength())
+ if (rOutString[0] == '-' && checkForAll0s(rOutString, 1))
{
rOutString = comphelper::string::stripStart(rOutString, '-'); // not -0
}
@@ -4302,8 +4322,7 @@ bool SvNumberformat::ImpGetNumberOutput(double fNumber,
}
sStr.remove( nDecPos, 1 ); // Remove .
}
- if (bSign && (sStr.isEmpty() ||
- comphelper::string::getTokenCount(sStr.toString(), '0') == sStr.getLength()+1)) // Only 00000
+ if (bSign && (sStr.isEmpty() || checkForAll0s(sStr))) // Only 00000
{
bSign = false; // Not -0.00
}