add string_view wrappers for rtl::math::stringToDouble
Change-Id: I114bec72cb933238675e539a8388a607226827cd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133455 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
@@ -110,7 +110,7 @@ namespace basegfx::internal
|
||||
if(sNumberString.getLength())
|
||||
{
|
||||
rtl_math_ConversionStatus eStatus;
|
||||
o_fRetval = ::rtl::math::stringToDouble( sNumberString.makeStringAndClear(),
|
||||
o_fRetval = ::rtl::math::stringToDouble( sNumberString,
|
||||
'.',
|
||||
',',
|
||||
&eStatus );
|
||||
|
||||
@@ -172,11 +172,10 @@ ErrCode ImpScan( const OUString& rWSrc, double& nVal, SbxDataType& rType,
|
||||
if( decsep > 1 || exp > 1 )
|
||||
bRes = false;
|
||||
|
||||
OUString aBufStr( aBuf.makeStringAndClear());
|
||||
rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok;
|
||||
sal_Int32 nParseEnd = 0;
|
||||
nVal = rtl::math::stringToDouble( aBufStr, cIntntlDecSep, cIntntlGrpSep, &eStatus, &nParseEnd );
|
||||
if( eStatus != rtl_math_ConversionStatus_Ok || nParseEnd != aBufStr.getLength() )
|
||||
nVal = rtl::math::stringToDouble( aBuf, cIntntlDecSep, cIntntlGrpSep, &eStatus, &nParseEnd );
|
||||
if( eStatus != rtl_math_ConversionStatus_Ok || nParseEnd != aBuf.getLength() )
|
||||
bRes = false;
|
||||
|
||||
if( !decsep && !exp )
|
||||
|
||||
@@ -91,7 +91,7 @@ struct OOO_DLLPUBLIC_CHARTTOOLS AnyToString
|
||||
*/
|
||||
struct OOO_DLLPUBLIC_CHARTTOOLS OUStringToDouble
|
||||
{
|
||||
double operator() ( const OUString & rStr )
|
||||
double operator() ( std::u16string_view rStr )
|
||||
{
|
||||
rtl_math_ConversionStatus eConversionStatus;
|
||||
double fResult = ::rtl::math::stringToDouble( rStr, '.', ',', & eConversionStatus );
|
||||
|
||||
@@ -1648,7 +1648,7 @@ Reference<XPropertySet> ODbaseTable::isUniqueByColumnName(sal_Int32 _nColumnPos)
|
||||
return Reference<XPropertySet>();
|
||||
}
|
||||
|
||||
static double toDouble(const OString& rString)
|
||||
static double toDouble(std::string_view rString)
|
||||
{
|
||||
return ::rtl::math::stringToDouble( rString, '.', ',' );
|
||||
}
|
||||
|
||||
@@ -173,6 +173,23 @@ inline void doubleToUStringBuffer( rtl::OUStringBuffer& rBuffer, double fValue,
|
||||
|
||||
/** A wrapper around rtl_math_stringToDouble.
|
||||
*/
|
||||
#ifdef LIBO_INTERNAL_ONLY
|
||||
inline double stringToDouble(std::string_view aString,
|
||||
char cDecSeparator, char cGroupSeparator,
|
||||
rtl_math_ConversionStatus * pStatus = NULL,
|
||||
sal_Int32 * pParsedEnd = NULL)
|
||||
{
|
||||
char const * pBegin = aString.data();
|
||||
char const * pEnd;
|
||||
double fResult = rtl_math_stringToDouble(pBegin,
|
||||
pBegin + aString.size(),
|
||||
cDecSeparator, cGroupSeparator,
|
||||
pStatus, &pEnd);
|
||||
if (pParsedEnd != NULL)
|
||||
*pParsedEnd = static_cast<sal_Int32>(pEnd - pBegin);
|
||||
return fResult;
|
||||
}
|
||||
#else
|
||||
inline double stringToDouble(rtl::OString const & rString,
|
||||
char cDecSeparator, char cGroupSeparator,
|
||||
rtl_math_ConversionStatus * pStatus = NULL,
|
||||
@@ -188,9 +205,29 @@ inline double stringToDouble(rtl::OString const & rString,
|
||||
*pParsedEnd = static_cast<sal_Int32>(pEnd - pBegin);
|
||||
return fResult;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/** A wrapper around rtl_math_uStringToDouble.
|
||||
*/
|
||||
#ifdef LIBO_INTERNAL_ONLY
|
||||
inline double stringToDouble(std::u16string_view aString,
|
||||
sal_Unicode cDecSeparator,
|
||||
sal_Unicode cGroupSeparator,
|
||||
rtl_math_ConversionStatus * pStatus = NULL,
|
||||
sal_Int32 * pParsedEnd = NULL)
|
||||
{
|
||||
sal_Unicode const * pBegin = aString.data();
|
||||
sal_Unicode const * pEnd;
|
||||
double fResult = rtl_math_uStringToDouble(pBegin,
|
||||
pBegin + aString.size(),
|
||||
cDecSeparator, cGroupSeparator,
|
||||
pStatus, &pEnd);
|
||||
if (pParsedEnd != NULL)
|
||||
*pParsedEnd = static_cast<sal_Int32>(pEnd - pBegin);
|
||||
return fResult;
|
||||
}
|
||||
#else
|
||||
inline double stringToDouble(rtl::OUString const & rString,
|
||||
sal_Unicode cDecSeparator,
|
||||
sal_Unicode cGroupSeparator,
|
||||
@@ -207,6 +244,7 @@ inline double stringToDouble(rtl::OUString const & rString,
|
||||
*pParsedEnd = static_cast<sal_Int32>(pEnd - pBegin);
|
||||
return fResult;
|
||||
}
|
||||
#endif
|
||||
|
||||
/** A wrapper around rtl_math_round.
|
||||
*/
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <sax/saxdllapi.h>
|
||||
|
||||
#include <rtl/strbuf.hxx>
|
||||
#include <sal/types.h>
|
||||
#include <rtl/ustrbuf.hxx>
|
||||
#include <com/sun/star/util/MeasureUnit.hpp>
|
||||
@@ -184,6 +185,13 @@ public:
|
||||
sal_Int16 nSourceUnit,
|
||||
sal_Int16 nTargetUnit );
|
||||
|
||||
/** convert string to double number (using ::rtl::math) and DO convert from
|
||||
source unit to target unit. */
|
||||
static bool convertDouble( double& rValue,
|
||||
std::string_view rString,
|
||||
sal_Int16 nSourceUnit,
|
||||
sal_Int16 nTargetUnit );
|
||||
|
||||
/** convert string to double number (using ::rtl::math) without unit conversion */
|
||||
static bool convertDouble(double& rValue, std::u16string_view rString);
|
||||
|
||||
@@ -281,6 +289,7 @@ public:
|
||||
sal_Int32 nPos );
|
||||
|
||||
static double GetConversionFactor(OUStringBuffer& rUnit, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit);
|
||||
static double GetConversionFactor(OStringBuffer& rUnit, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit);
|
||||
static sal_Int16 GetUnitFromString(std::u16string_view rString, sal_Int16 nDefaultUnit);
|
||||
static sal_Int16 GetUnitFromString(std::string_view rString, sal_Int16 nDefaultUnit);
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@ public:
|
||||
rtl::math::stringToDouble() does. The caller is responsible for proper
|
||||
error checking and end comparison.
|
||||
|
||||
@param rString
|
||||
@param aString
|
||||
The string to parse as floating point number.
|
||||
@param bUseGroupSep
|
||||
Whether group separator is used/accepted during parsing.
|
||||
@@ -264,7 +264,7 @@ public:
|
||||
rtl::math::stringToDouble().
|
||||
@return The floating point number as parsed.
|
||||
*/
|
||||
double stringToDouble( const OUString& rString, bool bUseGroupSep,
|
||||
double stringToDouble( std::u16string_view aString, bool bUseGroupSep,
|
||||
rtl_math_ConversionStatus* pStatus, sal_Int32* pParseEnd ) const;
|
||||
|
||||
/** A wrapper around rtl_math_uStringToDouble() using the locale dependent
|
||||
|
||||
@@ -222,6 +222,9 @@ public:
|
||||
/** convert string to double number (using ::rtl::math) and DO convert. */
|
||||
bool convertDouble(double& rValue, std::u16string_view rString) const;
|
||||
|
||||
/** convert string to double number (using ::rtl::math) and DO convert. */
|
||||
bool convertDouble(double& rValue, std::string_view rString) const;
|
||||
|
||||
/** get the Null Date of the XModel and set it to the UnitConverter */
|
||||
bool setNullDate (
|
||||
const css::uno::Reference <css::frame::XModel>& xModel);
|
||||
|
||||
@@ -304,7 +304,7 @@ namespace oox::ppt {
|
||||
}
|
||||
else if (msCommand.startsWith("playFrom"))
|
||||
{
|
||||
const OUString aMediaTime( msCommand.copy( 9, msCommand.getLength() - 10 ) );
|
||||
std::u16string_view aMediaTime( msCommand.subView( 9, msCommand.getLength() - 10 ) );
|
||||
rtl_math_ConversionStatus eStatus;
|
||||
double fMediaTime = ::rtl::math::stringToDouble( aMediaTime, u'.', u',', &eStatus );
|
||||
if( eStatus == rtl_math_ConversionStatus_Ok )
|
||||
|
||||
@@ -65,11 +65,11 @@ using ::com::sun::star::drawing::PolygonFlags_CONTROL;
|
||||
|
||||
namespace {
|
||||
|
||||
bool lclExtractDouble( double& orfValue, sal_Int32& ornEndPos, const OUString& rValue )
|
||||
bool lclExtractDouble( double& orfValue, sal_Int32& ornEndPos, std::u16string_view aValue )
|
||||
{
|
||||
// extract the double value and find start position of unit characters
|
||||
rtl_math_ConversionStatus eConvStatus = rtl_math_ConversionStatus_Ok;
|
||||
orfValue = ::rtl::math::stringToDouble( rValue, '.', '\0', &eConvStatus, &ornEndPos );
|
||||
orfValue = ::rtl::math::stringToDouble( aValue, '.', '\0', &eConvStatus, &ornEndPos );
|
||||
return eConvStatus == rtl_math_ConversionStatus_Ok;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,42 +54,42 @@ public:
|
||||
rtl_math_ConversionStatus status;
|
||||
sal_Int32 end;
|
||||
double res = rtl::math::stringToDouble(
|
||||
OUString(" +1.E01foo"),
|
||||
" +1.E01foo",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(RTL_CONSTASCII_LENGTH(" +1.E01"), end);
|
||||
CPPUNIT_ASSERT_EQUAL(10.0, res);
|
||||
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("NaN"),
|
||||
"NaN",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), end);
|
||||
CPPUNIT_ASSERT(std::isnan(res));
|
||||
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("NaN1.23"),
|
||||
"NaN1.23",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), end);
|
||||
CPPUNIT_ASSERT(std::isnan(res));
|
||||
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("+NaN"),
|
||||
"+NaN",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end);
|
||||
CPPUNIT_ASSERT_EQUAL(0.0, res);
|
||||
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("-NaN"),
|
||||
"-NaN",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end);
|
||||
CPPUNIT_ASSERT_EQUAL(0.0, res);
|
||||
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("+1.#NAN"),
|
||||
"+1.#NAN",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(7), end);
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
CPPUNIT_ASSERT(!std::signbit(res));
|
||||
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("-1.#NAN"),
|
||||
"-1.#NAN",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(7), end);
|
||||
@@ -105,28 +105,28 @@ public:
|
||||
CPPUNIT_ASSERT(std::signbit(res));
|
||||
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("INF"),
|
||||
"INF",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_OutOfRange, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), end);
|
||||
CPPUNIT_ASSERT(std::isinf(res));
|
||||
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("INF1.23"),
|
||||
"INF1.23",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_OutOfRange, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), end);
|
||||
CPPUNIT_ASSERT(std::isinf(res));
|
||||
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString(".5"),
|
||||
".5",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), end);
|
||||
CPPUNIT_ASSERT_EQUAL(0.5, res);
|
||||
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("5."),
|
||||
"5.",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), end);
|
||||
@@ -134,7 +134,7 @@ public:
|
||||
|
||||
// Leading 0 and group separator.
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("0,123"),
|
||||
"0,123",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), end);
|
||||
@@ -142,7 +142,7 @@ public:
|
||||
|
||||
// Leading 0 and two consecutive group separators are none.
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("0,,1"),
|
||||
"0,,1",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), end);
|
||||
@@ -150,7 +150,7 @@ public:
|
||||
|
||||
// Leading 0 and group separator at end is none.
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("0,"),
|
||||
"0,",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), end);
|
||||
@@ -158,7 +158,7 @@ public:
|
||||
|
||||
// Leading 0 and group separator before non-digit is none.
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("0,x"),
|
||||
"0,x",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), end);
|
||||
@@ -166,7 +166,7 @@ public:
|
||||
|
||||
// Trailing group separator is none.
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("1,234,"),
|
||||
"1,234,",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), end);
|
||||
@@ -174,7 +174,7 @@ public:
|
||||
|
||||
// Group separator followed by non-digit is none.
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("1,234,x"),
|
||||
"1,234,x",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), end);
|
||||
@@ -182,67 +182,67 @@ public:
|
||||
|
||||
// Check that the value is the nearest double-precision representation of the decimal 0.0042
|
||||
// (it was 0.0042000000000000006 instead of 0.0041999999999999997)
|
||||
res = rtl::math::stringToDouble(OUString("0,0042"), ',', ' ', &status, &end);
|
||||
res = rtl::math::stringToDouble("0,0042", ',', ' ', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(0.0042, res);
|
||||
|
||||
// "- 1" is nothing
|
||||
res = rtl::math::stringToDouble(OUString("- 1"), '.', ',', &status, &end);
|
||||
res = rtl::math::stringToDouble("- 1", '.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end);
|
||||
CPPUNIT_ASSERT_EQUAL(0.0, res);
|
||||
|
||||
// "-1E+E" : no exponent
|
||||
res = rtl::math::stringToDouble(OUString("-1E+E"), '.', ',', &status, &end);
|
||||
res = rtl::math::stringToDouble("-1E+E", '.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), end);
|
||||
CPPUNIT_ASSERT_EQUAL(-1.0, res);
|
||||
|
||||
// "-0" is negative zero
|
||||
res = rtl::math::stringToDouble(OUString("-0"), '.', ',', &status, &end);
|
||||
res = rtl::math::stringToDouble("-0", '.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), end);
|
||||
CPPUNIT_ASSERT_EQUAL(0.0, res);
|
||||
CPPUNIT_ASSERT(std::signbit(res));
|
||||
|
||||
// Compensating: "0.001E311" is 1E308, not overflow/inf
|
||||
res = rtl::math::stringToDouble(OUString("0.001E311"), '.', ',', &status, &end);
|
||||
res = rtl::math::stringToDouble("0.001E311", '.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(9), end);
|
||||
CPPUNIT_ASSERT_EQUAL(1E308, res);
|
||||
|
||||
res = rtl::math::stringToDouble(OUString("1E8589934590"), '.', ',', &status, &end);
|
||||
res = rtl::math::stringToDouble("1E8589934590", '.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_OutOfRange, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(12), end);
|
||||
CPPUNIT_ASSERT_EQUAL(std::numeric_limits<double>::infinity(), res);
|
||||
|
||||
// DBL_MAX and 4 nextafters
|
||||
double fValAfter = DBL_MAX;
|
||||
res = rtl::math::stringToDouble(OUString("1.7976931348623157e+308"), '.', ',', &status, &end);
|
||||
res = rtl::math::stringToDouble("1.7976931348623157e+308", '.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(23), end);
|
||||
CPPUNIT_ASSERT_EQUAL(fValAfter, res);
|
||||
|
||||
fValAfter = std::nextafter( fValAfter, 0);
|
||||
res = rtl::math::stringToDouble(OUString("1.7976931348623155e+308"), '.', ',', &status, &end);
|
||||
res = rtl::math::stringToDouble("1.7976931348623155e+308", '.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(23), end);
|
||||
CPPUNIT_ASSERT_EQUAL(fValAfter, res);
|
||||
|
||||
fValAfter = std::nextafter( fValAfter, 0);
|
||||
res = rtl::math::stringToDouble(OUString("1.7976931348623153e+308"), '.', ',', &status, &end);
|
||||
res = rtl::math::stringToDouble("1.7976931348623153e+308", '.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(23), end);
|
||||
CPPUNIT_ASSERT_EQUAL(fValAfter, res);
|
||||
|
||||
fValAfter = std::nextafter( fValAfter, 0);
|
||||
res = rtl::math::stringToDouble(OUString("1.7976931348623151e+308"), '.', ',', &status, &end);
|
||||
res = rtl::math::stringToDouble("1.7976931348623151e+308", '.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(23), end);
|
||||
CPPUNIT_ASSERT_EQUAL(fValAfter, res);
|
||||
|
||||
fValAfter = std::nextafter( fValAfter, 0);
|
||||
res = rtl::math::stringToDouble(OUString("1.7976931348623149e+308"), '.', ',', &status, &end);
|
||||
res = rtl::math::stringToDouble("1.7976931348623149e+308", '.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(23), end);
|
||||
CPPUNIT_ASSERT_EQUAL(fValAfter, res);
|
||||
@@ -252,28 +252,28 @@ public:
|
||||
rtl_math_ConversionStatus status;
|
||||
sal_Int32 end;
|
||||
double res = rtl::math::stringToDouble(
|
||||
OUString(" +Efoo"),
|
||||
" +Efoo",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end);
|
||||
CPPUNIT_ASSERT_EQUAL(0.0, res);
|
||||
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("."),
|
||||
".",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end);
|
||||
CPPUNIT_ASSERT_EQUAL(0.0, res);
|
||||
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString(" +.Efoo"),
|
||||
" +.Efoo",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end);
|
||||
CPPUNIT_ASSERT_EQUAL(0.0, res);
|
||||
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString(" +,.Efoo"),
|
||||
" +,.Efoo",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end);
|
||||
@@ -281,7 +281,7 @@ public:
|
||||
|
||||
// Leading group separator is none.
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString(",1234"),
|
||||
",1234",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), end);
|
||||
@@ -292,13 +292,13 @@ public:
|
||||
rtl_math_ConversionStatus status;
|
||||
sal_Int32 end;
|
||||
double res = rtl::math::stringToDouble(
|
||||
OUString("1e"),
|
||||
"1e",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(RTL_CONSTASCII_LENGTH("1"), end);
|
||||
CPPUNIT_ASSERT_EQUAL(1.0, res);
|
||||
res = rtl::math::stringToDouble(
|
||||
OUString("0e"),
|
||||
"0e",
|
||||
'.', ',', &status, &end);
|
||||
CPPUNIT_ASSERT_EQUAL(rtl_math_ConversionStatus_Ok, status);
|
||||
CPPUNIT_ASSERT_EQUAL(RTL_CONSTASCII_LENGTH("1"), end);
|
||||
|
||||
@@ -686,6 +686,22 @@ bool Converter::convertDouble(double& rValue,
|
||||
return true;
|
||||
}
|
||||
|
||||
/** convert string to double number (using ::rtl::math) */
|
||||
bool Converter::convertDouble(double& rValue,
|
||||
std::string_view rString, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
|
||||
{
|
||||
if (!convertDouble(rValue, rString))
|
||||
return false;
|
||||
|
||||
OStringBuffer sUnit;
|
||||
// fdo#48969: switch source and target because factor is used to divide!
|
||||
double const fFactor =
|
||||
GetConversionFactor(sUnit, nTargetUnit, nSourceUnit);
|
||||
if(fFactor != 1.0 && fFactor != 0.0)
|
||||
rValue /= fFactor;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** convert string to double number (using ::rtl::math) */
|
||||
bool Converter::convertDouble(double& rValue, std::u16string_view rString)
|
||||
{
|
||||
@@ -2280,6 +2296,25 @@ double Converter::GetConversionFactor(OUStringBuffer& rUnit, sal_Int16 nSourceUn
|
||||
return fRetval;
|
||||
}
|
||||
|
||||
double Converter::GetConversionFactor(OStringBuffer& rUnit, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
|
||||
{
|
||||
double fRetval(1.0);
|
||||
rUnit.setLength(0);
|
||||
|
||||
|
||||
if(nSourceUnit != nTargetUnit)
|
||||
{
|
||||
const o3tl::Length eFrom = Measure2O3tlUnit(nSourceUnit);
|
||||
const o3tl::Length eTo = Measure2O3tlUnit(nTargetUnit);
|
||||
fRetval = o3tl::convert(1.0, eFrom, eTo);
|
||||
|
||||
if (const auto sUnit = Measure2UnitString(nTargetUnit); sUnit.size() > 0)
|
||||
rUnit.append(sUnit.data(), sUnit.size());
|
||||
}
|
||||
|
||||
return fRetval;
|
||||
}
|
||||
|
||||
template<typename V>
|
||||
static sal_Int16 lcl_GetUnitFromString(V rString, sal_Int16 nDefaultUnit)
|
||||
{
|
||||
|
||||
@@ -191,9 +191,8 @@ bool ScStringUtil::parseSimpleNumber(
|
||||
|
||||
rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok;
|
||||
sal_Int32 nParseEnd = 0;
|
||||
OUString aString( aBuf.makeStringAndClear());
|
||||
rVal = ::rtl::math::stringToDouble( aString, dsep, gsep, &eStatus, &nParseEnd);
|
||||
if (eStatus != rtl_math_ConversionStatus_Ok || nParseEnd < aString.getLength())
|
||||
rVal = ::rtl::math::stringToDouble( aBuf, dsep, gsep, &eStatus, &nParseEnd);
|
||||
if (eStatus != rtl_math_ConversionStatus_Ok || nParseEnd < aBuf.getLength())
|
||||
// Not a valid number or not entire string consumed.
|
||||
return false;
|
||||
|
||||
@@ -337,9 +336,8 @@ bool ScStringUtil::parseSimpleNumber(
|
||||
|
||||
rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok;
|
||||
sal_Int32 nParseEnd = 0;
|
||||
OString aString( aBuf.makeStringAndClear());
|
||||
rVal = ::rtl::math::stringToDouble( aString, dsep, gsep, &eStatus, &nParseEnd);
|
||||
if (eStatus != rtl_math_ConversionStatus_Ok || nParseEnd < aString.getLength())
|
||||
rVal = ::rtl::math::stringToDouble( aBuf, dsep, gsep, &eStatus, &nParseEnd);
|
||||
if (eStatus != rtl_math_ConversionStatus_Ok || nParseEnd < aBuf.getLength())
|
||||
// Not a valid number or not entire string consumed.
|
||||
return false;
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <com/sun/star/sheet/ConditionOperator2.hpp>
|
||||
#include <sal/log.hxx>
|
||||
#include <osl/diagnose.h>
|
||||
#include <o3tl/string_view.hxx>
|
||||
#include <svl/sharedstringpool.hxx>
|
||||
#include <oox/core/filterbase.hxx>
|
||||
#include <oox/helper/binaryinputstream.hxx>
|
||||
@@ -101,12 +102,12 @@ const sal_uInt16 BIFF12_CFRULE_ABOVEAVERAGE = 0x0004;
|
||||
const sal_uInt16 BIFF12_CFRULE_BOTTOM = 0x0008;
|
||||
const sal_uInt16 BIFF12_CFRULE_PERCENT = 0x0010;
|
||||
|
||||
bool isValue(const OUString& rStr, double& rVal)
|
||||
bool isValue(std::u16string_view rStr, double& rVal)
|
||||
{
|
||||
sal_Int32 nEnd = -1;
|
||||
rVal = rtl::math::stringToDouble(rStr.trim(), '.', ',', nullptr, &nEnd);
|
||||
rVal = rtl::math::stringToDouble(o3tl::trim(rStr), '.', ',', nullptr, &nEnd);
|
||||
|
||||
return nEnd >= rStr.getLength();
|
||||
return nEnd >= static_cast<sal_Int32>(rStr.size());
|
||||
}
|
||||
|
||||
void SetCfvoData( ColorScaleRuleModelEntry* pEntry, const AttributeList& rAttribs )
|
||||
|
||||
@@ -1727,7 +1727,7 @@ void AnimationImporter::importCommandContainer( const Atom* pAtom, const Referen
|
||||
}
|
||||
else if( aParam.startsWith( "playFrom" ) )
|
||||
{
|
||||
const OUString aMediaTime( aParam.copy( 9, aParam.getLength() - 10 ) );
|
||||
const std::u16string_view aMediaTime( aParam.subView( 9, aParam.getLength() - 10 ) );
|
||||
rtl_math_ConversionStatus eStatus;
|
||||
double fMediaTime = ::rtl::math::stringToDouble( aMediaTime, u'.', u',', &eStatus );
|
||||
if( eStatus == rtl_math_ConversionStatus_Ok )
|
||||
|
||||
@@ -273,7 +273,7 @@ namespace svgio::svgreader
|
||||
rtl_math_ConversionStatus eStatus;
|
||||
|
||||
fNum = rtl::math::stringToDouble(
|
||||
aNum.makeStringAndClear(), '.', ',',
|
||||
aNum, '.', ',',
|
||||
&eStatus);
|
||||
|
||||
return eStatus == rtl_math_ConversionStatus_Ok;
|
||||
|
||||
@@ -4057,7 +4057,7 @@ bool ImpSvNumberInputScan::IsNumberFormat( const OUString& rString, // s
|
||||
}
|
||||
sResString.append(sStrArray[nNums[nNumericsCnt-1]]);
|
||||
rtl_math_ConversionStatus eStatus;
|
||||
fOutNumber = ::rtl::math::stringToDouble( sResString.makeStringAndClear(), '.', ',', &eStatus );
|
||||
fOutNumber = ::rtl::math::stringToDouble( sResString, '.', ',', &eStatus );
|
||||
if ( eStatus == rtl_math_ConversionStatus_OutOfRange )
|
||||
{
|
||||
F_Type = SvNumFormatType::TEXT; // overflow/underflow -> Text
|
||||
|
||||
@@ -101,7 +101,7 @@ SwSortElement::~SwSortElement()
|
||||
{
|
||||
}
|
||||
|
||||
double SwSortElement::StrToDouble( const OUString& rStr )
|
||||
double SwSortElement::StrToDouble( std::u16string_view rStr )
|
||||
{
|
||||
if( !pLclData )
|
||||
pLclData = new LocaleDataWrapper( LanguageTag( *pLocale ));
|
||||
|
||||
@@ -82,7 +82,7 @@ struct SwSortElement
|
||||
|
||||
bool operator<(const SwSortElement& ) const;
|
||||
|
||||
static double StrToDouble(const OUString& rStr);
|
||||
static double StrToDouble(std::u16string_view rStr);
|
||||
private:
|
||||
int keycompare(const SwSortElement& rCmp, sal_uInt16 nKey) const;
|
||||
};
|
||||
|
||||
@@ -1413,22 +1413,13 @@ OUString LocaleDataWrapper::getCurr( sal_Int64 nNumber, sal_uInt16 nDecimals,
|
||||
|
||||
// --- number parsing -------------------------------------------------
|
||||
|
||||
double LocaleDataWrapper::stringToDouble( const OUString& rString, bool bUseGroupSep,
|
||||
double LocaleDataWrapper::stringToDouble( std::u16string_view aString, bool bUseGroupSep,
|
||||
rtl_math_ConversionStatus* pStatus, sal_Int32* pParseEnd ) const
|
||||
{
|
||||
const sal_Unicode cGroupSep = (bUseGroupSep ? aLocaleDataItem.thousandSeparator[0] : 0);
|
||||
rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok;
|
||||
sal_Int32 nParseEnd = 0;
|
||||
double fValue = rtl::math::stringToDouble( rString, aLocaleDataItem.decimalSeparator[0], cGroupSep, &eStatus, &nParseEnd);
|
||||
bool bTryAlt = (nParseEnd < rString.getLength() && !aLocaleDataItem.decimalSeparatorAlternative.isEmpty() &&
|
||||
rString[nParseEnd] == aLocaleDataItem.decimalSeparatorAlternative.toChar());
|
||||
// Try re-parsing with alternative if that was the reason to stop.
|
||||
if (bTryAlt)
|
||||
fValue = rtl::math::stringToDouble( rString, aLocaleDataItem.decimalSeparatorAlternative.toChar(), cGroupSep, &eStatus, &nParseEnd);
|
||||
if (pStatus)
|
||||
*pStatus = eStatus;
|
||||
const sal_Unicode* pParseEndChar;
|
||||
double fValue = stringToDouble(aString.data(), aString.data() + aString.size(), bUseGroupSep, pStatus, &pParseEndChar);
|
||||
if (pParseEnd)
|
||||
*pParseEnd = nParseEnd;
|
||||
*pParseEnd = pParseEndChar - aString.data();
|
||||
return fValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,12 +44,12 @@ namespace psp
|
||||
|
||||
|
||||
// parses the first double in the string; decimal is '.' only
|
||||
inline double StringToDouble( const OUString& rStr )
|
||||
inline double StringToDouble( std::u16string_view rStr )
|
||||
{
|
||||
return rtl::math::stringToDouble(rStr, u'.', u'\0');
|
||||
}
|
||||
|
||||
inline double StringToDouble(const OString& rStr)
|
||||
inline double StringToDouble(std::string_view rStr)
|
||||
{
|
||||
return rtl::math::stringToDouble(rStr, '.', static_cast<char>(0));
|
||||
}
|
||||
|
||||
@@ -348,6 +348,17 @@ bool SvXMLUnitConverter::convertDouble(double& rValue,
|
||||
eSrcUnit, m_pImpl->m_eCoreMeasureUnit);
|
||||
}
|
||||
|
||||
/** convert string to double number (using ::rtl::math) */
|
||||
bool SvXMLUnitConverter::convertDouble(double& rValue,
|
||||
std::string_view rString) const
|
||||
{
|
||||
sal_Int16 const eSrcUnit = ::sax::Converter::GetUnitFromString(
|
||||
rString, m_pImpl->m_eCoreMeasureUnit);
|
||||
|
||||
return ::sax::Converter::convertDouble(rValue, rString,
|
||||
eSrcUnit, m_pImpl->m_eCoreMeasureUnit);
|
||||
}
|
||||
|
||||
/** get the Null Date of the XModel and set it to the UnitConverter */
|
||||
bool SvXMLUnitConverter::setNullDate(const css::uno::Reference <css::frame::XModel>& xModel)
|
||||
{
|
||||
@@ -539,7 +550,7 @@ bool SvXMLTokenEnumerator::getNextToken( std::u16string_view& rToken )
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool lcl_getPositions(std::u16string_view _sValue, OUString& _rContentX, OUString& _rContentY, OUString& _rContentZ)
|
||||
static bool lcl_getPositions(std::u16string_view _sValue, std::u16string_view& _rContentX, std::u16string_view& _rContentY, std::u16string_view& _rContentZ)
|
||||
{
|
||||
if(_sValue.empty() || _sValue[0] != '(')
|
||||
return false;
|
||||
@@ -570,7 +581,7 @@ static bool lcl_getPositions(std::u16string_view _sValue, OUString& _rContentX,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool lcl_getPositions(std::string_view _sValue,OUString& _rContentX,OUString& _rContentY,OUString& _rContentZ)
|
||||
static bool lcl_getPositions(std::string_view _sValue, std::string_view& _rContentX, std::string_view& _rContentY, std::string_view& _rContentZ)
|
||||
{
|
||||
if(_sValue.empty() || _sValue[0] != '(')
|
||||
return false;
|
||||
@@ -581,7 +592,7 @@ static bool lcl_getPositions(std::string_view _sValue,OUString& _rContentX,OUStr
|
||||
if(nFound == std::string_view::npos || nFound <= nPos)
|
||||
return false;
|
||||
|
||||
_rContentX = OUString::fromUtf8(_sValue.substr(nPos, nFound - nPos));
|
||||
_rContentX = _sValue.substr(nPos, nFound - nPos);
|
||||
|
||||
nPos = nFound + 1;
|
||||
nFound = _sValue.find(' ', nPos);
|
||||
@@ -589,7 +600,7 @@ static bool lcl_getPositions(std::string_view _sValue,OUString& _rContentX,OUStr
|
||||
if(nFound == std::string_view::npos || nFound <= nPos)
|
||||
return false;
|
||||
|
||||
_rContentY = OUString::fromUtf8(_sValue.substr(nPos, nFound - nPos));
|
||||
_rContentY = _sValue.substr(nPos, nFound - nPos);
|
||||
|
||||
nPos = nFound + 1;
|
||||
nFound = _sValue.find(')', nPos);
|
||||
@@ -597,7 +608,7 @@ static bool lcl_getPositions(std::string_view _sValue,OUString& _rContentX,OUStr
|
||||
if(nFound == std::string_view::npos || nFound <= nPos)
|
||||
return false;
|
||||
|
||||
_rContentZ = OUString::fromUtf8(_sValue.substr(nPos, nFound - nPos));
|
||||
_rContentZ = _sValue.substr(nPos, nFound - nPos);
|
||||
return true;
|
||||
|
||||
}
|
||||
@@ -605,7 +616,7 @@ static bool lcl_getPositions(std::string_view _sValue,OUString& _rContentX,OUStr
|
||||
/** convert string to ::basegfx::B3DVector */
|
||||
bool SvXMLUnitConverter::convertB3DVector( ::basegfx::B3DVector& rVector, std::u16string_view rValue )
|
||||
{
|
||||
OUString aContentX,aContentY,aContentZ;
|
||||
std::u16string_view aContentX,aContentY,aContentZ;
|
||||
if ( !lcl_getPositions(rValue,aContentX,aContentY,aContentZ) )
|
||||
return false;
|
||||
|
||||
@@ -633,7 +644,7 @@ bool SvXMLUnitConverter::convertB3DVector( ::basegfx::B3DVector& rVector, std::u
|
||||
/** convert string to ::basegfx::B3DVector */
|
||||
bool SvXMLUnitConverter::convertB3DVector( ::basegfx::B3DVector& rVector, std::string_view rValue )
|
||||
{
|
||||
OUString aContentX,aContentY,aContentZ;
|
||||
std::string_view aContentX,aContentY,aContentZ;
|
||||
if ( !lcl_getPositions(rValue,aContentX,aContentY,aContentZ) )
|
||||
return false;
|
||||
|
||||
@@ -674,7 +685,7 @@ void SvXMLUnitConverter::convertB3DVector( OUStringBuffer &rBuffer, const ::base
|
||||
bool SvXMLUnitConverter::convertPosition3D( drawing::Position3D& rPosition,
|
||||
std::string_view rValue ) const
|
||||
{
|
||||
OUString aContentX,aContentY,aContentZ;
|
||||
std::string_view aContentX,aContentY,aContentZ;
|
||||
if ( !lcl_getPositions(rValue,aContentX,aContentY,aContentZ) )
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user