diff options
Diffstat (limited to 'svl')
-rw-r--r-- | svl/source/numbers/zforfind.cxx | 21 | ||||
-rw-r--r-- | svl/source/numbers/zforlist.cxx | 6 | ||||
-rw-r--r-- | svl/source/numbers/zformat.cxx | 16 | ||||
-rw-r--r-- | svl/source/numbers/zforscan.hxx | 3 |
4 files changed, 43 insertions, 3 deletions
diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx index f0b08b5a903d..77832ea3024a 100644 --- a/svl/source/numbers/zforfind.cxx +++ b/svl/source/numbers/zforfind.cxx @@ -3222,7 +3222,16 @@ bool ImpSvNumberInputScan::IsNumberFormatMain( const OUString& rString, / } 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 ) { @@ -3250,7 +3259,15 @@ bool ImpSvNumberInputScan::IsNumberFormatMain( const OUString& rString, / } 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 ) { diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index 19c5d95fa436..afca600bb927 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -1322,7 +1322,11 @@ void SvNumberFormatter::GetInputLineString(const double& fOutNumber, short eType = pFormat->GetType() & ~css::util::NumberFormat::DEFINED; 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(); diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index ec65c7ceee19..e7501ffb15e7 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -943,6 +943,22 @@ SvNumberformat::SvNumberformat(OUString& rString, sBuff.insert(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); pSc->CopyInfo(&(NumFor[nIndex].Info()), nAnz); // type check diff --git a/svl/source/numbers/zforscan.hxx b/svl/source/numbers/zforscan.hxx index c5933200013a..54eec03c69ac 100644 --- a/svl/source/numbers/zforscan.hxx +++ b/svl/source/numbers/zforscan.hxx @@ -144,6 +144,9 @@ public: SvNumberFormatter* GetNumberformatter() { return pFormatter; } // Access to formatter (for zformat.cxx) + /// Get type scanned (so far). + short GetScannedType() const { return eScannedType; } + private: // Private section NfKeywordTable sKeyword; // Syntax keywords Color StandardColor[NF_MAX_DEFAULT_COLORS]; // Standard color array |