[Libreoffice-commits] core.git: svl/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Thu Jan 3 15:13:26 UTC 2019
svl/source/numbers/zformat.cxx | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
New commits:
commit b39ee3f45db25fb689574a17210daa16cc511f6b
Author: Matteo Casalin <matteo.casalin at yahoo.com>
AuthorDate: Wed Nov 21 23:33:52 2018 +0100
Commit: Matteo Casalin <matteo.casalin at yahoo.com>
CommitDate: Thu Jan 3 16:13:05 2019 +0100
Avoid getTokenCount
Change-Id: I66d6e8d91924b2dcca9ab8ab499fb94bfb1dc723
Reviewed-on: https://gerrit.libreoffice.org/65658
Tested-by: Jenkins
Reviewed-by: Matteo Casalin <matteo.casalin at yahoo.com>
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
}
More information about the Libreoffice-commits
mailing list