diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-05-06 19:01:26 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-05-07 08:07:40 +0200 |
commit | 4cec737a53c736bd38e81f7ba555c39117aaaf68 (patch) | |
tree | a462067110d83647e3f057cd7449b5332b85f75c /sal | |
parent | 31e2b4746a4a5d7661c4aa8f6a4489e50982aede (diff) |
Revert a thinko from commit 876010cbc4584249e919c694b8b977fd4e83084e
Indeed, the cDecSeparator and cGroupSeparator require that the buffer
uses the proper character type, otherwise it won't be possible to use
Unicode separators in rtl_math_doubleToUString.
Change-Id: Id26bed72776475c1be5b092e3ffcff0e75ffe557
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151451
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/qa/rtl/math/test-rtl-math.cxx | 8 | ||||
-rw-r--r-- | sal/rtl/strtmpl.hxx | 8 |
2 files changed, 12 insertions, 4 deletions
diff --git a/sal/qa/rtl/math/test-rtl-math.cxx b/sal/qa/rtl/math/test-rtl-math.cxx index 57ac2a2616f0..05879d567760 100644 --- a/sal/qa/rtl/math/test-rtl-math.cxx +++ b/sal/qa/rtl/math/test-rtl-math.cxx @@ -328,6 +328,14 @@ public: '.', aGroups, ',', true); CPPUNIT_ASSERT_EQUAL( OUString("1,000"), aRes); + // Check non-ASCII separators: Arabic decimal separator U+066B, thousand separator U+066C + fVal = 123456.78; + aRes = rtl::math::doubleToUString( fVal, + rtl_math_StringFormat_Automatic, + 2, + u'٫', aGroups, u'٬', true); + CPPUNIT_ASSERT_EQUAL( OUString(u"1٬23٬456٫78"), aRes); + fVal = 4503599627370495.0; aRes = rtl::math::doubleToUString( fVal, rtl_math_StringFormat_Automatic, diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx index cbbef030198f..eece825ec082 100644 --- a/sal/rtl/strtmpl.hxx +++ b/sal/rtl/strtmpl.hxx @@ -1416,7 +1416,7 @@ void doubleToString(rtl_tString** pResult, sal_Int32* pResultCapacity, sal_Int32 return (n + d / 2) / d * d; }; - auto append = [](rtl_tString** s, sal_Int32* pCapacity, sal_Int32 rOffset, std::string_view sv) + auto append = [](rtl_tString** s, sal_Int32* pCapacity, sal_Int32 rOffset, auto sv) { if (!pCapacity) newFromStr_WithLength(s, sv.data(), sv.size()); @@ -1569,8 +1569,8 @@ void doubleToString(rtl_tString** pResult, sal_Int32* pResultCapacity, sal_Int32 // max(nDigits) = max(nDecPlaces) + 1 + max(nExp) + 1 = 20 + 1 + 308 + 1 = 330 // max(nBuf) = max(nDigits) + max(nDecPlaces) + 10 + max(nDigits) * 2 = 330 * 3 + 20 + 10 = 1020 assert(nBuf <= 1024); - char* const pBuf = static_cast<char*>(alloca(nBuf)); - char* p = pBuf; + auto* const pBuf = static_cast<Char_T<rtl_tString>*>(alloca(nBuf * sizeof(Char_T<rtl_tString>))); + auto* p = pBuf; if (bSign) *p++ = '-'; @@ -1718,7 +1718,7 @@ void doubleToString(rtl_tString** pResult, sal_Int32* pResultCapacity, sal_Int32 *p++ = nExp % 10 + '0'; } - append(pResult, pResultCapacity, nResultOffset, std::string_view(pBuf, p - pBuf)); + append(pResult, pResultCapacity, nResultOffset, std::basic_string_view(pBuf, p - pBuf)); } template <sal_Int32 maxLen, typename C, typename T> sal_Int32 SAL_CALL valueOfFP(C* pStr, T f) |