summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2016-02-24 10:11:43 +0200
committerNoel Grandin <noel@peralex.com>2016-02-24 11:48:39 +0200
commita5e53f9ffdde320a7ba104a1e01b3f5ef75d7975 (patch)
tree49ebc3303916da8298183808630464a4c0ce00d8 /comphelper
parent2f9d53df89614955215a630beb0966f0c4a663c2 (diff)
convert TokenTypes to scoped enum
Change-Id: I17c0a616dd6cf48a22896b6cd6b0df157d1f9a9f
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/qa/unit/syntaxhighlighttest.cxx19
-rw-r--r--comphelper/source/misc/syntaxhighlight.cxx50
2 files changed, 37 insertions, 32 deletions
diff --git a/comphelper/qa/unit/syntaxhighlighttest.cxx b/comphelper/qa/unit/syntaxhighlighttest.cxx
index 5297bf12ffd7..848c741c3f2f 100644
--- a/comphelper/qa/unit/syntaxhighlighttest.cxx
+++ b/comphelper/qa/unit/syntaxhighlighttest.cxx
@@ -37,6 +37,11 @@ public:
CPPUNIT_TEST_SUITE_END();
};
+std::ostream& operator<<(std::ostream& rStrm, const TokenType& tt)
+{
+ return rStrm << (int)tt;
+}
+
void SyntaxHighlightTest::testBasicString() {
OUString s("\"foo\"");
std::vector<HighlightPortion> ps;
@@ -45,7 +50,7 @@ void SyntaxHighlightTest::testBasicString() {
static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size());
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin);
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[0].nEnd);
- CPPUNIT_ASSERT_EQUAL(TT_STRING, ps[0].tokenType);
+ CPPUNIT_ASSERT_EQUAL(TokenType::String, ps[0].tokenType);
}
void SyntaxHighlightTest::testBasicComment() {
@@ -56,7 +61,7 @@ void SyntaxHighlightTest::testBasicComment() {
static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size());
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin);
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[0].nEnd);
- CPPUNIT_ASSERT_EQUAL(TT_COMMENT, ps[0].tokenType);
+ CPPUNIT_ASSERT_EQUAL(TokenType::Comment, ps[0].tokenType);
}
void SyntaxHighlightTest::testBasicCommentNewline() {
@@ -67,10 +72,10 @@ void SyntaxHighlightTest::testBasicCommentNewline() {
static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size());
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin);
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[0].nEnd);
- CPPUNIT_ASSERT_EQUAL(TT_COMMENT, ps[0].tokenType);
+ CPPUNIT_ASSERT_EQUAL(TokenType::Comment, ps[0].tokenType);
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[1].nBegin);
CPPUNIT_ASSERT_EQUAL(sal_Int32(6), ps[1].nEnd);
- CPPUNIT_ASSERT_EQUAL(TT_EOL, ps[1].tokenType);
+ CPPUNIT_ASSERT_EQUAL(TokenType::EOL, ps[1].tokenType);
}
void SyntaxHighlightTest::testBasicEmptyComment() {
@@ -81,7 +86,7 @@ void SyntaxHighlightTest::testBasicEmptyComment() {
static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size());
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ps[0].nEnd);
- CPPUNIT_ASSERT_EQUAL(TT_COMMENT, ps[0].tokenType);
+ CPPUNIT_ASSERT_EQUAL(TokenType::Comment, ps[0].tokenType);
}
void SyntaxHighlightTest::testBasicEmptyCommentNewline() {
@@ -92,10 +97,10 @@ void SyntaxHighlightTest::testBasicEmptyCommentNewline() {
static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size());
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ps[0].nEnd);
- CPPUNIT_ASSERT_EQUAL(TT_COMMENT, ps[0].tokenType);
+ CPPUNIT_ASSERT_EQUAL(TokenType::Comment, ps[0].tokenType);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ps[1].nBegin);
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), ps[1].nEnd);
- CPPUNIT_ASSERT_EQUAL(TT_EOL, ps[1].tokenType);
+ CPPUNIT_ASSERT_EQUAL(TokenType::EOL, ps[1].tokenType);
}
void SyntaxHighlightTest::testBasic()
diff --git a/comphelper/source/misc/syntaxhighlight.cxx b/comphelper/source/misc/syntaxhighlight.cxx
index 625490875567..639a957168c7 100644
--- a/comphelper/source/misc/syntaxhighlight.cxx
+++ b/comphelper/source/misc/syntaxhighlight.cxx
@@ -265,7 +265,7 @@ class SyntaxHighlighter::Tokenizer
bool testCharFlags(sal_Unicode c, sal_uInt16 nTestFlags) const;
// Get new token, EmptyString == nothing more over there
- bool getNextToken(const sal_Unicode*& pos, /*out*/TokenTypes& reType,
+ bool getNextToken(const sal_Unicode*& pos, /*out*/TokenType& reType,
/*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos) const;
const char** ppListKeyWords;
@@ -304,10 +304,10 @@ void SyntaxHighlighter::Tokenizer::setKeyWords( const char** ppKeyWords, sal_uIn
nKeyWordCount = nCount;
}
-bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/TokenTypes& reType,
+bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/TokenType& reType,
/*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos) const
{
- reType = TT_UNKNOWN;
+ reType = TokenType::Unknown;
rpStartPos = pos;
@@ -324,7 +324,7 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
while( testCharFlags( *pos, CHAR_SPACE ) )
++pos;
- reType = TT_WHITESPACE;
+ reType = TokenType::Whitespace;
}
// Identifier?
@@ -341,7 +341,7 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
}
while( bIdentifierChar );
- reType = TT_IDENTIFIER;
+ reType = TokenType::Identifier;
// Keyword table
if (ppListKeyWords != nullptr)
@@ -367,7 +367,7 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
if ( bsearch( aByteStr.getStr(), ppListKeyWords, nKeyWordCount, sizeof( char* ),
compare_strings ) )
{
- reType = TT_KEYWORDS;
+ reType = TokenType::Keywords;
if( aByteStr == "rem" )
{
@@ -378,7 +378,7 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
cPeek = *++pos;
}
- reType = TT_COMMENT;
+ reType = TokenType::Comment;
}
}
}
@@ -405,7 +405,7 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
}
while( bIdentifierChar );
}
- reType = TT_PARAMETER;
+ reType = TokenType::Parameter;
}
else if (c=='-')
{
@@ -418,7 +418,7 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
++pos;
cPeekNext = *pos;
}
- reType = TT_COMMENT;
+ reType = TokenType::Comment;
}
}
else if (c=='/')
@@ -432,7 +432,7 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
++pos;
cPeekNext = *pos;
}
- reType = TT_COMMENT;
+ reType = TokenType::Comment;
}
}
else
@@ -449,14 +449,14 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
++pos;
}
- reType = TT_COMMENT;
+ reType = TokenType::Comment;
}
// The real operator; can be easily used since not the actual
// operator (e.g. +=) is concerned, but the fact that it is one
- if( reType != TT_COMMENT )
+ if( reType != TokenType::Comment )
{
- reType = TT_OPERATOR;
+ reType = TokenType::Operator;
}
}
@@ -465,13 +465,13 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
// Object separator? Must be handled before Number
else if( c == '.' && ( *pos < '0' || *pos > '9' ) )
{
- reType = TT_OPERATOR;
+ reType = TokenType::Operator;
}
// Number?
else if( testCharFlags( c, CHAR_START_NUMBER ) )
{
- reType = TT_NUMBER;
+ reType = TokenType::Number;
// Number system, 10 = normal, it is changed for Oct/Hex
int nRadix = 10;
@@ -503,12 +503,12 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
}
else
{
- reType = TT_OPERATOR;
+ reType = TokenType::Operator;
}
}
// When it is not Oct or Hex, then it is double
- if( reType == TT_NUMBER && nRadix == 10 )
+ if( reType == TokenType::Number && nRadix == 10 )
{
// Flag if the last character is an exponent
bool bAfterExpChar = false;
@@ -540,25 +540,25 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
if( *pos == 0 )
{
// ERROR: unterminated string literal
- reType = TT_ERROR;
+ reType = TokenType::Error;
break;
}
c = *pos++;
if( testCharFlags( c, CHAR_EOL ) )
{
// ERROR: unterminated string literal
- reType = TT_ERROR;
+ reType = TokenType::Error;
break;
}
}
- if( reType != TT_ERROR )
+ if( reType != TokenType::Error )
{
++pos;
if( cEndString == ']' )
- reType = TT_IDENTIFIER;
+ reType = TokenType::Identifier;
else
- reType = TT_STRING;
+ reType = TokenType::String;
}
}
@@ -570,10 +570,10 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
if( cNext != c && testCharFlags( cNext, CHAR_EOL ) )
++pos;
- reType = TT_EOL;
+ reType = TokenType::EOL;
}
- // All other will remain TT_UNKNOWN
+ // All other will remain TokenType::Unknown
// Save end position
rpEndPos = pos;
@@ -672,7 +672,7 @@ void SyntaxHighlighter::Tokenizer::getHighlightPortions(const OUString& rLine,
const sal_Unicode* pos = rLine.getStr();
// Variables for the out parameter
- TokenTypes eType;
+ TokenType eType;
const sal_Unicode* pStartPos;
const sal_Unicode* pEndPos;