From 57f1934bdaa747f6e671419aa040e140d235f937 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 21 Apr 2017 14:31:00 +0200 Subject: convert HTML_TOKEN_IDS to scoped enum Change-Id: I525506e0103e4f17e5b8b95f15c1285d65b93de9 Reviewed-on: https://gerrit.libreoffice.org/37220 Tested-by: Jenkins Reviewed-by: Noel Grandin --- svtools/source/svrtf/parrtf.cxx | 2 +- svtools/source/svrtf/svparser.cxx | 109 ++++++++++++++++++++++++++++---------- 2 files changed, 81 insertions(+), 30 deletions(-) (limited to 'svtools/source/svrtf') diff --git a/svtools/source/svrtf/parrtf.cxx b/svtools/source/svrtf/parrtf.cxx index 625288c1277e..17921cdaf718 100644 --- a/svtools/source/svrtf/parrtf.cxx +++ b/svtools/source/svrtf/parrtf.cxx @@ -36,7 +36,7 @@ const int MAX_TOKEN_LEN = 128; #define RTF_ISALPHA( c ) rtl::isAsciiAlpha(c) SvRTFParser::SvRTFParser( SvStream& rIn, sal_uInt8 nStackSize ) - : SvParser( rIn, nStackSize ) + : SvParser( rIn, nStackSize ) , nOpenBrakets(0) , eCodeSet(RTL_TEXTENCODING_MS_1252) , nUCharOverread(1) diff --git a/svtools/source/svrtf/svparser.cxx b/svtools/source/svrtf/svparser.cxx index c2de091f1f0d..789464ddbdf5 100644 --- a/svtools/source/svrtf/svparser.cxx +++ b/svtools/source/svrtf/svparser.cxx @@ -28,6 +28,7 @@ #include // structure to store the actuel data +template struct SvParser_Impl { OUString aToken; // gescanntes Token @@ -35,10 +36,10 @@ struct SvParser_Impl sal_uLong nlLineNr; // actual line number sal_uLong nlLinePos; // actual column number long nTokenValue; // extra value (RTF) - bool bTokenHasValue; // indicates whether nTokenValue is valid - int nToken; // actual Token + bool bTokenHasValue; // indicates whether nTokenValue is valid + T nToken; // actual Token sal_uInt32 nNextCh; // actual character - int nSaveToken; // the token from Continue + T nSaveToken; // the token from Continue rtl_TextToUnicodeConverter hConv; rtl_TextToUnicodeContext hContext; @@ -49,9 +50,9 @@ struct SvParser_Impl , nlLinePos(0) , nTokenValue(0) , bTokenHasValue(false) - , nToken(0) + , nToken(static_cast(0)) , nNextCh(0) - , nSaveToken(0) + , nSaveToken(static_cast(0)) , hConv( nullptr ) , hContext( reinterpret_cast(1) ) { @@ -60,8 +61,17 @@ struct SvParser_Impl }; -// Construktor -SvParser::SvParser( SvStream& rIn, sal_uInt8 nStackSize ) +template +SvParser::TokenStackType::TokenStackType() + : nTokenValue(0) + , bTokenHasValue(false) + , nTokenId(static_cast(0)) +{ +} + +// Constructor +template +SvParser::SvParser( SvStream& rIn, sal_uInt8 nStackSize ) : rInput( rIn ) , nlLineNr( 1 ) , nlLinePos( 1 ) @@ -85,7 +95,8 @@ SvParser::SvParser( SvStream& rIn, sal_uInt8 nStackSize ) pTokenStackPos = pTokenStack; } -SvParser::~SvParser() +template +SvParser::~SvParser() { if( pImplData && pImplData->hConv ) { @@ -97,13 +108,32 @@ SvParser::~SvParser() delete [] pTokenStack; } -void SvParser::ClearTxtConvContext() +template SvParserState SvParser::GetStatus() const { return eState; } +template sal_uLong SvParser::GetLineNr() const { return nlLineNr; } +template sal_uLong SvParser::GetLinePos() const { return nlLinePos; } +template void SvParser::IncLineNr() { ++nlLineNr; } +template sal_uLong SvParser::IncLinePos() { return ++nlLinePos; } +template void SvParser::SetLineNr( sal_uLong nlNum ) { nlLineNr = nlNum; } +template void SvParser::SetLinePos( sal_uLong nlPos ) { nlLinePos = nlPos; } +template bool SvParser::IsParserWorking() const { return SvParserState::Working == eState; } +template rtl_TextEncoding SvParser::GetSrcEncoding() const { return eSrcEnc; } +template void SvParser::SetSwitchToUCS2( bool bSet ) { bSwitchToUCS2 = bSet; } +template bool SvParser::IsSwitchToUCS2() const { return bSwitchToUCS2; } +template sal_uInt16 SvParser::GetCharSize() const { return (RTL_TEXTENCODING_UCS2 == eSrcEnc) ? 2 : 1; } +template Link SvParser::GetAsynchCallLink() const +{ + return LINK( const_cast(this), SvParser, NewDataRead ); +} + +template +void SvParser::ClearTxtConvContext() { if( pImplData && pImplData->hConv ) rtl_resetTextToUnicodeContext( pImplData->hConv, pImplData->hContext ); } -void SvParser::SetSrcEncoding( rtl_TextEncoding eEnc ) +template +void SvParser::SetSrcEncoding( rtl_TextEncoding eEnc ) { if( eEnc != eSrcEnc ) { @@ -121,7 +151,7 @@ void SvParser::SetSrcEncoding( rtl_TextEncoding eEnc ) { eSrcEnc = eEnc; if( !pImplData ) - pImplData.reset(new SvParser_Impl); + pImplData.reset(new SvParser_Impl); pImplData->hConv = rtl_createTextToUnicodeConverter( eSrcEnc ); DBG_ASSERT( pImplData->hConv, "SvParser::SetSrcEncoding: no converter for source encoding" ); @@ -140,13 +170,15 @@ void SvParser::SetSrcEncoding( rtl_TextEncoding eEnc ) } } -void SvParser::RereadLookahead() +template +void SvParser::RereadLookahead() { rInput.Seek(nNextChPos); nNextCh = GetNextChar(); } -sal_uInt32 SvParser::GetNextChar() +template +sal_uInt32 SvParser::GetNextChar() { sal_uInt32 c = 0U; @@ -416,9 +448,10 @@ sal_uInt32 SvParser::GetNextChar() return c; } -int SvParser::GetNextToken() +template +T SvParser::GetNextToken() { - int nRet = 0; + T nRet = static_cast(0); if( !nTokenStackPos ) { @@ -458,7 +491,8 @@ int SvParser::GetNextToken() return nRet; } -int SvParser::SkipToken( short nCnt ) // "skip" n Tokens backward +template +T SvParser::SkipToken( short nCnt ) // "skip" n Tokens backward { pTokenStackPos = GetStackPtr( nCnt ); short nTmp = nTokenStackPos - nCnt; @@ -476,7 +510,8 @@ int SvParser::SkipToken( short nCnt ) // "skip" n Tokens backward return pTokenStackPos->nTokenId; } -SvParser::TokenStackType* SvParser::GetStackPtr( short nCnt ) +template +typename SvParser::TokenStackType* SvParser::GetStackPtr( short nCnt ) { sal_uInt8 nAktPos = sal_uInt8(pTokenStackPos - pTokenStack ); if( nCnt > 0 ) @@ -503,25 +538,28 @@ SvParser::TokenStackType* SvParser::GetStackPtr( short nCnt ) } // is called for each token which is recognised by CallParser -void SvParser::NextToken( int ) +template +void SvParser::NextToken( T ) { } // to read asynchronous from SvStream -int SvParser::GetSaveToken() const +template +T SvParser::GetSaveToken() const { - return pImplData ? pImplData->nSaveToken : 0; + return pImplData ? pImplData->nSaveToken : static_cast(0); } -void SvParser::SaveState( int nToken ) +template +void SvParser::SaveState( T nToken ) { // save actual status if( !pImplData ) { - pImplData.reset(new SvParser_Impl); - pImplData->nSaveToken = 0; + pImplData.reset(new SvParser_Impl); + pImplData->nSaveToken = static_cast(0); } pImplData->nFilePos = rInput.Tell(); @@ -535,7 +573,8 @@ void SvParser::SaveState( int nToken ) pImplData->nNextCh = nNextCh; } -void SvParser::RestoreState() +template +void SvParser::RestoreState() { // restore old status if( pImplData ) @@ -555,13 +594,14 @@ void SvParser::RestoreState() } } -void SvParser::Continue( int ) +template +void SvParser::Continue( T ) { } -void SvParser::BuildWhichTable( std::vector &rWhichMap, - sal_uInt16 *pWhichIds, - sal_uInt16 nWhichIds ) +void BuildWhichTable( std::vector &rWhichMap, + sal_uInt16 *pWhichIds, + sal_uInt16 nWhichIds ) { sal_uInt16 aNewRange[2]; @@ -615,7 +655,15 @@ void SvParser::BuildWhichTable( std::vector &rWhichMap, } -IMPL_LINK_NOARG( SvParser, NewDataRead, LinkParamNone*, void ) +// expanded out version of +// IMPL_LINK_NOARG( SvParser, NewDataRead, LinkParamNone*, void ) +// since it can't cope with template methods +template +void SvParser::LinkStubNewDataRead(void * instance, LinkParamNone* data) { + return static_cast *>(instance)->NewDataRead(data); +} +template +void SvParser::NewDataRead(SAL_UNUSED_PARAMETER LinkParamNone*) { switch( eState ) { @@ -642,6 +690,9 @@ IMPL_LINK_NOARG( SvParser, NewDataRead, LinkParamNone*, void ) } } +template class SVT_DLLPUBLIC SvParser; +template class SVT_DLLPUBLIC SvParser; + /*======================================================================== * * SvKeyValueIterator. -- cgit