diff options
Diffstat (limited to 'basic')
-rw-r--r-- | basic/source/sbx/sbxscan.cxx | 81 |
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 ); } |