Kaydet (Commit) f7f4d985 authored tarafından Eike Rathke's avatar Eike Rathke

Resolves: tdf#92457 handle trailing text subformat if others omitted

Change-Id: I597a5019540cef4700355df4d170c103e973797e
üst 12d1a2a0
...@@ -277,6 +277,12 @@ public: ...@@ -277,6 +277,12 @@ public:
return false; return false;
} }
/** Get the scanned type of the specified subformat. */
short GetNumForInfoScannedType( sal_uInt16 nNumFor ) const
{
return (nNumFor < 4) ? NumFor[nNumFor].Info().eScannedType : css::util::NumberFormat::UNDEFINED;
}
// Whether the second subformat code is really for negative numbers // Whether the second subformat code is really for negative numbers
// or another limit set. // or another limit set.
bool IsSecondSubformatRealNegative() const bool IsSecondSubformatRealNegative() const
......
...@@ -3222,7 +3222,16 @@ bool ImpSvNumberInputScan::IsNumberFormatMain( const OUString& rString, / ...@@ -3222,7 +3222,16 @@ bool ImpSvNumberInputScan::IsNumberFormatMain( const OUString& rString, /
} }
if ( nMatchedAllStrings ) if ( nMatchedAllStrings )
{ {
eScannedType = eSetType; // A type DEFINED means that no category could be assigned to the
// overall format because of mixed type subformats. Use the scan
// matched subformat's type if any.
short eForType = eSetType;
if ((eForType == css::util::NumberFormat::UNDEFINED || eForType == css::util::NumberFormat::DEFINED) && pFormat)
eForType = pFormat->GetNumForInfoScannedType( nStringScanNumFor);
if (eForType != css::util::NumberFormat::UNDEFINED && eForType != css::util::NumberFormat::DEFINED)
eScannedType = eForType;
else
eScannedType = css::util::NumberFormat::NUMBER;
} }
else if ( bDidMatch ) else if ( bDidMatch )
{ {
...@@ -3250,7 +3259,15 @@ bool ImpSvNumberInputScan::IsNumberFormatMain( const OUString& rString, / ...@@ -3250,7 +3259,15 @@ bool ImpSvNumberInputScan::IsNumberFormatMain( const OUString& rString, /
} }
if ( nMatchedAllStrings ) if ( nMatchedAllStrings )
{ {
eScannedType = eSetType; // A type DEFINED means that no category could be assigned to the
// overall format because of mixed type subformats. Do not override
// the scanned type in this case. Otherwise in IsNumberFormat() the
// first numeric particle would be accepted as number.
short eForType = eSetType;
if ((eForType == css::util::NumberFormat::UNDEFINED || eForType == css::util::NumberFormat::DEFINED) && pFormat)
eForType = pFormat->GetNumForInfoScannedType( nStringScanNumFor);
if (eForType != css::util::NumberFormat::UNDEFINED && eForType != css::util::NumberFormat::DEFINED)
eScannedType = eForType;
} }
else if ( bWasReturn ) else if ( bWasReturn )
{ {
......
...@@ -1322,7 +1322,11 @@ void SvNumberFormatter::GetInputLineString(const double& fOutNumber, ...@@ -1322,7 +1322,11 @@ void SvNumberFormatter::GetInputLineString(const double& fOutNumber,
short eType = pFormat->GetType() & ~css::util::NumberFormat::DEFINED; short eType = pFormat->GetType() & ~css::util::NumberFormat::DEFINED;
if (eType == 0) if (eType == 0)
{ {
eType = css::util::NumberFormat::DEFINED; // Mixed types in subformats, use first.
/* XXX we could choose a subformat according to fOutNumber and
* subformat conditions, but they may exist to suppress 0 or negative
* numbers so wouldn't be a safe bet. */
eType = pFormat->GetNumForInfoScannedType(0);
} }
sal_uInt16 nOldPrec = pFormatScanner->GetStandardPrec(); sal_uInt16 nOldPrec = pFormatScanner->GetStandardPrec();
......
...@@ -943,6 +943,22 @@ SvNumberformat::SvNumberformat(OUString& rString, ...@@ -943,6 +943,22 @@ SvNumberformat::SvNumberformat(OUString& rString,
sBuff.insert(nPos, ";"); sBuff.insert(nPos, ";");
nPos++; nPos++;
} }
else
{
// The last subformat. If it is a trailing text
// format the omitted subformats act like they were
// not specified and "inherited" the first format,
// e.g. 0;@ behaves like 0;-0;0;@
if (pSc->GetScannedType() == css::util::NumberFormat::TEXT)
{
// Reset conditions, reverting any set above.
if (nIndex == 1)
eOp1 = NUMBERFORMAT_OP_NO;
else if (nIndex == 2)
eOp2 = NUMBERFORMAT_OP_NO;
nIndex = 3;
}
}
NumFor[nIndex].Enlarge(nAnz); NumFor[nIndex].Enlarge(nAnz);
pSc->CopyInfo(&(NumFor[nIndex].Info()), nAnz); pSc->CopyInfo(&(NumFor[nIndex].Info()), nAnz);
// type check // type check
......
...@@ -144,6 +144,9 @@ public: ...@@ -144,6 +144,9 @@ public:
SvNumberFormatter* GetNumberformatter() { return pFormatter; } // Access to formatter (for zformat.cxx) SvNumberFormatter* GetNumberformatter() { return pFormatter; } // Access to formatter (for zformat.cxx)
/// Get type scanned (so far).
short GetScannedType() const { return eScannedType; }
private: // Private section private: // Private section
NfKeywordTable sKeyword; // Syntax keywords NfKeywordTable sKeyword; // Syntax keywords
Color StandardColor[NF_MAX_DEFAULT_COLORS]; // Standard color array Color StandardColor[NF_MAX_DEFAULT_COLORS]; // Standard color array
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment