summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2015-07-10 15:07:59 +0200
committerEike Rathke <erack@redhat.com>2015-07-10 15:11:32 +0200
commitf7f4d985ad44ba0c644b2be02d09002b13d749f7 (patch)
treead29b7c4d1760bf2a2f65be0c188265244776090
parent12d1a2a08a8056df2c14ad3e75b309847989bc23 (diff)
Resolves: tdf#92457 handle trailing text subformat if others omitted
Change-Id: I597a5019540cef4700355df4d170c103e973797e
-rw-r--r--include/svl/zformat.hxx6
-rw-r--r--svl/source/numbers/zforfind.cxx21
-rw-r--r--svl/source/numbers/zforlist.cxx6
-rw-r--r--svl/source/numbers/zformat.cxx16
-rw-r--r--svl/source/numbers/zforscan.hxx3
5 files changed, 49 insertions, 3 deletions
diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx
index 21c106ce9bfe..2858563ee4ef 100644
--- a/include/svl/zformat.hxx
+++ b/include/svl/zformat.hxx
@@ -277,6 +277,12 @@ public:
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
// or another limit set.
bool IsSecondSubformatRealNegative() const
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