use unique_ptr in LwpTools::GetSystemDateStyle
Change-Id: I6ea90be5736982422aaa45c7147beec1cfd5430b Reviewed-on: https://gerrit.libreoffice.org/65918 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
@@ -101,8 +101,8 @@ public:
|
|||||||
static OUString convertToFileUrl(const OString& fileName);
|
static OUString convertToFileUrl(const OString& fileName);
|
||||||
static OUString DateTimeToOUString(const LtTm& dt);
|
static OUString DateTimeToOUString(const LtTm& dt);
|
||||||
|
|
||||||
static XFDateStyle* GetSystemDateStyle(bool bLongFormat);
|
static std::unique_ptr<XFDateStyle> GetSystemDateStyle(bool bLongFormat);
|
||||||
static XFTimeStyle* GetSystemTimeStyle();
|
static std::unique_ptr<XFTimeStyle> GetSystemTimeStyle();
|
||||||
};
|
};
|
||||||
|
|
||||||
inline double LwpTools::ConvertFromUnits(sal_Int32 nUnits)
|
inline double LwpTools::ConvertFromUnits(sal_Int32 nUnits)
|
||||||
|
@@ -56,6 +56,7 @@
|
|||||||
#include <localtime.hxx>
|
#include <localtime.hxx>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <unicode/timezone.h>
|
#include <unicode/timezone.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
const long DAY_SEC =24 * 60 * 60;
|
const long DAY_SEC =24 * 60 * 60;
|
||||||
const long YEAR_SEC = 365 * DAY_SEC;
|
const long YEAR_SEC = 365 * DAY_SEC;
|
||||||
@@ -174,9 +175,9 @@ bool LtgLocalTime(long rtime,LtTm& rtm)
|
|||||||
|
|
||||||
if ((rtime > 3 * DAY_SEC)&&(rtime < LONG_MAX - 3 * DAY_SEC))
|
if ((rtime > 3 * DAY_SEC)&&(rtime < LONG_MAX - 3 * DAY_SEC))
|
||||||
{
|
{
|
||||||
icu::TimeZone* pLocalZone = icu::TimeZone::createDefault();
|
std::unique_ptr<icu::TimeZone> pLocalZone(icu::TimeZone::createDefault());
|
||||||
long offset = (pLocalZone->getRawOffset())/1000;
|
long offset = (pLocalZone->getRawOffset())/1000;
|
||||||
delete pLocalZone;
|
pLocalZone.reset();
|
||||||
long ltime = rtime + offset;
|
long ltime = rtime + offset;
|
||||||
return LtgGmTime(ltime,rtm);
|
return LtgGmTime(ltime,rtm);
|
||||||
}
|
}
|
||||||
|
@@ -398,11 +398,11 @@ void LwpFribField::RegisterDateTimeStyle(const OUString& sFormula)
|
|||||||
{
|
{
|
||||||
if (sFormula == "%FLSystemShortDate")
|
if (sFormula == "%FLSystemShortDate")
|
||||||
{
|
{
|
||||||
pDateStyle.reset( LwpTools::GetSystemDateStyle(false) );
|
pDateStyle = LwpTools::GetSystemDateStyle(false);
|
||||||
}
|
}
|
||||||
else if (sFormula == "%FLSystemLongDate")
|
else if (sFormula == "%FLSystemLongDate")
|
||||||
{
|
{
|
||||||
pDateStyle.reset( LwpTools::GetSystemDateStyle(true) );
|
pDateStyle = LwpTools::GetSystemDateStyle(true);
|
||||||
}
|
}
|
||||||
else if (sFormula == "%FLISODate1" || sFormula == "%FLYYYY/MM/DD" )
|
else if (sFormula == "%FLISODate1" || sFormula == "%FLYYYY/MM/DD" )
|
||||||
{
|
{
|
||||||
@@ -868,7 +868,7 @@ void LwpFribField::RegisterDateTimeStyle(const OUString& sFormula)
|
|||||||
//TIME
|
//TIME
|
||||||
else if (sFormula == "%FLSystemTime")
|
else if (sFormula == "%FLSystemTime")
|
||||||
{
|
{
|
||||||
pTimeStyle.reset(LwpTools::GetSystemTimeStyle());
|
pTimeStyle = LwpTools::GetSystemTimeStyle();
|
||||||
}
|
}
|
||||||
else if (sFormula == "%FLISOTime1" || sFormula == "%FLH:mm:SS")
|
else if (sFormula == "%FLISOTime1" || sFormula == "%FLH:mm:SS")
|
||||||
{
|
{
|
||||||
@@ -1018,7 +1018,7 @@ void LwpFribField::RegisterDateTimeStyle(const OUString& sFormula)
|
|||||||
{
|
{
|
||||||
if (sFormula == "%Da")
|
if (sFormula == "%Da")
|
||||||
{
|
{
|
||||||
pDateStyle.reset(LwpTools::GetSystemDateStyle(false));
|
pDateStyle = LwpTools::GetSystemDateStyle(false);
|
||||||
}
|
}
|
||||||
else if (sFormula == "%DB" || sFormula == "%Db")
|
else if (sFormula == "%DB" || sFormula == "%Db")
|
||||||
{
|
{
|
||||||
|
@@ -233,7 +233,7 @@ OUString LwpTools::DateTimeToOUString(const LtTm &dt)
|
|||||||
/**
|
/**
|
||||||
* @descr get the system date format
|
* @descr get the system date format
|
||||||
*/
|
*/
|
||||||
XFDateStyle* LwpTools::GetSystemDateStyle(bool bLongFormat)
|
std::unique_ptr<XFDateStyle> LwpTools::GetSystemDateStyle(bool bLongFormat)
|
||||||
{
|
{
|
||||||
icu::DateFormat::EStyle style;
|
icu::DateFormat::EStyle style;
|
||||||
if (bLongFormat)
|
if (bLongFormat)
|
||||||
@@ -268,7 +268,7 @@ XFDateStyle* LwpTools::GetSystemDateStyle(bool bLongFormat)
|
|||||||
// we parse pattern string letter by letter and get the time format.
|
// we parse pattern string letter by letter and get the time format.
|
||||||
UChar cSymbol;
|
UChar cSymbol;
|
||||||
UChar cTmp;
|
UChar cTmp;
|
||||||
XFDateStyle* pDateStyle = new XFDateStyle;
|
std::unique_ptr<XFDateStyle> pDateStyle(new XFDateStyle);
|
||||||
|
|
||||||
for (int32_t i=0;i<nLengthNeed;)
|
for (int32_t i=0;i<nLengthNeed;)
|
||||||
{
|
{
|
||||||
@@ -594,7 +594,6 @@ XFDateStyle* LwpTools::GetSystemDateStyle(bool bLongFormat)
|
|||||||
{
|
{
|
||||||
if ((cSymbol>='A' && cSymbol<='Z') || (cSymbol>='a' && cSymbol<='z') )
|
if ((cSymbol>='A' && cSymbol<='Z') || (cSymbol>='a' && cSymbol<='z') )
|
||||||
{
|
{
|
||||||
delete pDateStyle;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
else//TEXT
|
else//TEXT
|
||||||
@@ -628,7 +627,7 @@ XFDateStyle* LwpTools::GetSystemDateStyle(bool bLongFormat)
|
|||||||
/**
|
/**
|
||||||
* @descr get the system time format
|
* @descr get the system time format
|
||||||
*/
|
*/
|
||||||
XFTimeStyle* LwpTools::GetSystemTimeStyle()
|
std::unique_ptr<XFTimeStyle> LwpTools::GetSystemTimeStyle()
|
||||||
{
|
{
|
||||||
//1 get locale for system
|
//1 get locale for system
|
||||||
icu::Locale aLocale( LanguageTagIcu::getIcuLocale( Application::GetSettings().GetLanguageTag()));
|
icu::Locale aLocale( LanguageTagIcu::getIcuLocale( Application::GetSettings().GetLanguageTag()));
|
||||||
@@ -658,7 +657,7 @@ XFTimeStyle* LwpTools::GetSystemTimeStyle()
|
|||||||
// for time format ,for there is not date info,we can only parse the letter representing time.
|
// for time format ,for there is not date info,we can only parse the letter representing time.
|
||||||
UChar cSymbol;
|
UChar cSymbol;
|
||||||
UChar cTmp;
|
UChar cTmp;
|
||||||
XFTimeStyle* pTimeStyle = new XFTimeStyle;
|
std::unique_ptr<XFTimeStyle> pTimeStyle(new XFTimeStyle);
|
||||||
|
|
||||||
for (int32_t i=0;i<nLengthNeed;)
|
for (int32_t i=0;i<nLengthNeed;)
|
||||||
{
|
{
|
||||||
@@ -817,7 +816,6 @@ XFTimeStyle* LwpTools::GetSystemTimeStyle()
|
|||||||
{
|
{
|
||||||
if ((cSymbol>='A' && cSymbol<='Z') || (cSymbol>='a' && cSymbol<='z') )
|
if ((cSymbol>='A' && cSymbol<='Z') || (cSymbol>='a' && cSymbol<='z') )
|
||||||
{
|
{
|
||||||
delete pTimeStyle;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
else//TEXT
|
else//TEXT
|
||||||
|
Reference in New Issue
Block a user