basctl/source/basicide/baside2.hxx | 1 basctl/source/basicide/baside2b.cxx | 26 --- comphelper/qa/unit/syntaxhighlighttest.cxx | 26 --- comphelper/source/misc/syntaxhighlight.cxx | 225 ++++++++++++-------------- helpcompiler/source/BasCodeTagger.cxx | 7 include/comphelper/syntaxhighlight.hxx | 86 +-------- include/svtools/svmedit.hxx | 1 svtools/source/edit/editsyntaxhighlighter.cxx | 7 8 files changed, 137 insertions(+), 242 deletions(-)
New commits: commit a2f9c446b79d50d808bdc6e3487d230459f81260 Author: Stephan Bergmann <sberg...@redhat.com> Date: Mon Oct 28 12:56:23 2013 +0100 Some clean-up Change-Id: I8ef80b7ae952428a62cc1cea8b03219b77a83e99 diff --git a/comphelper/source/misc/syntaxhighlight.cxx b/comphelper/source/misc/syntaxhighlight.cxx index bdf9d43..c9bac08 100644 --- a/comphelper/source/misc/syntaxhighlight.cxx +++ b/comphelper/source/misc/syntaxhighlight.cxx @@ -257,7 +257,6 @@ namespace class SyntaxHighlighter::Tokenizer { - HighlighterLanguage aLanguage; // Character information tables sal_uInt16 aCharTypeTab[256]; @@ -272,7 +271,9 @@ class SyntaxHighlighter::Tokenizer sal_uInt16 nKeyWordCount; public: - Tokenizer( HighlighterLanguage aLang = HIGHLIGHT_BASIC ); + HighlighterLanguage const aLanguage; + + Tokenizer( HighlighterLanguage aLang ); ~Tokenizer( void ); void getHighlightPortions( const OUString& rLine, @@ -710,4 +711,9 @@ void SyntaxHighlighter::getHighlightPortions( const OUString& rLine, m_tokenizer->getHighlightPortions( rLine, portions ); } +HighlighterLanguage SyntaxHighlighter::GetLanguage() +{ + return m_tokenizer->aLanguage; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/syntaxhighlight.hxx b/include/comphelper/syntaxhighlight.hxx index ec0bf7c..081be1d 100644 --- a/include/comphelper/syntaxhighlight.hxx +++ b/include/comphelper/syntaxhighlight.hxx @@ -80,8 +80,9 @@ public: void getHighlightPortions( const OUString& rLine, std::vector<HighlightPortion>& pPortions ); - HighlighterLanguage GetLanguage() { return eLanguage;} + HighlighterLanguage GetLanguage(); }; + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 176ac1e61610579ba8ac202c16d7aa0c0991af89 Author: Stephan Bergmann <sberg...@redhat.com> Date: Mon Oct 28 12:51:52 2013 +0100 Remove unnecessary SyntaxHighlighter::Tokenizer statefulness ...which reveals that SyntaxHighlighter::notifyChange does nothing, so remove it. Change-Id: I49834af29081ee703d9e62e182e3c1f8ce7e212e diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index 1b3ad3f..d9316fe 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -1189,8 +1189,6 @@ void EditorWindow::ImpDoHighlight( sal_uLong nLine ) if ( bDoSyntaxHighlight ) { OUString aLine( pEditEngine->GetText( nLine ) ); - aHighlighter.notifyChange( &aLine, 1 ); - bool const bWasModified = pEditEngine->IsModified(); pEditEngine->RemoveAttribs( nLine, true ); std::vector<HighlightPortion> aPortions; @@ -1326,12 +1324,6 @@ void EditorWindow::ParagraphInsertedDeleted( sal_uLong nPara, bool bInserted ) GetOutputSizePixel().Height() - 2 * DWBORDER); rModulWindow.GetLineNumberWindow().SetPosSizePixel(Point(DWBORDER + 19, DWBORDER), aLnSz); rModulWindow.GetLineNumberWindow().Invalidate(); - - if ( bDoSyntaxHighlight ) - { - OUString aDummy; - aHighlighter.notifyChange( &aDummy, 1 ); - } } } diff --git a/comphelper/source/misc/syntaxhighlight.cxx b/comphelper/source/misc/syntaxhighlight.cxx index fa5afc1..bdf9d43 100644 --- a/comphelper/source/misc/syntaxhighlight.cxx +++ b/comphelper/source/misc/syntaxhighlight.cxx @@ -261,17 +261,11 @@ class SyntaxHighlighter::Tokenizer // Character information tables sal_uInt16 aCharTypeTab[256]; - const sal_Unicode* mpStringBegin; - const sal_Unicode* mpActualPos; - - sal_Unicode peekChar( void ) { return *mpActualPos; } - sal_Unicode getChar( void ) { return *mpActualPos++; } - // Auxiliary function: testing of the character flags sal_Bool testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags ); // Get new token, EmptyString == nothing more over there - sal_Bool getNextToken( /*out*/TokenTypes& reType, + sal_Bool getNextToken( const sal_Unicode*& pos, /*out*/TokenTypes& reType, /*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos ); const char** ppListKeyWords; @@ -281,7 +275,6 @@ public: Tokenizer( HighlighterLanguage aLang = HIGHLIGHT_BASIC ); ~Tokenizer( void ); - sal_uInt16 parseLine( const OUString* aSource ); void getHighlightPortions( const OUString& rLine, /*out*/std::vector<HighlightPortion>& portions ); void setKeyWords( const char** ppKeyWords, sal_uInt16 nCount ); @@ -309,25 +302,25 @@ void SyntaxHighlighter::Tokenizer::setKeyWords( const char** ppKeyWords, sal_uIn nKeyWordCount = nCount; } -sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType, +sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( const sal_Unicode*& pos, /*out*/TokenTypes& reType, /*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos ) { reType = TT_UNKNOWN; - rpStartPos = mpActualPos; + rpStartPos = pos; - sal_Unicode c = peekChar(); + sal_Unicode c = *pos; if( c == 0 ) return sal_False; - getChar(); + ++pos; //*** Go through all possibilities *** // Space? if ( (testCharFlags( c, CHAR_SPACE ) == sal_True) ) { - while( testCharFlags( peekChar(), CHAR_SPACE ) == sal_True ) - getChar(); + while( testCharFlags( *pos, CHAR_SPACE ) == sal_True ) + ++pos; reType = TT_WHITESPACE; } @@ -339,10 +332,10 @@ sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType, do { // Naechstes Zeichen holen - c = peekChar(); + c = *pos; bIdentifierChar = testCharFlags( c, CHAR_IN_IDENTIFIER ); if( bIdentifierChar ) - getChar(); + ++pos; } while( bIdentifierChar ); @@ -351,7 +344,7 @@ sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType, // Keyword table if (ppListKeyWords != NULL) { - int nCount = mpActualPos - rpStartPos; + int nCount = pos - rpStartPos; // No keyword if string contains char > 255 bool bCanBeKeyword = true; @@ -377,11 +370,11 @@ sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType, if (aByteStr.equalsL(RTL_CONSTASCII_STRINGPARAM("rem"))) { // Remove all characters until end of line or EOF - sal_Unicode cPeek = peekChar(); + sal_Unicode cPeek = *pos; while( cPeek != 0 && testCharFlags( cPeek, CHAR_EOL ) == sal_False ) { - c = getChar(); - cPeek = peekChar(); + c = *pos++; + cPeek = *pos; } reType = TT_COMMENT; @@ -404,10 +397,10 @@ sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType, do { // Get next character - c = peekChar(); + c = *pos; bIdentifierChar = isAlpha(c); if( bIdentifierChar ) - getChar(); + ++pos; } while( bIdentifierChar ); } @@ -415,28 +408,28 @@ sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType, } else if (c=='-') { - sal_Unicode cPeekNext = peekChar(); + sal_Unicode cPeekNext = *pos; if (cPeekNext=='-') { // Remove all characters until end of line or EOF while( cPeekNext != 0 && testCharFlags( cPeekNext, CHAR_EOL ) == sal_False ) { - getChar(); - cPeekNext = peekChar(); + ++pos; + cPeekNext = *pos; } reType = TT_COMMENT; } } else if (c=='/') { - sal_Unicode cPeekNext = peekChar(); + sal_Unicode cPeekNext = *pos; if (cPeekNext=='/') { // Remove all characters until end of line or EOF while( cPeekNext != 0 && testCharFlags( cPeekNext, CHAR_EOL ) == sal_False ) { - getChar(); - cPeekNext = peekChar(); + ++pos; + cPeekNext = *pos; } reType = TT_COMMENT; } @@ -448,11 +441,11 @@ sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType, { // Skip all characters until end of input or end of line: for (;;) { - c = peekChar(); + c = *pos; if (c == 0 || testCharFlags(c, CHAR_EOL)) { break; } - getChar(); + ++pos; } reType = TT_COMMENT; @@ -469,7 +462,7 @@ sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType, } // Object separator? Must be handled before Number - else if( c == '.' && ( peekChar() < '0' || peekChar() > '9' ) ) + else if( c == '.' && ( *pos < '0' || *pos > '9' ) ) { reType = TT_OPERATOR; } @@ -486,26 +479,26 @@ sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType, if( c == '&' ) { // Octal? - if( peekChar() == 'o' || peekChar() == 'O' ) + if( *pos == 'o' || *pos == 'O' ) { // remove o - getChar(); + ++pos; nRadix = 8; // Octal base // Read all numbers - while( testCharFlags( peekChar(), CHAR_IN_OCT_NUMBER ) ) - c = getChar(); + while( testCharFlags( *pos, CHAR_IN_OCT_NUMBER ) ) + c = *pos++; } // Hexadecimal? - else if( peekChar() == 'h' || peekChar() == 'H' ) + else if( *pos == 'h' || *pos == 'H' ) { // remove x - getChar(); + ++pos; nRadix = 16; // Hexadecimal base // Read all numbers - while( testCharFlags( peekChar(), CHAR_IN_HEX_NUMBER ) ) - c = getChar(); + while( testCharFlags( *pos, CHAR_IN_HEX_NUMBER ) ) + c = *pos++; } else { @@ -520,12 +513,12 @@ sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType, sal_Bool bAfterExpChar = sal_False; // Read all numbers - while( testCharFlags( peekChar(), CHAR_IN_NUMBER ) || - (bAfterExpChar && peekChar() == '+' ) || - (bAfterExpChar && peekChar() == '-' ) ) + while( testCharFlags( *pos, CHAR_IN_NUMBER ) || + (bAfterExpChar && *pos == '+' ) || + (bAfterExpChar && *pos == '-' ) ) // After exponent +/- are OK, too { - c = getChar(); + c = *pos++; bAfterExpChar = ( c == 'e' || c == 'E' ); } } @@ -540,16 +533,16 @@ sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType, cEndString = ']'; // Read all characters - while( peekChar() != cEndString ) + while( *pos != cEndString ) { - // Detect EOF before getChar(), so we do not loose EOF - if( peekChar() == 0 ) + // Detect EOF before reading next char, so we do not loose EOF + if( *pos == 0 ) { // ERROR: unterminated string literal reType = TT_ERROR; break; } - c = getChar(); + c = *pos++; if( testCharFlags( c, CHAR_EOL ) == sal_True ) { // ERROR: unterminated string literal @@ -560,7 +553,7 @@ sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType, if( reType != TT_ERROR ) { - getChar(); + ++pos; if( cEndString == ']' ) reType = TT_IDENTIFIER; else @@ -572,9 +565,9 @@ sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType, else if( testCharFlags( c, CHAR_EOL ) == sal_True ) { // If another EOL character comes, read it - sal_Unicode cNext = peekChar(); + sal_Unicode cNext = *pos; if( cNext != c && testCharFlags( cNext, CHAR_EOL ) == sal_True ) - getChar(); + ++pos; reType = TT_EOL; } @@ -582,7 +575,7 @@ sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType, // All other will remain TT_UNKNOWN // Save end position - rpEndPos = mpActualPos; + rpEndPos = pos; return sal_True; } @@ -670,29 +663,11 @@ SyntaxHighlighter::Tokenizer::~Tokenizer( void ) { } -sal_uInt16 SyntaxHighlighter::Tokenizer::parseLine( const OUString* aSource ) -{ - // Set the position to the beginning of the source string - mpStringBegin = mpActualPos = aSource->getStr(); - - // Variables for the out parameter - TokenTypes eType; - const sal_Unicode* pStartPos; - const sal_Unicode* pEndPos; - - // Loop over all the tokens - sal_uInt16 nTokenCount = 0; - while( getNextToken( eType, pStartPos, pEndPos ) ) - nTokenCount++; - - return nTokenCount; -} - void SyntaxHighlighter::Tokenizer::getHighlightPortions( const OUString& rLine, /*out*/std::vector<HighlightPortion>& portions ) { // Set the position to the beginning of the source string - mpStringBegin = mpActualPos = rLine.getStr(); + const sal_Unicode* pos = rLine.getStr(); // Variables for the out parameter TokenTypes eType; @@ -700,11 +675,11 @@ void SyntaxHighlighter::Tokenizer::getHighlightPortions( const OUString& rLine, const sal_Unicode* pEndPos; // Loop over all the tokens - while( getNextToken( eType, pStartPos, pEndPos ) ) + while( getNextToken( pos, eType, pStartPos, pEndPos ) ) { portions.push_back( HighlightPortion( - pStartPos - mpStringBegin, pEndPos - mpStringBegin, eType)); + pStartPos - rLine.getStr(), pEndPos - rLine.getStr(), eType)); } } @@ -729,13 +704,6 @@ SyntaxHighlighter::SyntaxHighlighter(HighlighterLanguage language): SyntaxHighlighter::~SyntaxHighlighter() {} -void SyntaxHighlighter::notifyChange( - const OUString* pChangedLines, sal_uInt32 nArrayLength) -{ - for( sal_uInt32 i=0 ; i < nArrayLength ; i++ ) - m_tokenizer->parseLine(&pChangedLines[i]); -} - void SyntaxHighlighter::getHighlightPortions( const OUString& rLine, /*out*/std::vector<HighlightPortion>& portions ) { diff --git a/helpcompiler/source/BasCodeTagger.cxx b/helpcompiler/source/BasCodeTagger.cxx index a01c6b6..fcbe8e4 100644 --- a/helpcompiler/source/BasCodeTagger.cxx +++ b/helpcompiler/source/BasCodeTagger.cxx @@ -149,7 +149,6 @@ void BasicCodeTagger::tagParagraph( xmlNodePtr paragraph ) OUString strLine( reinterpret_cast<const sal_Char*>(codeSnippet), strlen(reinterpret_cast<const char*>(codeSnippet)), RTL_TEXTENCODING_UTF8 ); - m_Highlighter.notifyChange ( &strLine, 1 ); std::vector<HighlightPortion> portions; m_Highlighter.getHighlightPortions( strLine, portions ); for (std::vector<HighlightPortion>::iterator i(portions.begin()); diff --git a/include/comphelper/syntaxhighlight.hxx b/include/comphelper/syntaxhighlight.hxx index 8a57822..ec0bf7c 100644 --- a/include/comphelper/syntaxhighlight.hxx +++ b/include/comphelper/syntaxhighlight.hxx @@ -66,11 +66,6 @@ enum HighlighterLanguage HIGHLIGHT_SQL }; -//*** SyntaxHighlighter Class *** -// Concept: the Highlighter will be notified of all changes in the source -// (notifyChange) and returns the caller the range of lines, which based on the -// changes, need to be highlighted again. For this the Highlighter marks all -// lines internally whether or not C comments begin or end. class COMPHELPER_DLLPUBLIC SyntaxHighlighter: private boost::noncopyable { class Tokenizer; @@ -82,8 +77,6 @@ public: SyntaxHighlighter(HighlighterLanguage language); ~SyntaxHighlighter(); - void notifyChange(const OUString* pChangedLines, sal_uInt32 nArrayLength); - void getHighlightPortions( const OUString& rLine, std::vector<HighlightPortion>& pPortions ); diff --git a/svtools/source/edit/editsyntaxhighlighter.cxx b/svtools/source/edit/editsyntaxhighlighter.cxx index d679408..6834396 100644 --- a/svtools/source/edit/editsyntaxhighlighter.cxx +++ b/svtools/source/edit/editsyntaxhighlighter.cxx @@ -170,8 +170,6 @@ void MultiLineEditSyntaxHighlight::UpdateData() for (unsigned int nLine=0; nLine < GetTextEngine()->GetParagraphCount(); nLine++) { OUString aLine( GetTextEngine()->GetText( nLine ) ); - aHighlighter.notifyChange( &aLine, 1 ); - GetTextEngine()->RemoveAttribs( nLine, sal_True ); std::vector<HighlightPortion> aPortions; aHighlighter.getHighlightPortions( aLine, aPortions ); commit c99267b326afcfd4002dc5ee33f5076a466c0cab Author: Stephan Bergmann <sberg...@redhat.com> Date: Mon Oct 28 12:30:28 2013 +0100 Fold SyntaxHighlighter::initialize into ctor ...which reveals that m_pKeyWords, m_nKeyWordCount members are unused. Change-Id: I55020e892d463f2e40d5bcf71efba92778b317c1 diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index 0a52760..1b3ad3f 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -233,6 +233,7 @@ EditorWindow::EditorWindow (Window* pParent, ModulWindow* pModulWindow) : pEditEngine(0), rModulWindow(*pModulWindow), nCurTextWidth(0), + aHighlighter(HIGHLIGHT_BASIC), bHighlightning(false), bDoSyntaxHighlight(true), bDelayHighlight(true), @@ -962,8 +963,6 @@ void EditorWindow::CreateEditEngine() aSyntaxIdleTimer.SetTimeout( 200 ); aSyntaxIdleTimer.SetTimeoutHdl( LINK( this, EditorWindow, SyntaxTimerHdl ) ); - aHighlighter.initialize( HIGHLIGHT_BASIC ); - bool bWasDoSyntaxHighlight = bDoSyntaxHighlight; bDoSyntaxHighlight = false; // too slow for large texts... OUString aOUSource(rModulWindow.GetModule()); @@ -1311,7 +1310,6 @@ void EditorWindow::ParagraphInsertedDeleted( sal_uLong nPara, bool bInserted ) rModulWindow.GetBreakPoints().reset(); rModulWindow.GetBreakPointWindow().Invalidate(); rModulWindow.GetLineNumberWindow().Invalidate(); - aHighlighter.initialize( HIGHLIGHT_BASIC ); } else { diff --git a/comphelper/qa/unit/syntaxhighlighttest.cxx b/comphelper/qa/unit/syntaxhighlighttest.cxx index af834a6..cf13cbb 100644 --- a/comphelper/qa/unit/syntaxhighlighttest.cxx +++ b/comphelper/qa/unit/syntaxhighlighttest.cxx @@ -38,11 +38,9 @@ public: }; void SyntaxHighlightTest::testBasicString() { - SyntaxHighlighter h; - h.initialize(HIGHLIGHT_BASIC); OUString s("\"foo\""); std::vector<HighlightPortion> ps; - h.getHighlightPortions(s, ps); + SyntaxHighlighter(HIGHLIGHT_BASIC).getHighlightPortions(s, ps); CPPUNIT_ASSERT_EQUAL( static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size()); CPPUNIT_ASSERT_EQUAL(0, ps[0].nBegin); @@ -51,11 +49,9 @@ void SyntaxHighlightTest::testBasicString() { } void SyntaxHighlightTest::testBasicComment() { - SyntaxHighlighter h; - h.initialize(HIGHLIGHT_BASIC); OUString s("' foo"); std::vector<HighlightPortion> ps; - h.getHighlightPortions(s, ps); + SyntaxHighlighter(HIGHLIGHT_BASIC).getHighlightPortions(s, ps); CPPUNIT_ASSERT_EQUAL( static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size()); CPPUNIT_ASSERT_EQUAL(0, ps[0].nBegin); @@ -64,11 +60,9 @@ void SyntaxHighlightTest::testBasicComment() { } void SyntaxHighlightTest::testBasicCommentNewline() { - SyntaxHighlighter h; - h.initialize(HIGHLIGHT_BASIC); OUString s("' foo\n"); std::vector<HighlightPortion> ps; - h.getHighlightPortions(s, ps); + SyntaxHighlighter(HIGHLIGHT_BASIC).getHighlightPortions(s, ps); CPPUNIT_ASSERT_EQUAL( static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size()); CPPUNIT_ASSERT_EQUAL(0, ps[0].nBegin); @@ -80,11 +74,9 @@ void SyntaxHighlightTest::testBasicCommentNewline() { } void SyntaxHighlightTest::testBasicEmptyComment() { - SyntaxHighlighter h; - h.initialize(HIGHLIGHT_BASIC); OUString s("'"); std::vector<HighlightPortion> ps; - h.getHighlightPortions(s, ps); + SyntaxHighlighter(HIGHLIGHT_BASIC).getHighlightPortions(s, ps); CPPUNIT_ASSERT_EQUAL( static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size()); CPPUNIT_ASSERT_EQUAL(0, ps[0].nBegin); @@ -93,11 +85,9 @@ void SyntaxHighlightTest::testBasicEmptyComment() { } void SyntaxHighlightTest::testBasicEmptyCommentNewline() { - SyntaxHighlighter h; - h.initialize(HIGHLIGHT_BASIC); OUString s("'\n"); std::vector<HighlightPortion> ps; - h.getHighlightPortions(s, ps); + SyntaxHighlighter(HIGHLIGHT_BASIC).getHighlightPortions(s, ps); CPPUNIT_ASSERT_EQUAL( static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size()); CPPUNIT_ASSERT_EQUAL(0, ps[0].nBegin); @@ -112,11 +102,9 @@ void SyntaxHighlightTest::testBasic() { OUString aBasicString(" if Mid(sText,iRun,1 )<> \" \" then Mid( sText ,iRun, 1, Chr( 1 + Asc( Mid(sText,iRun,1 )) ) '"); - SyntaxHighlighter aHighlighter; - aHighlighter.initialize( HIGHLIGHT_BASIC ); - std::vector<HighlightPortion> aPortions; - aHighlighter.getHighlightPortions( aBasicString, aPortions ); + SyntaxHighlighter(HIGHLIGHT_BASIC).getHighlightPortions( + aBasicString, aPortions ); sal_Int32 prevEnd = 0; for(std::vector<HighlightPortion>::const_iterator itr = diff --git a/comphelper/source/misc/syntaxhighlight.cxx b/comphelper/source/misc/syntaxhighlight.cxx index b886fea..fa5afc1 100644 --- a/comphelper/source/misc/syntaxhighlight.cxx +++ b/comphelper/source/misc/syntaxhighlight.cxx @@ -17,6 +17,9 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include "sal/config.h" + +#include <cassert> #include <unicode/uchar.h> #include <comphelper/syntaxhighlight.hxx> @@ -706,22 +709,9 @@ void SyntaxHighlighter::Tokenizer::getHighlightPortions( const OUString& rLine, } -SyntaxHighlighter::SyntaxHighlighter() +SyntaxHighlighter::SyntaxHighlighter(HighlighterLanguage language): + eLanguage(language), m_tokenizer(new SyntaxHighlighter::Tokenizer(language)) { - m_pKeyWords = NULL; - m_nKeyWordCount = 0; -} - -SyntaxHighlighter::~SyntaxHighlighter() -{ - delete m_pKeyWords; -} - -void SyntaxHighlighter::initialize( HighlighterLanguage eLanguage_ ) -{ - eLanguage = eLanguage_; - m_tokenizer.reset(new SyntaxHighlighter::Tokenizer(eLanguage)); - switch (eLanguage) { case HIGHLIGHT_BASIC: @@ -733,10 +723,12 @@ void SyntaxHighlighter::initialize( HighlighterLanguage eLanguage_ ) sizeof( strListSqlKeyWords ) / sizeof( char* )); break; default: - m_tokenizer->setKeyWords( NULL, 0 ); + assert(false); // this cannot happen } } +SyntaxHighlighter::~SyntaxHighlighter() {} + void SyntaxHighlighter::notifyChange( const OUString* pChangedLines, sal_uInt32 nArrayLength) { diff --git a/helpcompiler/source/BasCodeTagger.cxx b/helpcompiler/source/BasCodeTagger.cxx index 782bcdc..a01c6b6 100644 --- a/helpcompiler/source/BasCodeTagger.cxx +++ b/helpcompiler/source/BasCodeTagger.cxx @@ -55,13 +55,13 @@ xmlNodePtr LibXmlTreeWalker::currentNode() //====================================================== -BasicCodeTagger::BasicCodeTagger( xmlDocPtr rootDoc ) +BasicCodeTagger::BasicCodeTagger( xmlDocPtr rootDoc ): + m_Highlighter(HIGHLIGHT_BASIC) { if ( rootDoc == NULL ) throw NULL_DOCUMENT; m_pDocument = rootDoc; m_pXmlTreeWalker = NULL; - m_Highlighter.initialize( HIGHLIGHT_BASIC ); m_bTaggingCompleted = false; } diff --git a/include/comphelper/syntaxhighlight.hxx b/include/comphelper/syntaxhighlight.hxx index 43c42d0..8a57822 100644 --- a/include/comphelper/syntaxhighlight.hxx +++ b/include/comphelper/syntaxhighlight.hxx @@ -21,6 +21,7 @@ #include <vector> +#include <boost/noncopyable.hpp> #include <boost/scoped_ptr.hpp> #include <rtl/ustring.hxx> @@ -70,24 +71,16 @@ enum HighlighterLanguage // (notifyChange) and returns the caller the range of lines, which based on the // changes, need to be highlighted again. For this the Highlighter marks all // lines internally whether or not C comments begin or end. -class COMPHELPER_DLLPUBLIC SyntaxHighlighter +class COMPHELPER_DLLPUBLIC SyntaxHighlighter: private boost::noncopyable { class Tokenizer; HighlighterLanguage eLanguage; boost::scoped_ptr<Tokenizer> m_tokenizer; - char* m_pKeyWords; - sal_uInt16 m_nKeyWordCount; - -// void initializeKeyWords( HighlighterLanguage eLanguage ); public: - SyntaxHighlighter( void ); - ~SyntaxHighlighter( void ); - - // (Re-)initialize Highlighter. The line-table will be completely erased, - // meaning that on completion an empty Source is assumed. - void initialize( HighlighterLanguage eLanguage_ ); + SyntaxHighlighter(HighlighterLanguage language); + ~SyntaxHighlighter(); void notifyChange(const OUString* pChangedLines, sal_uInt32 nArrayLength); diff --git a/svtools/source/edit/editsyntaxhighlighter.cxx b/svtools/source/edit/editsyntaxhighlighter.cxx index d84fc15..d679408 100644 --- a/svtools/source/edit/editsyntaxhighlighter.cxx +++ b/svtools/source/edit/editsyntaxhighlighter.cxx @@ -26,10 +26,9 @@ MultiLineEditSyntaxHighlight::MultiLineEditSyntaxHighlight( Window* pParent, WinBits nWinStyle, - HighlighterLanguage aLanguage): MultiLineEdit(pParent,nWinStyle), mbDoBracketHilight(true) + HighlighterLanguage aLanguage): MultiLineEdit(pParent,nWinStyle), mbDoBracketHilight(true), aHighlighter(aLanguage) { EnableUpdateData(300); - aHighlighter.initialize( aLanguage ); } extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeMultiLineEditSyntaxHighlight(Window *pParent, VclBuilder::stringmap &) commit 6aa24e7565dfa5feafd12cd0ec12312df044916e Author: Stephan Bergmann <sberg...@redhat.com> Date: Mon Oct 28 12:09:28 2013 +0100 Move implementation details to syntaxhighlight.cxx (and clean up a little) Change-Id: I6e660708d8ca1509b89b306cd428dc38c8b03f2c diff --git a/basctl/source/basicide/baside2.hxx b/basctl/source/basicide/baside2.hxx index 85a1d88..68b937e 100644 --- a/basctl/source/basicide/baside2.hxx +++ b/basctl/source/basicide/baside2.hxx @@ -56,6 +56,7 @@ class SvxSearchItem; #include "com/sun/star/reflection/XIdlClass.hpp" #include <comphelper/namedvaluecollection.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/syntaxhighlight.hxx> #include <comphelper/configurationhelper.hxx> #include "com/sun/star/reflection/XIdlReflection.hpp" diff --git a/comphelper/source/misc/syntaxhighlight.cxx b/comphelper/source/misc/syntaxhighlight.cxx index fd8ee26..b886fea 100644 --- a/comphelper/source/misc/syntaxhighlight.cxx +++ b/comphelper/source/misc/syntaxhighlight.cxx @@ -22,6 +22,18 @@ #include <comphelper/syntaxhighlight.hxx> #include <comphelper/string.hxx> +// Flags for character properties +#define CHAR_START_IDENTIFIER 0x0001 +#define CHAR_IN_IDENTIFIER 0x0002 +#define CHAR_START_NUMBER 0x0004 +#define CHAR_IN_NUMBER 0x0008 +#define CHAR_IN_HEX_NUMBER 0x0010 +#define CHAR_IN_OCT_NUMBER 0x0020 +#define CHAR_START_STRING 0x0040 +#define CHAR_OPERATOR 0x0080 +#define CHAR_SPACE 0x0100 +#define CHAR_EOL 0x0200 + // ########################################################################## // ATTENTION: all these words need to be in lower case // ########################################################################## @@ -232,7 +244,7 @@ extern "C" int compare_strings( const void *arg1, const void *arg2 ) namespace { - static bool isAlpha(sal_Unicode c) + bool isAlpha(sal_Unicode c) { if (comphelper::string::isalphaAscii(c)) return true; @@ -240,8 +252,40 @@ namespace } } +class SyntaxHighlighter::Tokenizer +{ + HighlighterLanguage aLanguage; + // Character information tables + sal_uInt16 aCharTypeTab[256]; + + const sal_Unicode* mpStringBegin; + const sal_Unicode* mpActualPos; + + sal_Unicode peekChar( void ) { return *mpActualPos; } + sal_Unicode getChar( void ) { return *mpActualPos++; } + + // Auxiliary function: testing of the character flags + sal_Bool testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags ); + + // Get new token, EmptyString == nothing more over there + sal_Bool getNextToken( /*out*/TokenTypes& reType, + /*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos ); + + const char** ppListKeyWords; + sal_uInt16 nKeyWordCount; + +public: + Tokenizer( HighlighterLanguage aLang = HIGHLIGHT_BASIC ); + ~Tokenizer( void ); + + sal_uInt16 parseLine( const OUString* aSource ); + void getHighlightPortions( const OUString& rLine, + /*out*/std::vector<HighlightPortion>& portions ); + void setKeyWords( const char** ppKeyWords, sal_uInt16 nCount ); +}; + // Helper function: test character flag -sal_Bool SimpleTokenizer_Impl::testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags ) +sal_Bool SyntaxHighlighter::Tokenizer::testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags ) { bool bRet = false; if( c != 0 && c <= 255 ) @@ -256,13 +300,13 @@ sal_Bool SimpleTokenizer_Impl::testCharFlags( sal_Unicode c, sal_uInt16 nTestFla return bRet; } -void SimpleTokenizer_Impl::setKeyWords( const char** ppKeyWords, sal_uInt16 nCount ) +void SyntaxHighlighter::Tokenizer::setKeyWords( const char** ppKeyWords, sal_uInt16 nCount ) { ppListKeyWords = ppKeyWords; nKeyWordCount = nCount; } -sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, +sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType, /*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos ) { reType = TT_UNKNOWN; @@ -539,7 +583,7 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, return sal_True; } -SimpleTokenizer_Impl::SimpleTokenizer_Impl( HighlighterLanguage aLang ): aLanguage(aLang) +SyntaxHighlighter::Tokenizer::Tokenizer( HighlighterLanguage aLang ): aLanguage(aLang) { memset( aCharTypeTab, 0, sizeof( aCharTypeTab ) ); @@ -619,19 +663,11 @@ SimpleTokenizer_Impl::SimpleTokenizer_Impl( HighlighterLanguage aLang ): aLangua ppListKeyWords = NULL; } -SimpleTokenizer_Impl::~SimpleTokenizer_Impl( void ) -{ -} - -SimpleTokenizer_Impl* getSimpleTokenizer( void ) +SyntaxHighlighter::Tokenizer::~Tokenizer( void ) { - static SimpleTokenizer_Impl* pSimpleTokenizer = NULL; - if( !pSimpleTokenizer ) - pSimpleTokenizer = new SimpleTokenizer_Impl(); - return pSimpleTokenizer; } -sal_uInt16 SimpleTokenizer_Impl::parseLine( const OUString* aSource ) +sal_uInt16 SyntaxHighlighter::Tokenizer::parseLine( const OUString* aSource ) { // Set the position to the beginning of the source string mpStringBegin = mpActualPos = aSource->getStr(); @@ -649,7 +685,7 @@ sal_uInt16 SimpleTokenizer_Impl::parseLine( const OUString* aSource ) return nTokenCount; } -void SimpleTokenizer_Impl::getHighlightPortions( const OUString& rLine, +void SyntaxHighlighter::Tokenizer::getHighlightPortions( const OUString& rLine, /*out*/std::vector<HighlightPortion>& portions ) { // Set the position to the beginning of the source string @@ -672,35 +708,32 @@ void SimpleTokenizer_Impl::getHighlightPortions( const OUString& rLine, SyntaxHighlighter::SyntaxHighlighter() { - m_pSimpleTokenizer = 0; m_pKeyWords = NULL; m_nKeyWordCount = 0; } SyntaxHighlighter::~SyntaxHighlighter() { - delete m_pSimpleTokenizer; delete m_pKeyWords; } void SyntaxHighlighter::initialize( HighlighterLanguage eLanguage_ ) { eLanguage = eLanguage_; - delete m_pSimpleTokenizer; - m_pSimpleTokenizer = new SimpleTokenizer_Impl(eLanguage); + m_tokenizer.reset(new SyntaxHighlighter::Tokenizer(eLanguage)); switch (eLanguage) { case HIGHLIGHT_BASIC: - m_pSimpleTokenizer->setKeyWords( strListBasicKeyWords, + m_tokenizer->setKeyWords( strListBasicKeyWords, sizeof( strListBasicKeyWords ) / sizeof( char* )); break; case HIGHLIGHT_SQL: - m_pSimpleTokenizer->setKeyWords( strListSqlKeyWords, + m_tokenizer->setKeyWords( strListSqlKeyWords, sizeof( strListSqlKeyWords ) / sizeof( char* )); break; default: - m_pSimpleTokenizer->setKeyWords( NULL, 0 ); + m_tokenizer->setKeyWords( NULL, 0 ); } } @@ -708,13 +741,13 @@ void SyntaxHighlighter::notifyChange( const OUString* pChangedLines, sal_uInt32 nArrayLength) { for( sal_uInt32 i=0 ; i < nArrayLength ; i++ ) - m_pSimpleTokenizer->parseLine(&pChangedLines[i]); + m_tokenizer->parseLine(&pChangedLines[i]); } void SyntaxHighlighter::getHighlightPortions( const OUString& rLine, /*out*/std::vector<HighlightPortion>& portions ) { - m_pSimpleTokenizer->getHighlightPortions( rLine, portions ); + m_tokenizer->getHighlightPortions( rLine, portions ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/syntaxhighlight.hxx b/include/comphelper/syntaxhighlight.hxx index cbeb95e..43c42d0 100644 --- a/include/comphelper/syntaxhighlight.hxx +++ b/include/comphelper/syntaxhighlight.hxx @@ -20,6 +20,8 @@ #define INCLUDED_COMPHELPER_SYNTAXHIGHLIGHT_HXX #include <vector> + +#include <boost/scoped_ptr.hpp> #include <rtl/ustring.hxx> #include <comphelper/comphelperdllapi.h> @@ -55,22 +57,6 @@ struct HighlightPortion { {} }; -///////////////////////////////////////////////////////////////////////// -// Auxiliary class to support JavaScript modules, next to find functions which -// will later will be used for syntax highlighting - -// Flags for character properties -#define CHAR_START_IDENTIFIER 0x0001 -#define CHAR_IN_IDENTIFIER 0x0002 -#define CHAR_START_NUMBER 0x0004 -#define CHAR_IN_NUMBER 0x0008 -#define CHAR_IN_HEX_NUMBER 0x0010 -#define CHAR_IN_OCT_NUMBER 0x0020 -#define CHAR_START_STRING 0x0040 -#define CHAR_OPERATOR 0x0080 -#define CHAR_SPACE 0x0100 -#define CHAR_EOL 0x0200 - // Language mode of the Highlighter (possibly to be refined later with keyword // lists, C comment flags) enum HighlighterLanguage @@ -79,39 +65,6 @@ enum HighlighterLanguage HIGHLIGHT_SQL }; -class SimpleTokenizer_Impl -{ - HighlighterLanguage aLanguage; - // Character information tables - sal_uInt16 aCharTypeTab[256]; - - const sal_Unicode* mpStringBegin; - const sal_Unicode* mpActualPos; - - sal_Unicode peekChar( void ) { return *mpActualPos; } - sal_Unicode getChar( void ) { return *mpActualPos++; } - - // Auxiliary function: testing of the character flags - sal_Bool testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags ); - - // Get new token, EmptyString == nothing more over there - sal_Bool getNextToken( /*out*/TokenTypes& reType, - /*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos ); - - const char** ppListKeyWords; - sal_uInt16 nKeyWordCount; - -public: - SimpleTokenizer_Impl( HighlighterLanguage aLang = HIGHLIGHT_BASIC ); - ~SimpleTokenizer_Impl( void ); - - sal_uInt16 parseLine( const OUString* aSource ); - void getHighlightPortions( const OUString& rLine, - /*out*/std::vector<HighlightPortion>& portions ); - void setKeyWords( const char** ppKeyWords, sal_uInt16 nCount ); -}; - - //*** SyntaxHighlighter Class *** // Concept: the Highlighter will be notified of all changes in the source // (notifyChange) and returns the caller the range of lines, which based on the @@ -119,8 +72,10 @@ public: // lines internally whether or not C comments begin or end. class COMPHELPER_DLLPUBLIC SyntaxHighlighter { + class Tokenizer; + HighlighterLanguage eLanguage; - SimpleTokenizer_Impl* m_pSimpleTokenizer; + boost::scoped_ptr<Tokenizer> m_tokenizer; char* m_pKeyWords; sal_uInt16 m_nKeyWordCount; diff --git a/include/svtools/svmedit.hxx b/include/svtools/svmedit.hxx index 6999db8..64d81bd 100644 --- a/include/svtools/svmedit.hxx +++ b/include/svtools/svmedit.hxx @@ -23,7 +23,6 @@ #include <vcl/svapp.hxx> #include <vcl/vclmedit.hxx> -#include <comphelper/syntaxhighlight.hxx> #include <svtools/svtdllapi.h> #include <svtools/colorcfg.hxx> commit f5e8be8bb1681f0e2494337bc769b33332ef3fff Author: Stephan Bergmann <sberg...@redhat.com> Date: Mon Oct 28 11:38:36 2013 +0100 Remove unused SimpleTokenizer_Impl::nLine/nCol ...which are never read; remove thereby unused parameters from functions. Change-Id: I644d2dc1b2d13ae2f932d04243521eef97e67e3e diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index 485d696..0a52760 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -599,7 +599,7 @@ void EditorWindow::HandleAutoCorrect() const OUString& sActSubName = GetActualSubName( nLine ); // the actual procedure std::vector<HighlightPortion> aPortions; - aHighlighter.getHighlightPortions( nLine, aLine, aPortions ); + aHighlighter.getHighlightPortions( aLine, aPortions ); if( aPortions.empty() ) return; @@ -674,7 +674,7 @@ TextSelection EditorWindow::GetLastHighlightPortionTextSelection() sal_uInt16 nIndex = GetEditView()->GetSelection().GetStart().GetIndex(); OUString aLine( pEditEngine->GetText( nLine ) ); // the line being modified std::vector<HighlightPortion> aPortions; - aHighlighter.getHighlightPortions( nLine, aLine, aPortions ); + aHighlighter.getHighlightPortions( aLine, aPortions ); assert(!aPortions.empty()); HighlightPortion& r = aPortions.back(); @@ -722,7 +722,7 @@ void EditorWindow::HandleAutoCloseDoubleQuotes() OUString aLine( pEditEngine->GetText( nLine ) ); // the line being modified std::vector<HighlightPortion> aPortions; - aHighlighter.getHighlightPortions( nLine, aLine, aPortions ); + aHighlighter.getHighlightPortions( aLine, aPortions ); if( aPortions.empty() ) return; @@ -743,7 +743,7 @@ void EditorWindow::HandleProcedureCompletion() OUString aLine( pEditEngine->GetText( nLine ) ); std::vector<HighlightPortion> aPortions; - aHighlighter.getHighlightPortions( nLine, aLine, aPortions ); + aHighlighter.getHighlightPortions( aLine, aPortions ); if( aPortions.empty() ) return; @@ -793,7 +793,7 @@ void EditorWindow::HandleProcedureCompletion() {//searching forward for end token, or another sub/function definition OUString aCurrLine = pEditEngine->GetText( i ); std::vector<HighlightPortion> aCurrPortions; - aHighlighter.getHighlightPortions( i, aCurrLine, aCurrPortions ); + aHighlighter.getHighlightPortions( aCurrLine, aCurrPortions ); if( aCurrPortions.size() >= 3 ) {//at least 3 tokens: (sub|function) whitespace idetifier .... @@ -827,7 +827,7 @@ void EditorWindow::HandleCodeCompletion() std::vector<HighlightPortion> aPortions; aLine = aLine.copy(0, aSel.GetEnd().GetIndex()); - aHighlighter.getHighlightPortions( nLine, aLine, aPortions ); + aHighlighter.getHighlightPortions( aLine, aPortions ); if( !aPortions.empty() ) {//use the syntax highlighter to grab out nested reflection calls, eg. aVar.aMethod("aa").aOtherMethod .. for( std::vector<HighlightPortion>::reverse_iterator i( @@ -1190,12 +1190,12 @@ void EditorWindow::ImpDoHighlight( sal_uLong nLine ) if ( bDoSyntaxHighlight ) { OUString aLine( pEditEngine->GetText( nLine ) ); - aHighlighter.notifyChange( nLine, 0, &aLine, 1 ); + aHighlighter.notifyChange( &aLine, 1 ); bool const bWasModified = pEditEngine->IsModified(); pEditEngine->RemoveAttribs( nLine, true ); std::vector<HighlightPortion> aPortions; - aHighlighter.getHighlightPortions( nLine, aLine, aPortions ); + aHighlighter.getHighlightPortions( aLine, aPortions ); for (std::vector<HighlightPortion>::iterator i(aPortions.begin()); i != aPortions.end(); ++i) @@ -1332,7 +1332,7 @@ void EditorWindow::ParagraphInsertedDeleted( sal_uLong nPara, bool bInserted ) if ( bDoSyntaxHighlight ) { OUString aDummy; - aHighlighter.notifyChange( nPara, bInserted ? 1 : (-1), &aDummy, 1 ); + aHighlighter.notifyChange( &aDummy, 1 ); } } } diff --git a/comphelper/qa/unit/syntaxhighlighttest.cxx b/comphelper/qa/unit/syntaxhighlighttest.cxx index 294db3e..af834a6 100644 --- a/comphelper/qa/unit/syntaxhighlighttest.cxx +++ b/comphelper/qa/unit/syntaxhighlighttest.cxx @@ -42,7 +42,7 @@ void SyntaxHighlightTest::testBasicString() { h.initialize(HIGHLIGHT_BASIC); OUString s("\"foo\""); std::vector<HighlightPortion> ps; - h.getHighlightPortions(0, s, ps); + h.getHighlightPortions(s, ps); CPPUNIT_ASSERT_EQUAL( static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size()); CPPUNIT_ASSERT_EQUAL(0, ps[0].nBegin); @@ -55,7 +55,7 @@ void SyntaxHighlightTest::testBasicComment() { h.initialize(HIGHLIGHT_BASIC); OUString s("' foo"); std::vector<HighlightPortion> ps; - h.getHighlightPortions(0, s, ps); + h.getHighlightPortions(s, ps); CPPUNIT_ASSERT_EQUAL( static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size()); CPPUNIT_ASSERT_EQUAL(0, ps[0].nBegin); @@ -68,7 +68,7 @@ void SyntaxHighlightTest::testBasicCommentNewline() { h.initialize(HIGHLIGHT_BASIC); OUString s("' foo\n"); std::vector<HighlightPortion> ps; - h.getHighlightPortions(0, s, ps); + h.getHighlightPortions(s, ps); CPPUNIT_ASSERT_EQUAL( static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size()); CPPUNIT_ASSERT_EQUAL(0, ps[0].nBegin); @@ -84,7 +84,7 @@ void SyntaxHighlightTest::testBasicEmptyComment() { h.initialize(HIGHLIGHT_BASIC); OUString s("'"); std::vector<HighlightPortion> ps; - h.getHighlightPortions(0, s, ps); + h.getHighlightPortions(s, ps); CPPUNIT_ASSERT_EQUAL( static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size()); CPPUNIT_ASSERT_EQUAL(0, ps[0].nBegin); @@ -97,7 +97,7 @@ void SyntaxHighlightTest::testBasicEmptyCommentNewline() { h.initialize(HIGHLIGHT_BASIC); OUString s("'\n"); std::vector<HighlightPortion> ps; - h.getHighlightPortions(0, s, ps); + h.getHighlightPortions(s, ps); CPPUNIT_ASSERT_EQUAL( static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size()); CPPUNIT_ASSERT_EQUAL(0, ps[0].nBegin); @@ -116,7 +116,7 @@ void SyntaxHighlightTest::testBasic() aHighlighter.initialize( HIGHLIGHT_BASIC ); std::vector<HighlightPortion> aPortions; - aHighlighter.getHighlightPortions( 0, aBasicString, aPortions ); + aHighlighter.getHighlightPortions( aBasicString, aPortions ); sal_Int32 prevEnd = 0; for(std::vector<HighlightPortion>::const_iterator itr = diff --git a/comphelper/source/misc/syntaxhighlight.cxx b/comphelper/source/misc/syntaxhighlight.cxx index ca3207d..fd8ee26 100644 --- a/comphelper/source/misc/syntaxhighlight.cxx +++ b/comphelper/source/misc/syntaxhighlight.cxx @@ -529,10 +529,6 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, if( cNext != c && testCharFlags( cNext, CHAR_EOL ) == sal_True ) getChar(); - // Set position data at the line start - nCol = 0; - nLine++; - reType = TT_EOL; } @@ -635,15 +631,11 @@ SimpleTokenizer_Impl* getSimpleTokenizer( void ) return pSimpleTokenizer; } -sal_uInt16 SimpleTokenizer_Impl::parseLine( sal_uInt32 nParseLine, const OUString* aSource ) +sal_uInt16 SimpleTokenizer_Impl::parseLine( const OUString* aSource ) { // Set the position to the beginning of the source string mpStringBegin = mpActualPos = aSource->getStr(); - // Initialize row and column - nLine = nParseLine; - nCol = 0L; - // Variables for the out parameter TokenTypes eType; const sal_Unicode* pStartPos; @@ -657,16 +649,12 @@ sal_uInt16 SimpleTokenizer_Impl::parseLine( sal_uInt32 nParseLine, const OUStrin return nTokenCount; } -void SimpleTokenizer_Impl::getHighlightPortions( sal_uInt32 nParseLine, const OUString& rLine, +void SimpleTokenizer_Impl::getHighlightPortions( const OUString& rLine, /*out*/std::vector<HighlightPortion>& portions ) { // Set the position to the beginning of the source string mpStringBegin = mpActualPos = rLine.getStr(); - // Initialize row and column - nLine = nParseLine; - nCol = 0L; - // Variables for the out parameter TokenTypes eType; const sal_Unicode* pStartPos; @@ -716,19 +704,17 @@ void SyntaxHighlighter::initialize( HighlighterLanguage eLanguage_ ) } } -void SyntaxHighlighter::notifyChange( sal_uInt32 nLine, sal_Int32 nLineCountDifference, - const OUString* pChangedLines, sal_uInt32 nArrayLength) +void SyntaxHighlighter::notifyChange( + const OUString* pChangedLines, sal_uInt32 nArrayLength) { - (void)nLineCountDifference; - for( sal_uInt32 i=0 ; i < nArrayLength ; i++ ) - m_pSimpleTokenizer->parseLine(nLine+i, &pChangedLines[i]); + m_pSimpleTokenizer->parseLine(&pChangedLines[i]); } -void SyntaxHighlighter::getHighlightPortions( sal_uInt32 nLine, const OUString& rLine, +void SyntaxHighlighter::getHighlightPortions( const OUString& rLine, /*out*/std::vector<HighlightPortion>& portions ) { - m_pSimpleTokenizer->getHighlightPortions( nLine, rLine, portions ); + m_pSimpleTokenizer->getHighlightPortions( rLine, portions ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/helpcompiler/source/BasCodeTagger.cxx b/helpcompiler/source/BasCodeTagger.cxx index 6e698f5..782bcdc 100644 --- a/helpcompiler/source/BasCodeTagger.cxx +++ b/helpcompiler/source/BasCodeTagger.cxx @@ -149,9 +149,9 @@ void BasicCodeTagger::tagParagraph( xmlNodePtr paragraph ) OUString strLine( reinterpret_cast<const sal_Char*>(codeSnippet), strlen(reinterpret_cast<const char*>(codeSnippet)), RTL_TEXTENCODING_UTF8 ); - m_Highlighter.notifyChange ( 0, 0, &strLine, 1 ); + m_Highlighter.notifyChange ( &strLine, 1 ); std::vector<HighlightPortion> portions; - m_Highlighter.getHighlightPortions( 0, strLine, portions ); + m_Highlighter.getHighlightPortions( strLine, portions ); for (std::vector<HighlightPortion>::iterator i(portions.begin()); i != portions.end(); ++i) { diff --git a/include/comphelper/syntaxhighlight.hxx b/include/comphelper/syntaxhighlight.hxx index dc1631a..cbeb95e 100644 --- a/include/comphelper/syntaxhighlight.hxx +++ b/include/comphelper/syntaxhighlight.hxx @@ -88,12 +88,8 @@ class SimpleTokenizer_Impl const sal_Unicode* mpStringBegin; const sal_Unicode* mpActualPos; - // Lines and columns - sal_uInt32 nLine; - sal_uInt32 nCol; - sal_Unicode peekChar( void ) { return *mpActualPos; } - sal_Unicode getChar( void ) { nCol++; return *mpActualPos++; } + sal_Unicode getChar( void ) { return *mpActualPos++; } // Auxiliary function: testing of the character flags sal_Bool testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags ); @@ -109,8 +105,8 @@ public: SimpleTokenizer_Impl( HighlighterLanguage aLang = HIGHLIGHT_BASIC ); ~SimpleTokenizer_Impl( void ); - sal_uInt16 parseLine( sal_uInt32 nLine, const OUString* aSource ); - void getHighlightPortions( sal_uInt32 nParseLine, const OUString& rLine, + sal_uInt16 parseLine( const OUString* aSource ); + void getHighlightPortions( const OUString& rLine, /*out*/std::vector<HighlightPortion>& portions ); void setKeyWords( const char** ppKeyWords, sal_uInt16 nCount ); }; @@ -136,13 +132,11 @@ public: // (Re-)initialize Highlighter. The line-table will be completely erased, // meaning that on completion an empty Source is assumed. - // notifyChange() can only be given line 0 void initialize( HighlighterLanguage eLanguage_ ); - void notifyChange( sal_uInt32 nLine, sal_Int32 nLineCountDifference, - const OUString* pChangedLines, sal_uInt32 nArrayLength); + void notifyChange(const OUString* pChangedLines, sal_uInt32 nArrayLength); - void getHighlightPortions( sal_uInt32 nLine, const OUString& rLine, + void getHighlightPortions( const OUString& rLine, std::vector<HighlightPortion>& pPortions ); HighlighterLanguage GetLanguage() { return eLanguage;} diff --git a/svtools/source/edit/editsyntaxhighlighter.cxx b/svtools/source/edit/editsyntaxhighlighter.cxx index ba1aca2..d84fc15 100644 --- a/svtools/source/edit/editsyntaxhighlighter.cxx +++ b/svtools/source/edit/editsyntaxhighlighter.cxx @@ -171,11 +171,11 @@ void MultiLineEditSyntaxHighlight::UpdateData() for (unsigned int nLine=0; nLine < GetTextEngine()->GetParagraphCount(); nLine++) { OUString aLine( GetTextEngine()->GetText( nLine ) ); - aHighlighter.notifyChange( nLine, 0, &aLine, 1 ); + aHighlighter.notifyChange( &aLine, 1 ); GetTextEngine()->RemoveAttribs( nLine, sal_True ); std::vector<HighlightPortion> aPortions; - aHighlighter.getHighlightPortions( nLine, aLine, aPortions ); + aHighlighter.getHighlightPortions( aLine, aPortions ); for (std::vector<HighlightPortion>::iterator i(aPortions.begin()); i != aPortions.end(); ++i) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits