summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-07-18 19:43:05 +0200
committerEike Rathke <erack@redhat.com>2017-07-18 19:43:35 +0200
commit038063a352f59bad1ecdeeb63016e37f6945a420 (patch)
treeb64769d58f9bc001dbf235f420038ba436344a33 /svl
parent71c3113e9dbf61693fd947262370cc61cdf31ac7 (diff)
Change nonsense non-const Date* GetNullDate() to const Date&
* first, a non-const Date* may leave the impression that one could change the NullDate through the pointer, which is only partly successful; luckily no one did that * second, there is always a NullDate so checking for nullptr is superfluous * third, the pointer was dereferenced (maybe after a check) everywhere to obtain the NullDate, luckily.. Change-Id: I3c3a788ba0336596ac6bde4c96e77a0cdb7a4a95
Diffstat (limited to 'svl')
-rw-r--r--svl/source/numbers/numfmuno.cxx7
-rw-r--r--svl/source/numbers/zforlist.cxx2
-rw-r--r--svl/source/numbers/zformat.cxx6
-rw-r--r--svl/source/numbers/zforscan.cxx17
-rw-r--r--svl/source/numbers/zforscan.hxx4
5 files changed, 18 insertions, 18 deletions
diff --git a/svl/source/numbers/numfmuno.cxx b/svl/source/numbers/numfmuno.cxx
index bef4075994e1..9c014f06ccac 100644
--- a/svl/source/numbers/numfmuno.cxx
+++ b/svl/source/numbers/numfmuno.cxx
@@ -927,11 +927,8 @@ uno::Any SAL_CALL SvNumberFormatSettingsObj::getPropertyValue( const OUString& a
}
else if (aPropertyName == PROPERTYNAME_NULLDATE)
{
- Date* pDate = pFormatter->GetNullDate();
- if (pDate)
- {
- aRet <<= pDate->GetUNODate();
- }
+ const Date& rDate = pFormatter->GetNullDate();
+ aRet <<= rDate.GetUNODate();
}
else if (aPropertyName == PROPERTYNAME_STDDEC)
aRet <<= (sal_Int16)( pFormatter->GetStandardPrec() );
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index 1acc79778e4a..2f3059ec4378 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -395,7 +395,7 @@ void SvNumberFormatter::ChangeNullDate(sal_uInt16 nDay,
pStringScanner->ChangeNullDate(nDay, nMonth, nYear);
}
-Date* SvNumberFormatter::GetNullDate()
+const Date& SvNumberFormatter::GetNullDate()
{
return pFormatScanner->GetNullDate();
}
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index a736c16518dc..224190550edd 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -2997,7 +2997,7 @@ bool SvNumberformat::ImpGetTimeOutput(double fNumber,
case NF_KEY_AMPM: // AM/PM
if ( !bCalendarSet )
{
- double fDiff = DateTime(*(rScan.GetNullDate())) - GetCal().getEpochStart();
+ double fDiff = DateTime(rScan.GetNullDate()) - GetCal().getEpochStart();
fDiff += fNumberOrig;
GetCal().setLocalDateTime( fDiff );
bCalendarSet = true;
@@ -3454,7 +3454,7 @@ bool SvNumberformat::ImpGetDateOutput(double fNumber,
bool bRes = false;
CalendarWrapper& rCal = GetCal();
- double fDiff = DateTime(*(rScan.GetNullDate())) - rCal.getEpochStart();
+ double fDiff = DateTime(rScan.GetNullDate()) - rCal.getEpochStart();
fNumber += fDiff;
rCal.setLocalDateTime( fNumber );
int nUseMonthCase = 0; // Not decided yet
@@ -3661,7 +3661,7 @@ bool SvNumberformat::ImpGetDateTimeOutput(double fNumber,
bool bRes = false;
CalendarWrapper& rCal = GetCal();
- double fDiff = DateTime(*(rScan.GetNullDate())) - rCal.getEpochStart();
+ double fDiff = DateTime(rScan.GetNullDate()) - rCal.getEpochStart();
fNumber += fDiff;
const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info();
diff --git a/svl/source/numbers/zforscan.cxx b/svl/source/numbers/zforscan.cxx
index 25014fa7e0f5..13c0362e873f 100644
--- a/svl/source/numbers/zforscan.cxx
+++ b/svl/source/numbers/zforscan.cxx
@@ -40,7 +40,8 @@ const sal_Unicode cNoBreakSpace = 0xA0;
const sal_Unicode cNarrowNoBreakSpace = 0x202F;
ImpSvNumberformatScan::ImpSvNumberformatScan( SvNumberFormatter* pFormatterP )
- : eNewLnge(LANGUAGE_DONTKNOW)
+ : maNullDate( 30, 12, 1899)
+ , eNewLnge(LANGUAGE_DONTKNOW)
, eTmpLnge(LANGUAGE_DONTKNOW)
, nCurrPos(-1)
{
@@ -77,7 +78,6 @@ ImpSvNumberformatScan::ImpSvNumberformatScan( SvNumberFormatter* pFormatterP )
StandardColor[8] = Color(COL_YELLOW);
StandardColor[9] = Color(COL_WHITE);
- pNullDate = new Date(30,12,1899);
nStandardPrec = 2;
sErrStr = "###";
@@ -86,7 +86,6 @@ ImpSvNumberformatScan::ImpSvNumberformatScan( SvNumberFormatter* pFormatterP )
ImpSvNumberformatScan::~ImpSvNumberformatScan()
{
- delete pNullDate;
Reset();
}
@@ -429,10 +428,14 @@ void ImpSvNumberformatScan::SetDependentKeywords()
void ImpSvNumberformatScan::ChangeNullDate(sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear)
{
- if ( pNullDate )
- *pNullDate = Date(nDay, nMonth, nYear);
- else
- pNullDate = new Date(nDay, nMonth, nYear);
+ maNullDate = Date(nDay, nMonth, nYear);
+ if (!maNullDate.IsValidDate())
+ {
+ maNullDate.Normalize();
+ SAL_WARN("svl.numbers","ImpSvNumberformatScan::ChangeNullDate - not valid"
+ " d: " << nDay << " m: " << nMonth << " y: " << nYear << " normalized to"
+ " d: " << maNullDate.GetDay() << " m: " << maNullDate.GetMonth() << " y: " << maNullDate.GetYear());
+ }
}
void ImpSvNumberformatScan::ChangeStandardPrec(sal_uInt16 nPrec)
diff --git a/svl/source/numbers/zforscan.hxx b/svl/source/numbers/zforscan.hxx
index 13d5b1a67177..5aaee72f870f 100644
--- a/svl/source/numbers/zforscan.hxx
+++ b/svl/source/numbers/zforscan.hxx
@@ -80,7 +80,7 @@ public:
const OUString& GetBooleanString() const { return GetKeywords()[NF_KEY_BOOLEAN]; }
const OUString& GetErrorString() const { return sErrStr; }
- Date* GetNullDate() const { return pNullDate; }
+ const Date& GetNullDate() const { return maNullDate; }
const OUString& GetStandardName() const
{
if ( bKeywordsNeedInit )
@@ -150,7 +150,7 @@ public:
private: // Private section
NfKeywordTable sKeyword; // Syntax keywords
Color StandardColor[NF_MAX_DEFAULT_COLORS]; // Standard color array
- Date* pNullDate; // 30Dec1899
+ Date maNullDate; // 30Dec1899
OUString sNameStandardFormat; // "Standard"
sal_uInt16 nStandardPrec; // Default Precision for Standardformat
SvNumberFormatter* pFormatter; // Pointer to the FormatList