Resolves: tdf#122110 convert condition decimal separator to target locale
Otherwise re-scanning the format code in the target locale failed.
Change-Id: Ia4face1b5630c197f68b1f521e62b163550301e6
Reviewed-on: https://gerrit.libreoffice.org/77852
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
diff --git a/include/svl/zforlist.hxx b/include/svl/zforlist.hxx
index 2d52ce4..adbde81 100644
--- a/include/svl/zforlist.hxx
+++ b/include/svl/zforlist.hxx
@@ -719,6 +719,9 @@ public:
/// Return the decimal separator matching the locale of the given format
OUString GetFormatDecimalSep( sal_uInt32 nFormat ) const;
/// Return the decimal separator matching the given locale / LanguageType.
OUString GetLangDecimalSep( LanguageType nLang ) const;
/// Return a NfCurrencyTable with pointers to <type>NfCurrencyEntry</type> entries
static const NfCurrencyTable& GetTheCurrencyTable();
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index cc44b9b..7a558bd 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -2076,20 +2076,30 @@ OUString SvNumberFormatter::GetFormatDecimalSep( sal_uInt32 nFormat ) const
{
::osl::MutexGuard aGuard( GetInstanceMutex() );
const SvNumberformat* pFormat = GetFormatEntry(nFormat);
if ( !pFormat || pFormat->GetLanguage() == ActLnge )
if (!pFormat)
{
return GetNumDecimalSep();
}
return GetLangDecimalSep( pFormat->GetLanguage());
}
OUString SvNumberFormatter::GetLangDecimalSep( LanguageType nLang ) const
{
::osl::MutexGuard aGuard( GetInstanceMutex() );
if (nLang == ActLnge)
{
return GetNumDecimalSep();
}
OUString aRet;
LanguageType eSaveLang = xLocaleData.getCurrentLanguage();
if ( pFormat->GetLanguage() == eSaveLang )
if (nLang == eSaveLang)
{
aRet = xLocaleData->getNumDecimalSep();
}
else
{
LanguageTag aSaveLocale( xLocaleData->getLanguageTag() );
const_cast<SvNumberFormatter*>(this)->xLocaleData.changeLocale( LanguageTag( pFormat->GetLanguage()) );
const_cast<SvNumberFormatter*>(this)->xLocaleData.changeLocale( LanguageTag( nLang));
aRet = xLocaleData->getNumDecimalSep();
const_cast<SvNumberFormatter*>(this)->xLocaleData.changeLocale( aSaveLocale );
}
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index c182c93..792f6cb 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -788,8 +788,11 @@ SvNumberformat::SvNumberformat(OUString& rString,
sBuff.replace( cNNBSp, ' ');
}
OUString aConvertFromDecSep;
OUString aConvertToDecSep;
if (rScan.GetConvertMode())
{
aConvertFromDecSep = GetFormatter().GetNumDecimalSep();
maLocale.meLanguage = rScan.GetNewLnge();
eLan = maLocale.meLanguage; // Make sure to return switch
}
@@ -850,6 +853,7 @@ SvNumberformat::SvNumberformat(OUString& rString,
sal_Int32 nCntChars = ImpGetNumber(sBuff, nPos, sStr);
if (nCntChars > 0)
{
sal_Int32 nDecPos;
SvNumFormatType F_Type = SvNumFormatType::UNDEFINED;
if (!pISc->IsNumberFormat(sStr, F_Type, fNumber, nullptr) ||
( F_Type != SvNumFormatType::NUMBER &&
@@ -861,6 +865,20 @@ SvNumberformat::SvNumberformat(OUString& rString,
sBuff.insert(nPos, '0');
nPos++;
}
else if (rScan.GetConvertMode() && ((nDecPos = sStr.indexOf( aConvertFromDecSep)) >= 0))
{
if (aConvertToDecSep.isEmpty())
aConvertToDecSep = GetFormatter().GetLangDecimalSep( rScan.GetNewLnge());
if (aConvertToDecSep != aConvertFromDecSep)
{
const OUString aStr( sStr.replaceAt( nDecPos,
aConvertFromDecSep.getLength(), aConvertToDecSep));
nPos = nPos - nCntChars;
sBuff.remove(nPos, nCntChars);
sBuff.insert(nPos, aStr);
nPos += aStr.getLength();
}
}
}
else
{