svl/source/numbers/zforlist.cxx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
New commits: commit 3e24263d6174cd1e33c4216acbd0130b4ffa2dce Author: Eike Rathke <[email protected]> AuthorDate: Mon Jun 20 17:13:53 2022 +0200 Commit: Xisco Fauli <[email protected]> CommitDate: Tue Jun 21 13:48:40 2022 +0200 Resolves: tdf#147265 Return correct default if currency format is duplicate For the default currency format SvNumberFormatter::GetCurrencyFormatStrings() returned always the last added position, regardless whether that format was added or not, which it isn't if the format code is a duplicate. Let addToCurrencyFormatsList() return the position of the existing format if the duplicate was rejected and use that for default. Change-Id: I148d7379de75cae402b063f7b2f92947e345176f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136187 Reviewed-by: Eike Rathke <[email protected]> Tested-by: Jenkins (cherry picked from commit 36cf12d449c892e6bbacb7da5f4b008f7762232b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136166 Reviewed-by: Xisco Fauli <[email protected]> diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index fbd05a481df9..6a9934fdbed1 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -4285,12 +4285,16 @@ void SvNumberFormatter::ImpInitCurrencyTable() } -static void addToCurrencyFormatsList( NfWSStringsDtor& rStrArr, const OUString& rFormat ) +static std::ptrdiff_t addToCurrencyFormatsList( NfWSStringsDtor& rStrArr, const OUString& rFormat ) { // Prevent duplicates even over subsequent calls of // GetCurrencyFormatStrings() with the same vector. - if (std::find( rStrArr.begin(), rStrArr.end(), rFormat) == rStrArr.end()) - rStrArr.push_back( rFormat); + NfWSStringsDtor::const_iterator it( std::find( rStrArr.begin(), rStrArr.end(), rFormat)); + if (it != rStrArr.end()) + return it - rStrArr.begin(); + + rStrArr.push_back( rFormat); + return rStrArr.size() - 1; } @@ -4319,9 +4323,7 @@ sal_uInt16 SvNumberFormatter::GetCurrencyFormatStrings( NfWSStringsDtor& rStrArr + ";" + aRed + aNegativeBank; - addToCurrencyFormatsList( rStrArr, format2); - - nDefault = rStrArr.size() - 1; + nDefault = addToCurrencyFormatsList( rStrArr, format2); } else { @@ -4374,8 +4376,7 @@ sal_uInt16 SvNumberFormatter::GetCurrencyFormatStrings( NfWSStringsDtor& rStrArr { addToCurrencyFormatsList( rStrArr, format3); } - addToCurrencyFormatsList( rStrArr, format4); - nDefault = rStrArr.size() - 1; + nDefault = addToCurrencyFormatsList( rStrArr, format4); if (rCurr.GetDigits()) { addToCurrencyFormatsList( rStrArr, format5);
