summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Nitschke <j.nitschke+logerrit@ok.de>2017-03-10 12:26:35 +0100
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-03-11 05:07:42 +0000
commitc328aefa6f2c9a04c50bad7228a468ff2f136d22 (patch)
tree6cfabf684d7004e0e50ddec799dde4d55bbb4fb0
parentfba66b325c493567126b23d481d75ee00dc9c30d (diff)
replace macros and use scoped enum
use OUStringLiteral to store format names. just create ResMgr, no need to check if its gone. Change-Id: Ie3e33bc70b975d8ee49f47dcf23737ca56652f1a Reviewed-on: https://gerrit.libreoffice.org/35007 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--basic/source/sbx/sbxscan.cxx81
1 files changed, 38 insertions, 43 deletions
diff --git a/basic/source/sbx/sbxscan.cxx b/basic/source/sbx/sbxscan.cxx
index d06f4e0073fa..3a7c4caf3c0a 100644
--- a/basic/source/sbx/sbxscan.cxx
+++ b/basic/source/sbx/sbxscan.cxx
@@ -581,74 +581,69 @@ bool SbxValue::Scan( const OUString& rSrc, sal_uInt16* pLen )
}
-ResMgr* implGetResMgr()
+namespace
{
- static ResMgr* pResMgr = nullptr;
- if( !pResMgr )
- {
- pResMgr = ResMgr::CreateResMgr("sb", Application::GetSettings().GetUILanguageTag() );
- }
- return pResMgr;
+
+ResMgr& implGetResMgr()
+{
+ static ResMgr* const pResMgr( ResMgr::CreateResMgr(
+ "sb", Application::GetSettings().GetUILanguageTag() ));
+
+ return *pResMgr;
}
class SbxValueFormatResId : public ResId
{
public:
- explicit SbxValueFormatResId( sal_uInt16 nId )
- : ResId( nId, *implGetResMgr() )
+ explicit SbxValueFormatResId( sal_uInt32 nId )
+ : ResId( nId, implGetResMgr() )
{}
};
-
-enum VbaFormatType
+enum class VbaFormatType
{
- VBA_FORMAT_TYPE_OFFSET, // standard number format
- VBA_FORMAT_TYPE_USERDEFINED, // user defined number format
- VBA_FORMAT_TYPE_NULL
+ Offset, // standard number format
+ UserDefined, // user defined number format
+ Null
};
struct VbaFormatInfo
{
VbaFormatType meType;
- OUString mpVbaFormat; // Format string in vba
- NfIndexTableOffset meOffset; // SvNumberFormatter format index, if meType = VBA_FORMAT_TYPE_OFFSET
- const char* mpOOoFormat; // if meType = VBA_FORMAT_TYPE_USERDEFINED
+ OUStringLiteral mpVbaFormat; // Format string in vba
+ NfIndexTableOffset meOffset; // SvNumberFormatter format index, if meType = VbaFormatType::Offset
+ const char* mpOOoFormat; // if meType = VbaFormatType::UserDefined
};
-#define VBA_FORMAT_OFFSET( pcUtf8, eOffset ) \
- { VBA_FORMAT_TYPE_OFFSET, OUString(pcUtf8), eOffset, nullptr }
-
-#define VBA_FORMAT_USERDEFINED( pcUtf8, pcDefinedUtf8 ) \
- { VBA_FORMAT_TYPE_USERDEFINED, OUString(pcUtf8), NF_NUMBER_STANDARD, pcDefinedUtf8 }
-
-static VbaFormatInfo pFormatInfoTable[] =
+const VbaFormatInfo pFormatInfoTable[] =
{
- VBA_FORMAT_OFFSET( "Long Date", NF_DATE_SYSTEM_LONG ),
- VBA_FORMAT_USERDEFINED( "Medium Date", "DD-MMM-YY" ),
- VBA_FORMAT_OFFSET( "Short Date", NF_DATE_SYSTEM_SHORT ),
- VBA_FORMAT_USERDEFINED( "Long Time", "H:MM:SS AM/PM" ),
- VBA_FORMAT_OFFSET( "Medium Time", NF_TIME_HHMMAMPM ),
- VBA_FORMAT_OFFSET( "Short Time", NF_TIME_HHMM ),
- VBA_FORMAT_OFFSET( "ddddd", NF_DATE_SYSTEM_SHORT ),
- VBA_FORMAT_OFFSET( "dddddd", NF_DATE_SYSTEM_LONG ),
- VBA_FORMAT_USERDEFINED( "ttttt", "H:MM:SS AM/PM" ),
- VBA_FORMAT_OFFSET( "ww", NF_DATE_WW ),
- { VBA_FORMAT_TYPE_NULL, OUString(""), NF_INDEX_TABLE_ENTRIES, nullptr }
+ { VbaFormatType::Offset, OUStringLiteral("Long Date"), NF_DATE_SYSTEM_LONG, nullptr },
+ { VbaFormatType::UserDefined, OUStringLiteral("Medium Date"), NF_NUMBER_STANDARD, "DD-MMM-YY" },
+ { VbaFormatType::Offset, OUStringLiteral("Short Date"), NF_DATE_SYSTEM_SHORT, nullptr },
+ { VbaFormatType::UserDefined, OUStringLiteral("Long Time"), NF_NUMBER_STANDARD, "H:MM:SS AM/PM" },
+ { VbaFormatType::Offset, OUStringLiteral("Medium Time"), NF_TIME_HHMMAMPM, nullptr },
+ { VbaFormatType::Offset, OUStringLiteral("Short Time"), NF_TIME_HHMM, nullptr },
+ { VbaFormatType::Offset, OUStringLiteral("ddddd"), NF_DATE_SYSTEM_SHORT, nullptr },
+ { VbaFormatType::Offset, OUStringLiteral("dddddd"), NF_DATE_SYSTEM_LONG, nullptr },
+ { VbaFormatType::UserDefined, OUStringLiteral("ttttt"), NF_NUMBER_STANDARD, "H:MM:SS AM/PM" },
+ { VbaFormatType::Offset, OUStringLiteral("ww"), NF_DATE_WW, nullptr },
+ { VbaFormatType::Null, OUStringLiteral(""), NF_INDEX_TABLE_ENTRIES, nullptr }
};
-VbaFormatInfo* getFormatInfo( const OUString& rFmt )
+const VbaFormatInfo* getFormatInfo( const OUString& rFmt )
{
- VbaFormatInfo* pInfo = nullptr;
- sal_Int16 i = 0;
- while( (pInfo = pFormatInfoTable + i )->meType != VBA_FORMAT_TYPE_NULL )
+ const VbaFormatInfo* pInfo = pFormatInfoTable;
+ while( pInfo->meType != VbaFormatType::Null )
{
if( rFmt.equalsIgnoreAsciiCase( pInfo->mpVbaFormat ) )
break;
- i++;
+ ++pInfo;
}
return pInfo;
}
+} // namespace
+
#define VBAFORMAT_GENERALDATE "General Date"
#define VBAFORMAT_C "c"
#define VBAFORMAT_N "n"
@@ -699,10 +694,10 @@ void SbxValue::Format( OUString& rRes, const OUString* pFmt ) const
sal_Int32 nCheckPos = 0;
short nType;
OUString aFmtStr = *pFmt;
- VbaFormatInfo* pInfo = getFormatInfo( aFmtStr );
- if( pInfo && pInfo->meType != VBA_FORMAT_TYPE_NULL )
+ const VbaFormatInfo* pInfo = getFormatInfo( aFmtStr );
+ if( pInfo->meType != VbaFormatType::Null )
{
- if( pInfo->meType == VBA_FORMAT_TYPE_OFFSET )
+ if( pInfo->meType == VbaFormatType::Offset )
{
nIndex = aFormatter.GetFormatIndex( pInfo->meOffset, eLangType );
}