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:
Noel Grandin 2019-01-07 08:25:56 +02:00
parent 05f12ce00f
commit c4331c0b6a
4 changed files with 13 additions and 14 deletions

View file

@ -101,8 +101,8 @@ public:
static OUString convertToFileUrl(const OString& fileName);
static OUString DateTimeToOUString(const LtTm& dt);
static XFDateStyle* GetSystemDateStyle(bool bLongFormat);
static XFTimeStyle* GetSystemTimeStyle();
static std::unique_ptr<XFDateStyle> GetSystemDateStyle(bool bLongFormat);
static std::unique_ptr<XFTimeStyle> GetSystemTimeStyle();
};
inline double LwpTools::ConvertFromUnits(sal_Int32 nUnits)

View file

@ -56,6 +56,7 @@
#include <localtime.hxx>
#include <limits.h>
#include <unicode/timezone.h>
#include <memory>
const long DAY_SEC =24 * 60 * 60;
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))
{
icu::TimeZone* pLocalZone = icu::TimeZone::createDefault();
std::unique_ptr<icu::TimeZone> pLocalZone(icu::TimeZone::createDefault());
long offset = (pLocalZone->getRawOffset())/1000;
delete pLocalZone;
pLocalZone.reset();
long ltime = rtime + offset;
return LtgGmTime(ltime,rtm);
}

View file

@ -398,11 +398,11 @@ void LwpFribField::RegisterDateTimeStyle(const OUString& sFormula)
{
if (sFormula == "%FLSystemShortDate")
{
pDateStyle.reset( LwpTools::GetSystemDateStyle(false) );
pDateStyle = LwpTools::GetSystemDateStyle(false);
}
else if (sFormula == "%FLSystemLongDate")
{
pDateStyle.reset( LwpTools::GetSystemDateStyle(true) );
pDateStyle = LwpTools::GetSystemDateStyle(true);
}
else if (sFormula == "%FLISODate1" || sFormula == "%FLYYYY/MM/DD" )
{
@ -868,7 +868,7 @@ void LwpFribField::RegisterDateTimeStyle(const OUString& sFormula)
//TIME
else if (sFormula == "%FLSystemTime")
{
pTimeStyle.reset(LwpTools::GetSystemTimeStyle());
pTimeStyle = LwpTools::GetSystemTimeStyle();
}
else if (sFormula == "%FLISOTime1" || sFormula == "%FLH:mm:SS")
{
@ -1018,7 +1018,7 @@ void LwpFribField::RegisterDateTimeStyle(const OUString& sFormula)
{
if (sFormula == "%Da")
{
pDateStyle.reset(LwpTools::GetSystemDateStyle(false));
pDateStyle = LwpTools::GetSystemDateStyle(false);
}
else if (sFormula == "%DB" || sFormula == "%Db")
{

View file

@ -233,7 +233,7 @@ OUString LwpTools::DateTimeToOUString(const LtTm &dt)
/**
* @descr get the system date format
*/
XFDateStyle* LwpTools::GetSystemDateStyle(bool bLongFormat)
std::unique_ptr<XFDateStyle> LwpTools::GetSystemDateStyle(bool bLongFormat)
{
icu::DateFormat::EStyle style;
if (bLongFormat)
@ -268,7 +268,7 @@ XFDateStyle* LwpTools::GetSystemDateStyle(bool bLongFormat)
// we parse pattern string letter by letter and get the time format.
UChar cSymbol;
UChar cTmp;
XFDateStyle* pDateStyle = new XFDateStyle;
std::unique_ptr<XFDateStyle> pDateStyle(new XFDateStyle);
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') )
{
delete pDateStyle;
return nullptr;
}
else//TEXT
@ -628,7 +627,7 @@ XFDateStyle* LwpTools::GetSystemDateStyle(bool bLongFormat)
/**
* @descr get the system time format
*/
XFTimeStyle* LwpTools::GetSystemTimeStyle()
std::unique_ptr<XFTimeStyle> LwpTools::GetSystemTimeStyle()
{
//1 get locale for system
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.
UChar cSymbol;
UChar cTmp;
XFTimeStyle* pTimeStyle = new XFTimeStyle;
std::unique_ptr<XFTimeStyle> pTimeStyle(new XFTimeStyle);
for (int32_t i=0;i<nLengthNeed;)
{
@ -817,7 +816,6 @@ XFTimeStyle* LwpTools::GetSystemTimeStyle()
{
if ((cSymbol>='A' && cSymbol<='Z') || (cSymbol>='a' && cSymbol<='z') )
{
delete pTimeStyle;
return nullptr;
}
else//TEXT