diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-03-13 21:33:56 +0000 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-03-14 12:55:05 +0100 |
commit | 479893fa6fd82a7f96df63a6b89ed24c5e0a2866 (patch) | |
tree | 1f50e229f3ec3ffb70970e6f8c3ebbf83b7925e0 | |
parent | 4ec72f3935125d3994effd6fa863bbd357e0c246 (diff) |
Related: tdf#160056 pass 'StarFormat' flag in instead of changing state
towards making these immutable
Change-Id: I9f9ac17828018525194c34eadda66bbf863fd2f7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164795
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
-rw-r--r-- | include/svl/zformat.hxx | 23 | ||||
-rw-r--r-- | svl/source/numbers/zforlist.cxx | 26 | ||||
-rw-r--r-- | svl/source/numbers/zformat.cxx | 53 |
3 files changed, 49 insertions, 53 deletions
diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx index b4d7ddb0ac29..30f74af23a88 100644 --- a/include/svl/zformat.hxx +++ b/include/svl/zformat.hxx @@ -235,16 +235,15 @@ public: LanguageType nOriginalLang = LANGUAGE_DONTKNOW, bool bSystemLanguage = false ) const; - void SetStarFormatSupport( bool b ) { bStarFlag = b; } - /** * Get output string from a numeric value that fits the number of * characters specified. */ bool GetOutputString( double fNumber, sal_uInt16 nCharCount, OUString& rOutString ) const; - bool GetOutputString( double fNumber, OUString& OutString, const Color** ppColor ); - void GetOutputString( std::u16string_view sString, OUString& OutString, const Color** ppColor ); + // bStarFlag: Take *n format as ESC n + bool GetOutputString( double fNumber, OUString& OutString, const Color** ppColor, bool bStarFlag = false ); + void GetOutputString( std::u16string_view sString, OUString& OutString, const Color** ppColor, bool bStarFlag = false ); // True if type text bool IsTextFormat() const { return bool(eType & SvNumFormatType::TEXT); } @@ -513,7 +512,6 @@ private: SvNumberformatLimitOps eOp2; // Operator for second condition SvNumFormatType eType; // Type of format bool bAdditionalBuiltin; // If this is an additional built-in format defined by i18n - bool bStarFlag; // Take *n format as ESC n bool bStandard; // If this is a default standard format bool bIsUsed; // Flag as used for storing @@ -623,21 +621,23 @@ private: // Helper function for number strings // append string symbols, insert leading 0 or ' ', or ... - SVL_DLLPRIVATE bool ImpNumberFill( OUStringBuffer& sStr, + SVL_DLLPRIVATE bool ImpNumberFill(OUStringBuffer& sStr, double& rNumber, sal_Int32& k, sal_uInt16& j, sal_uInt16 nIx, short eSymbolType, + bool bStarFlag, bool bInsertRightBlank = false ); // Helper function to fill in the integer part and the group (AKA thousand) separators - SVL_DLLPRIVATE bool ImpNumberFillWithThousands( OUStringBuffer& sStr, + SVL_DLLPRIVATE bool ImpNumberFillWithThousands(OUStringBuffer& sStr, double& rNumber, sal_Int32 k, sal_uInt16 j, sal_uInt16 nIx, sal_Int32 nDigCnt, + bool bStarFlag, bool bAddDecSep = true ) const; // Helper function to fill in the group (AKA thousand) separators @@ -654,7 +654,8 @@ private: sal_Int32 nDecPos, sal_uInt16 j, sal_uInt16 nIx, - bool bInteger ) const; + bool bInteger, + bool bStarFlag) const; /** Calculate each element of fraction: * integer part, numerator part, denominator part @@ -671,19 +672,24 @@ private: sal_Int64& nDiv ) const; SVL_DLLPRIVATE bool ImpGetFractionOutput(double fNumber, sal_uInt16 nIx, + bool bStarFlag, OUStringBuffer& OutString); SVL_DLLPRIVATE bool ImpGetScientificOutput(double fNumber, sal_uInt16 nIx, + bool bStarFlag, OUStringBuffer& OutString); SVL_DLLPRIVATE bool ImpGetDateOutput( double fNumber, sal_uInt16 nIx, + bool bStarFlag, OUStringBuffer& OutString ); SVL_DLLPRIVATE bool ImpGetTimeOutput( double fNumber, sal_uInt16 nIx, + bool bStarFlag, OUStringBuffer& OutString ); SVL_DLLPRIVATE bool ImpGetDateTimeOutput( double fNumber, sal_uInt16 nIx, + bool bStarFlag, OUStringBuffer& OutString ); // Switches to the "gregorian" calendar if the current calendar is @@ -705,6 +711,7 @@ private: SVL_DLLPRIVATE bool ImpGetNumberOutput( double fNumber, sal_uInt16 nIx, + bool bStarFlag, OUStringBuffer& OutString ) const; SVL_DLLPRIVATE void ImpCopyNumberformat( const SvNumberformat& rFormat ); diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index c7b5ce164e65..24ecfed891f5 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -1763,15 +1763,7 @@ void SvNumberFormatter::GetOutputString(const OUString& sString, else { ChangeIntl(pFormat->GetLanguage()); - if ( bUseStarFormat ) - { - pFormat->SetStarFormatSupport( true ); - } - pFormat->GetOutputString(sString, sOutString, ppColor); - if ( bUseStarFormat ) - { - pFormat->SetStarFormatSupport( false ); - } + pFormat->GetOutputString(sString, sOutString, ppColor, bUseStarFormat); } } @@ -1791,11 +1783,7 @@ void SvNumberFormatter::GetOutputString(const double& fOutNumber, if (!pFormat) pFormat = GetFormatEntry(ZF_STANDARD); ChangeIntl(pFormat->GetLanguage()); - if ( bUseStarFormat ) - pFormat->SetStarFormatSupport( true ); - pFormat->GetOutputString(fOutNumber, sOutString, ppColor); - if ( bUseStarFormat ) - pFormat->SetStarFormatSupport( false ); + pFormat->GetOutputString(fOutNumber, sOutString, ppColor, bUseStarFormat); } bool SvNumberFormatter::GetPreviewString(const OUString& sFormatString, @@ -1833,15 +1821,7 @@ bool SvNumberFormatter::GetPreviewString(const OUString& sFormatString, } else { - if ( bUseStarFormat ) - { - aEntry.SetStarFormatSupport( true ); - } - aEntry.GetOutputString(fPreviewNumber, sOutString, ppColor); - if ( bUseStarFormat ) - { - aEntry.SetStarFormatSupport( false ); - } + aEntry.GetOutputString(fPreviewNumber, sOutString, ppColor, bUseStarFormat); } return true; } diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index 062f86fe4c59..5977294b0075 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -364,14 +364,13 @@ void SvNumberformat::ImpCopyNumberformat( const SvNumberformat& rFormat ) } SvNumberformat::SvNumberformat( SvNumberformat const & rFormat ) - : rScan(rFormat.rScan), bStarFlag( rFormat.bStarFlag ) + : rScan(rFormat.rScan) { ImpCopyNumberformat( rFormat ); } SvNumberformat::SvNumberformat( SvNumberformat const & rFormat, ImpSvNumberformatScan& rSc ) : rScan(rSc) - , bStarFlag( rFormat.bStarFlag ) { ImpCopyNumberformat( rFormat ); } @@ -757,7 +756,6 @@ SvNumberformat::SvNumberformat(OUString& rString, bool bReplaceBooleanEquivalent) : rScan(*pSc) , bAdditionalBuiltin( false ) - , bStarFlag( false ) { if (bReplaceBooleanEquivalent) rScan.ReplaceBooleanEquivalent( rString); @@ -2199,7 +2197,8 @@ static bool lcl_insertStarFillChar( OUStringBuffer& rBuf, sal_Int32 nPos, std::u void SvNumberformat::GetOutputString(std::u16string_view sString, OUString& OutString, - const Color** ppColor) + const Color** ppColor, + bool bStarFlag) { OUStringBuffer sOutBuff; sal_uInt16 nIx; @@ -2476,7 +2475,8 @@ sal_uInt16 SvNumberformat::GetSubformatIndex (double fNumber ) const bool SvNumberformat::GetOutputString(double fNumber, OUString& OutString, - const Color** ppColor) + const Color** ppColor, + bool bStarFlag) { bool bRes = false; OutString.clear(); @@ -2564,15 +2564,15 @@ bool SvNumberformat::GetOutputString(double fNumber, bHadStandard = true; break; case SvNumFormatType::DATE: - bRes |= ImpGetDateOutput(fNumber, 0, sBuff); + bRes |= ImpGetDateOutput(fNumber, 0, bStarFlag, sBuff); bHadStandard = true; break; case SvNumFormatType::TIME: - bRes |= ImpGetTimeOutput(fNumber, 0, sBuff); + bRes |= ImpGetTimeOutput(fNumber, 0, bStarFlag, sBuff); bHadStandard = true; break; case SvNumFormatType::DATETIME: - bRes |= ImpGetDateTimeOutput(fNumber, 0, sBuff); + bRes |= ImpGetDateTimeOutput(fNumber, 0, bStarFlag, sBuff); bHadStandard = true; break; default: break; @@ -2634,27 +2634,27 @@ bool SvNumberformat::GetOutputString(double fNumber, } break; case SvNumFormatType::DATE: - bRes |= ImpGetDateOutput(fNumber, nIx, sBuff); + bRes |= ImpGetDateOutput(fNumber, nIx, bStarFlag, sBuff); break; case SvNumFormatType::TIME: - bRes |= ImpGetTimeOutput(fNumber, nIx, sBuff); + bRes |= ImpGetTimeOutput(fNumber, nIx, bStarFlag, sBuff); break; case SvNumFormatType::DATETIME: - bRes |= ImpGetDateTimeOutput(fNumber, nIx, sBuff); + bRes |= ImpGetDateTimeOutput(fNumber, nIx, bStarFlag, sBuff); break; case SvNumFormatType::NUMBER: case SvNumFormatType::PERCENT: case SvNumFormatType::CURRENCY: - bRes |= ImpGetNumberOutput(fNumber, nIx, sBuff); + bRes |= ImpGetNumberOutput(fNumber, nIx, bStarFlag, sBuff); break; case SvNumFormatType::LOGICAL: bRes |= ImpGetLogicalOutput(fNumber, nIx, sBuff); break; case SvNumFormatType::FRACTION: - bRes |= ImpGetFractionOutput(fNumber, nIx, sBuff); + bRes |= ImpGetFractionOutput(fNumber, nIx, bStarFlag, sBuff); break; case SvNumFormatType::SCIENTIFIC: - bRes |= ImpGetScientificOutput(fNumber, nIx, sBuff); + bRes |= ImpGetScientificOutput(fNumber, nIx, bStarFlag, sBuff); break; default: break; } @@ -2665,6 +2665,7 @@ bool SvNumberformat::GetOutputString(double fNumber, bool SvNumberformat::ImpGetScientificOutput(double fNumber, sal_uInt16 nIx, + bool bStarFlag, OUStringBuffer& sStr) { bool bRes = false; @@ -2768,7 +2769,7 @@ bool SvNumberformat::ImpGetScientificOutput(double fNumber, } // restore leading zeros or blanks according to format '0' or '?' tdf#156449 - bRes |= ImpNumberFill(ExpStr, fNumber, k, j, nIx, NF_SYMBOLTYPE_EXP); + bRes |= ImpNumberFill(ExpStr, fNumber, k, j, nIx, NF_SYMBOLTYPE_EXP, bStarFlag); bool bCont = true; @@ -2800,7 +2801,7 @@ bool SvNumberformat::ImpGetScientificOutput(double fNumber, } else { - bRes |= ImpDecimalFill(sStr, fNumber, nDecPos, j, nIx, false); + bRes |= ImpDecimalFill(sStr, fNumber, nDecPos, j, nIx, false, bStarFlag); } if (bSign) @@ -2898,6 +2899,7 @@ void SvNumberformat::ImpGetFractionElements ( double& fNumber, sal_uInt16 nIx, bool SvNumberformat::ImpGetFractionOutput(double fNumber, sal_uInt16 nIx, + bool bStarFlag, OUStringBuffer& sBuff) { bool bRes = false; @@ -2964,7 +2966,7 @@ bool SvNumberformat::ImpGetFractionOutput(double fNumber, sal_uInt16 j = nCnt-1; // Last symbol -> backwards sal_Int32 k; // Denominator - bRes |= ImpNumberFill(sDiv, fNumber, k, j, nIx, NF_SYMBOLTYPE_FRAC, true); + bRes |= ImpNumberFill(sDiv, fNumber, k, j, nIx, NF_SYMBOLTYPE_FRAC, bStarFlag, true); bool bCont = true; if (rInfo.nTypeArray[j] == NF_SYMBOLTYPE_FRAC) @@ -2995,7 +2997,7 @@ bool SvNumberformat::ImpGetFractionOutput(double fNumber, } else { - bRes |= ImpNumberFill(sFrac, fNumber, k, j, nIx, NF_SYMBOLTYPE_FRACBLANK); + bRes |= ImpNumberFill(sFrac, fNumber, k, j, nIx, NF_SYMBOLTYPE_FRACBLANK, bStarFlag); bCont = false; // there is no integer part? if (rInfo.nTypeArray[j] == NF_SYMBOLTYPE_FRACBLANK) { @@ -3041,7 +3043,7 @@ bool SvNumberformat::ImpGetFractionOutput(double fNumber, { k = sStr.getLength(); // After last figure bRes |= ImpNumberFillWithThousands(sStr, fNumber, k, j, nIx, - rInfo.nCntPre); + rInfo.nCntPre, bStarFlag); } if (bSign && (nFrac != 0 || fNum != 0.0)) { @@ -3086,6 +3088,7 @@ sal_uInt16 SvNumberformat::ImpGetFractionOfSecondString( OUStringBuffer& rBuf, d bool SvNumberformat::ImpGetTimeOutput(double fNumber, sal_uInt16 nIx, + bool bStarFlag, OUStringBuffer& sBuff) { using namespace ::com::sun::star::i18n; @@ -3705,6 +3708,7 @@ static bool lcl_getValidDate( const DateTime& rNullDate, const DateTime& rEpochS bool SvNumberformat::ImpGetDateOutput(double fNumber, sal_uInt16 nIx, + bool bStarFlag, OUStringBuffer& sBuff) { using namespace ::com::sun::star::i18n; @@ -3975,6 +3979,7 @@ bool SvNumberformat::ImpGetDateOutput(double fNumber, bool SvNumberformat::ImpGetDateTimeOutput(double fNumber, sal_uInt16 nIx, + bool bStarFlag, OUStringBuffer& sBuff) { using namespace ::com::sun::star::i18n; @@ -4352,6 +4357,7 @@ bool SvNumberformat::ImpGetLogicalOutput(double fNumber, bool SvNumberformat::ImpGetNumberOutput(double fNumber, sal_uInt16 nIx, + bool bStarFlag, OUStringBuffer& sStr) const { bool bRes = false; @@ -4456,7 +4462,7 @@ bool SvNumberformat::ImpGetNumberOutput(double fNumber, // Edit backwards: j = NumFor[nIx].GetCount()-1; // Last symbol // Decimal places: - bRes |= ImpDecimalFill( sStr, fNumber, nDecPos, j, nIx, bInteger ); + bRes |= ImpDecimalFill( sStr, fNumber, nDecPos, j, nIx, bInteger, bStarFlag ); if (bSign) { sStr.insert(0, '-'); @@ -4470,7 +4476,8 @@ bool SvNumberformat::ImpDecimalFill( OUStringBuffer& sStr, // number string sal_Int32 nDecPos, // decimals start sal_uInt16 j, // symbol index within format code sal_uInt16 nIx, // subformat index - bool bInteger) const // is integer + bool bInteger, // is integer + bool bStarFlag) const { bool bRes = false; bool bFilled = false; // Was filled? @@ -4581,7 +4588,7 @@ bool SvNumberformat::ImpDecimalFill( OUStringBuffer& sStr, // number string } // of decimal places bRes |= ImpNumberFillWithThousands(sStr, rNumber, k, j, nIx, // Fill with . if needed - rInfo.nCntPre, bFilled ); + rInfo.nCntPre, bStarFlag, bFilled ); return bRes; } @@ -4592,6 +4599,7 @@ bool SvNumberformat::ImpNumberFillWithThousands( OUStringBuffer& sBuff, // numb sal_uInt16 j, // symbol index within format code sal_uInt16 nIx, // subformat index sal_Int32 nDigCnt, // count of integer digits in format + bool bStarFlag, // Take *n format as ESC n bool bAddDecSep) const // add decimal separator if necessary { bool bRes = false; @@ -4780,6 +4788,7 @@ bool SvNumberformat::ImpNumberFill( OUStringBuffer& sBuff, // number string sal_uInt16& j, // symbol index within format code sal_uInt16 nIx, // subformat index short eSymbolType, // type of stop condition + bool bStarFlag, // Take *n format as ESC n bool bInsertRightBlank)// insert blank on right for denominator (default = false) { bool bRes = false; |