diff options
-rw-r--r-- | basegfx/source/tools/numbertools.cxx | 6 | ||||
-rw-r--r-- | include/rtl/math.hxx | 37 | ||||
-rw-r--r-- | include/rtl/strbuf.hxx | 24 |
3 files changed, 64 insertions, 3 deletions
diff --git a/basegfx/source/tools/numbertools.cxx b/basegfx/source/tools/numbertools.cxx index d30a8371ab2b..86b926ab55d2 100644 --- a/basegfx/source/tools/numbertools.cxx +++ b/basegfx/source/tools/numbertools.cxx @@ -12,7 +12,7 @@ #include <basegfx/polygon/b2dpolypolygon.hxx> #include <basegfx/polygon/b2dpolypolygontools.hxx> -#include <rtl/ustrbuf.hxx> +#include <rtl/strbuf.hxx> #include <rtl/math.hxx> #include <utility> @@ -27,8 +27,8 @@ namespace basegfx { namespace tools // } // config here - rtl::OUStringBuffer aNum; - rtl::math::doubleToUStringBuffer(aNum, + rtl::OStringBuffer aNum; + rtl::math::doubleToStringBuffer(aNum, fValue, rtl_math_StringFormat_F, nDecPlaces, '.', diff --git a/include/rtl/math.hxx b/include/rtl/math.hxx index fed674fdd210..7572c972a91f 100644 --- a/include/rtl/math.hxx +++ b/include/rtl/math.hxx @@ -21,6 +21,7 @@ #define INCLUDED_RTL_MATH_HXX #include <rtl/math.h> +#include <rtl/strbuf.hxx> #include <rtl/string.hxx> #include <rtl/ustring.hxx> #include <rtl/ustrbuf.hxx> @@ -63,6 +64,42 @@ inline rtl::OString doubleToString(double fValue, rtl_math_StringFormat eFormat, return aResult; } +/** A wrapper around rtl_math_doubleToString that appends to an + rtl::OStringBuffer. + + @since LibreOffice 5.4 +*/ +inline void doubleToStringBuffer( + rtl::OStringBuffer& rBuffer, double fValue, rtl_math_StringFormat eFormat, + sal_Int32 nDecPlaces, sal_Char cDecSeparator, sal_Int32 const * pGroups, + sal_Char cGroupSeparator, bool bEraseTrailingDecZeros = false) +{ + rtl_String ** pData; + sal_Int32 * pCapacity; + rBuffer.accessInternals(&pData, &pCapacity); + rtl_math_doubleToString( + pData, pCapacity, rBuffer.getLength(), fValue, eFormat, nDecPlaces, + cDecSeparator, pGroups, cGroupSeparator, bEraseTrailingDecZeros); +} + +/** A wrapper around rtl_math_doubleToString that appends to an + rtl::OStringBuffer, with no grouping. + + @since LibreOffice 5.4 +*/ +inline void doubleToStringBuffer( + rtl::OStringBuffer& rBuffer, double fValue, rtl_math_StringFormat eFormat, + sal_Int32 nDecPlaces, sal_Char cDecSeparator, + bool bEraseTrailingDecZeros = false) +{ + rtl_String ** pData; + sal_Int32 * pCapacity; + rBuffer.accessInternals(&pData, &pCapacity); + rtl_math_doubleToString( + pData, pCapacity, rBuffer.getLength(), fValue, eFormat, nDecPlaces, + cDecSeparator, NULL, 0, bEraseTrailingDecZeros); +} + /** A wrapper around rtl_math_doubleToUString. */ inline rtl::OUString doubleToUString(double fValue, diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx index 7cf4123d0ae8..791eb142f9dc 100644 --- a/include/rtl/strbuf.hxx +++ b/include/rtl/strbuf.hxx @@ -988,6 +988,30 @@ public: return *this; } + /** Allows access to the internal data of this OStringBuffer, for effective + manipulation. + + This function should be used with care. After you have called this + function, you may use the returned pInternalData and pInternalCapacity + only as long as you make no other calls on this OUStringBuffer. + + @param pInternalData + This output parameter receives a pointer to the internal data + (rtl_String pointer). pInternalData itself must not be null. + + @param pInternalCapacity + This output parameter receives a pointer to the internal capacity. + pInternalCapacity itself must not be null. + + @since LibreOffice 5.4 + */ + void accessInternals( + rtl_String *** pInternalData, sal_Int32 ** pInternalCapacity) + { + *pInternalData = &pData; + *pInternalCapacity = &nCapacity; + } + private: /** A pointer to the data structure which contains the data. |