Avoid getTokenCount

Change-Id: I66d6e8d91924b2dcca9ab8ab499fb94bfb1dc723
Reviewed-on: https://gerrit.libreoffice.org/65658
Tested-by: Jenkins
Reviewed-by: Matteo Casalin <matteo.casalin@yahoo.com>
This commit is contained in:
Matteo Casalin
2018-11-21 23:33:52 +01:00
parent 920f9155a7
commit b39ee3f45d

View File

@@ -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 void SvNumberformat::ImpGetOutputStdToPrecision(double& rNumber, OUString& rOutString, sal_uInt16 nPrecision) const
{ {
// Make sure the precision doesn't go over the maximum allowable precision. // 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, rOutString = ::rtl::math::doubleToUString( rNumber,
rtl_math_StringFormat_F, nPrecision /*2*/, rtl_math_StringFormat_F, nPrecision /*2*/,
GetFormatter().GetNumDecimalSep()[0], true ); GetFormatter().GetNumDecimalSep()[0], true );
if (rOutString[0] == '-' && if (rOutString[0] == '-' && checkForAll0s(rOutString, 1))
comphelper::string::getTokenCount(rOutString, '0') == rOutString.getLength())
{ {
rOutString = comphelper::string::stripStart(rOutString, '-'); // not -0 rOutString = comphelper::string::stripStart(rOutString, '-'); // not -0
} }
@@ -4302,8 +4322,7 @@ bool SvNumberformat::ImpGetNumberOutput(double fNumber,
} }
sStr.remove( nDecPos, 1 ); // Remove . sStr.remove( nDecPos, 1 ); // Remove .
} }
if (bSign && (sStr.isEmpty() || if (bSign && (sStr.isEmpty() || checkForAll0s(sStr))) // Only 00000
comphelper::string::getTokenCount(sStr.toString(), '0') == sStr.getLength()+1)) // Only 00000
{ {
bSign = false; // Not -0.00 bSign = false; // Not -0.00
} }