From ec326f42c6390a241a5d0535611b68326885e8dd Mon Sep 17 00:00:00 2001 From: Bjoern Michaelsen Date: Sat, 28 Nov 2015 01:34:35 +0100 Subject: use constexprs and static_assert() Change-Id: Ia7abeed325d8bc845e35bb9e7667cec6b83ac11f --- sw/source/core/unocore/unostyle.cxx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index bdc6f822730c..49b4267bfffb 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -482,17 +482,17 @@ uno::Any SwXStyleFamily::getByIndex(sal_Int32 nIndex) if(!m_pBasePool) throw uno::RuntimeException(); OUString sStyleName; - switch( m_eFamily ) + switch(m_eFamily) { case SFX_STYLE_FAMILY_CHAR: { - if ( nIndex < ( RES_POOLCHR_NORMAL_END - RES_POOLCHR_NORMAL_BEGIN ) ) - SwStyleNameMapper::FillUIName ( static_cast< sal_uInt16 >(RES_POOLCHR_NORMAL_BEGIN + nIndex), sStyleName ); - else if ( nIndex < ( RES_POOLCHR_HTML_END - RES_POOLCHR_HTML_BEGIN + - RES_POOLCHR_NORMAL_END - RES_POOLCHR_NORMAL_BEGIN ) ) - SwStyleNameMapper::FillUIName ( RES_POOLCHR_HTML_BEGIN - - RES_POOLCHR_NORMAL_END + RES_POOLCHR_NORMAL_BEGIN - + nIndex, sStyleName ); + constexpr sal_Int32 nPoolChrNormalRange = RES_POOLCHR_NORMAL_END - RES_POOLCHR_NORMAL_BEGIN; + constexpr sal_Int32 nPoolChrHtmlRange = RES_POOLCHR_HTML_END - RES_POOLCHR_HTML_BEGIN; + static_assert(nPoolChrNormalRange > 0 && nPoolChrHtmlRange > 0, "invalid pool range"); + if(nIndex < nPoolChrNormalRange) + SwStyleNameMapper::FillUIName(static_cast(RES_POOLCHR_NORMAL_BEGIN + nIndex), sStyleName); + else if(nIndex < (nPoolChrHtmlRange+nPoolChrNormalRange)) + SwStyleNameMapper::FillUIName(RES_POOLCHR_HTML_BEGIN + nPoolChrNormalRange + nIndex, sStyleName ); } break; case SFX_STYLE_FAMILY_PARA: -- cgit