tdf#170670 NumberFormat: fix blank width string treatment

In case of 2 characters string text,
with a delimiter as text and a blank width string like
"-"_)
the delimiter is now treated as text

Add qa test with format of bug report:
[>0]#,##0_);[<0](#,##0);"-"_)

Change-Id: Idd4542bd186c6b6b348f6716bee2fd5055f2c83f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199314
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Laurent Balland
2026-02-15 18:22:33 +01:00
committed by Mike Kaganski
parent a4d5492e65
commit fb07ca38af
3 changed files with 14 additions and 3 deletions
Binary file not shown.
+10
View File
@@ -1681,6 +1681,16 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testBlankWidthCharacter)
// save to XLSX and reload
saveAndReload(TestFilter::XLSX);
lcl_TestNumberFormat(*getScDoc(), u"_-?0;-?0;_-?0;@"_ustr);
createScDoc("ods/tdf170670-Blank-width-char.ods");
// save to ODS and reload
saveAndReload(TestFilter::ODS);
lcl_TestNumberFormat(*getScDoc(), u"[>0]#,##0_);[<0](#,##0);\"-\"_)"_ustr);
// save to XLSX and reload
saveAndReload(TestFilter::XLSX);
lcl_TestNumberFormat(*getScDoc(), u"#,##0_);\\(#,##0\\);-_)"_ustr);
}
CPPUNIT_TEST_FIXTURE(ScExportTest4, testEmbeddedTextInDecimal)
+4 -3
View File
@@ -530,13 +530,13 @@ static bool lcl_ValidChar( sal_Unicode cChar, const SvXMLNumFormatContext& rPare
return false;
}
static void lcl_EnquoteIfNecessary( OUStringBuffer& rContent, const SvXMLNumFormatContext& rParent )
static void lcl_EnquoteIfNecessary( OUStringBuffer& rContent, const SvXMLNumFormatContext& rParent, const bool bIsBlankWidthStringEmpty = true )
{
bool bQuote = true;
sal_Int32 nLength = rContent.getLength();
const SvXMLStylesTokens nFormatType = rParent.GetType();
if (nFormatType != SvXMLStylesTokens::BOOLEAN_STYLE &&
if (nFormatType != SvXMLStylesTokens::BOOLEAN_STYLE && bIsBlankWidthStringEmpty &&
((nLength == 1 && lcl_ValidChar( rContent[0], rParent)) ||
(nLength == 2 &&
((rContent[0] == ' ' && rContent[1] == '-') ||
@@ -547,6 +547,7 @@ static void lcl_EnquoteIfNecessary( OUStringBuffer& rContent, const SvXMLNumForm
// Or space followed by minus (used in currency formats) that would
// lead to almost duplicated formats with built-in formats just with
// the difference of quotes.
// tdf#170670: except if it is inside a blank width string
bQuote = false;
}
else if ( nFormatType == SvXMLStylesTokens::PERCENTAGE_STYLE && nLength > 1 )
@@ -974,7 +975,7 @@ void SvXMLNumFmtElementContext::endFastElement(sal_Int32 )
}
if ( !aContent.isEmpty() )
{
lcl_EnquoteIfNecessary( aContent, rParent );
lcl_EnquoteIfNecessary( aContent, rParent, sBlankWidthString.isEmpty() );
if ( !sBlankWidthString.isEmpty() )
{
lcl_InsertBlankWidthChars( sBlankWidthString, aContent );