basic/qa/basic_coverage/da-DK/test_ccur_da_DK_locale.bas | 6 - basic/qa/basic_coverage/test_ccur_method.bas | 3 basic/qa/basic_coverage/zh-CN/test_ccur_zh_CN_locale.bas | 2 basic/source/sbx/sbxcurr.cxx | 81 +++++---------- 4 files changed, 38 insertions(+), 54 deletions(-)
New commits: commit 7bbf1f2a7d4cb3230bf69723b6864cff1a52d531 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sat Aug 31 20:12:07 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sun Sep 1 04:06:52 2024 +0200 Refactor ImpCurrencyToString for simplicity Change-Id: Ie7acafb3c81348f03340f1aaa53b3849c8dae4a6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172694 Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Jenkins diff --git a/basic/source/sbx/sbxcurr.cxx b/basic/source/sbx/sbxcurr.cxx index 37de86a800f3..be4fed2b7bdd 100644 --- a/basic/source/sbx/sbxcurr.cxx +++ b/basic/source/sbx/sbxcurr.cxx @@ -32,63 +32,39 @@ static OUString ImpCurrencyToString( sal_Int64 rVal ) { - bool isNeg = ( rVal < 0 ); - sal_Int64 absVal = isNeg ? -rVal : rVal; - sal_Unicode cDecimalSep, cThousandSepDummy, cDecimalSepAltDummy; ImpGetIntntlSep(cDecimalSep, cThousandSepDummy, cDecimalSepAltDummy); - OUString aAbsStr = OUString::number( absVal ); - - sal_Int32 initialLen = aAbsStr.getLength(); - - bool bLessThanOne = false; - if ( initialLen <= 4 ) // if less the 1 - bLessThanOne = true; - - sal_Int32 nCapacity = 6; // minimum e.g. 0.0000 - - if ( !bLessThanOne ) + OUStringBuffer aBuf(22); + if (rVal < 0) { - nCapacity = initialLen + 1; + aBuf.append('-'); + rVal = -rVal; } + OUString aAbsStr = OUString::number(rVal); + sal_Int32 hasFractDigits = std::min(aAbsStr.getLength(), sal_Int32(4)); + sal_Int32 hasWholeDigits = aAbsStr.getLength() - hasFractDigits; - if ( isNeg ) - ++nCapacity; - - OUStringBuffer aBuf( nCapacity ); - aBuf.setLength( nCapacity ); - - - sal_Int32 nDigitCount = 0; - sal_Int32 nInsertIndex = nCapacity - 1; - sal_Int32 nEndIndex = isNeg ? 1 : 0; - - for ( sal_Int32 charCpyIndex = aAbsStr.getLength() - 1; nInsertIndex >= nEndIndex; ++nDigitCount ) - { - if ( nDigitCount == 4 ) - aBuf[nInsertIndex--] = cDecimalSep; - if ( nDigitCount < initialLen ) - aBuf[nInsertIndex--] = aAbsStr[ charCpyIndex-- ]; - else - // Handle leading 0's to right of decimal separator - // Note: in VBA the stringification is a little more complex - // but more natural as only the necessary digits - // to the right of the decimal places are displayed - // It would be great to conditionally be able to display like that too - - // Val OOo (Cur) VBA (Cur) - // --- --------- --------- - // 0 0.0000 0 - // 0.1 0.1000 0.1 - - aBuf[nInsertIndex--] = '0'; - } - if ( isNeg ) - aBuf[nInsertIndex] = '-'; - - aAbsStr = aBuf.makeStringAndClear(); - return aAbsStr; + if (hasWholeDigits > 0) + aBuf.append(aAbsStr.subView(0, hasWholeDigits)); + else + aBuf.append('0'); + aBuf.append(cDecimalSep); + // Handle leading 0's to right of decimal separator + // Note: in VBA the stringification is a little more complex + // but more natural as only the necessary digits + // to the right of the decimal places are displayed + // It would be great to conditionally be able to display like that too + + // Val OOo (Cur) VBA (Cur) + // --- --------- --------- + // 0 0.0000 0 + // 0.1 0.1000 0.1 + for (sal_Int32 i = 4; i > hasFractDigits; --i) + aBuf.append('0'); + aBuf.append(aAbsStr.subView(aAbsStr.getLength() - hasFractDigits, hasFractDigits)); + + return aBuf.makeStringAndClear(); } static sal_Int64 ImpStringToCurrency(const rtl::OUString& rStr) commit a795fddafad69e8a7ce600352c7236b35539cebb Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sat Aug 31 20:08:28 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sun Sep 1 04:06:40 2024 +0200 tdf#162724: use localized decimal separator in ImpCurrencyToString Same as in ImpCvtNum Change-Id: Icbaa237e944a39309b01fdb18e668d054ff61c60 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172693 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/basic/qa/basic_coverage/da-DK/test_ccur_da_DK_locale.bas b/basic/qa/basic_coverage/da-DK/test_ccur_da_DK_locale.bas index 52b8d3b6f1aa..ff4704fcc3db 100644 --- a/basic/qa/basic_coverage/da-DK/test_ccur_da_DK_locale.bas +++ b/basic/qa/basic_coverage/da-DK/test_ccur_da_DK_locale.bas @@ -18,8 +18,10 @@ Sub verify_testCCurDaDKLocale On Error GoTo errorHandler ' tdf#141050 - characteristic test for CCur() with the da_DK locale - TestUtil.AssertEqual(CCur("75,50"), 75.5, "CCur(75,50)") - TestUtil.AssertEqual(CCur("75,50 kr."), 75.5, "CCur(75,50 kr.)") + TestUtil.AssertEqual(CCur("75,50"), 75.5, "CCur(""75,50"")") + TestUtil.AssertEqual(CCur("75,50 kr."), 75.5, "CCur(""75,50 kr."")") + ' tdf#162724 - CStr must create strings that allow CCur round-trip + TestUtil.AssertEqual(CCur(CStr(CCur(75.50))), 75.5, "CCur(CStr(CCur(75.50)))") Exit Sub errorHandler: diff --git a/basic/qa/basic_coverage/test_ccur_method.bas b/basic/qa/basic_coverage/test_ccur_method.bas index c42dcb938590..d1c6c247a6e2 100644 --- a/basic/qa/basic_coverage/test_ccur_method.bas +++ b/basic/qa/basic_coverage/test_ccur_method.bas @@ -29,6 +29,9 @@ Sub verify_testCCur TestUtil.AssertEqual(CCur("$100"), 100, "CCur($100)") TestUtil.AssertEqual(CCur("$1.50"), 1.5, "CCur($1.50)") + ' tdf#162724 - CStr must create strings that allow CCur round-trip + TestUtil.AssertEqual(CCur(CStr(CCur(75.50))), 75.5, "CCur(CStr(CCur(75.50)))") + verify_testCCurUnderflow verify_testCCurOverflow verify_testCCurInvalidFormat diff --git a/basic/qa/basic_coverage/zh-CN/test_ccur_zh_CN_locale.bas b/basic/qa/basic_coverage/zh-CN/test_ccur_zh_CN_locale.bas index 38a084e36c7f..2d63cd87a72f 100644 --- a/basic/qa/basic_coverage/zh-CN/test_ccur_zh_CN_locale.bas +++ b/basic/qa/basic_coverage/zh-CN/test_ccur_zh_CN_locale.bas @@ -20,6 +20,8 @@ Sub verify_testCCurZhCNLocale ' tdf#141050 - characteristic test for CCur() with the zh_CN locale TestUtil.AssertEqual(CCur("75.50"), 75.5, "CCur(75.50)") TestUtil.AssertEqual(CCur("¥75.50"), 75.5, "CCur(¥75.50)") + ' tdf#162724 - CStr must create strings that allow CCur round-trip + TestUtil.AssertEqual(CCur(CStr(CCur(75.50))), 75.5, "CCur(CStr(CCur(75.50)))") Exit Sub errorHandler: diff --git a/basic/source/sbx/sbxcurr.cxx b/basic/source/sbx/sbxcurr.cxx index ca67977a3a56..37de86a800f3 100644 --- a/basic/source/sbx/sbxcurr.cxx +++ b/basic/source/sbx/sbxcurr.cxx @@ -35,7 +35,8 @@ static OUString ImpCurrencyToString( sal_Int64 rVal ) bool isNeg = ( rVal < 0 ); sal_Int64 absVal = isNeg ? -rVal : rVal; - sal_Unicode const cDecimalSep = '.'; + sal_Unicode cDecimalSep, cThousandSepDummy, cDecimalSepAltDummy; + ImpGetIntntlSep(cDecimalSep, cThousandSepDummy, cDecimalSepAltDummy); OUString aAbsStr = OUString::number( absVal ); @@ -70,7 +71,7 @@ static OUString ImpCurrencyToString( sal_Int64 rVal ) if ( nDigitCount < initialLen ) aBuf[nInsertIndex--] = aAbsStr[ charCpyIndex-- ]; else - // Handle leading 0's to right of decimal point + // Handle leading 0's to right of decimal separator // Note: in VBA the stringification is a little more complex // but more natural as only the necessary digits // to the right of the decimal places are displayed