summaryrefslogtreecommitdiff
path: root/src/libs/cplusplus/ExpressionUnderCursor.cpp
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2009-09-17 15:44:54 +0200
committerRoberto Raggi <roberto.raggi@nokia.com>2009-09-17 15:51:15 +0200
commitdfa6be721d845e41eeac6d91b7b04c08cf975859 (patch)
tree0c602af2a683d3c711c0aaa570879e59d9c93aa4 /src/libs/cplusplus/ExpressionUnderCursor.cpp
parent97df3b6ccaa3a10af65a969e255aa201becb60e1 (diff)
downloadqt-creator-dfa6be721d845e41eeac6d91b7b04c08cf975859.tar.gz
Added the helper class MatchingText and use it to automagically insert text for curly braces.
Diffstat (limited to 'src/libs/cplusplus/ExpressionUnderCursor.cpp')
-rw-r--r--src/libs/cplusplus/ExpressionUnderCursor.cpp54
1 files changed, 7 insertions, 47 deletions
diff --git a/src/libs/cplusplus/ExpressionUnderCursor.cpp b/src/libs/cplusplus/ExpressionUnderCursor.cpp
index 1cc546de22..622b420048 100644
--- a/src/libs/cplusplus/ExpressionUnderCursor.cpp
+++ b/src/libs/cplusplus/ExpressionUnderCursor.cpp
@@ -43,46 +43,6 @@ ExpressionUnderCursor::ExpressionUnderCursor()
ExpressionUnderCursor::~ExpressionUnderCursor()
{ }
-int ExpressionUnderCursor::startOfMatchingBrace(BackwardsScanner &tk, int index)
-{
- if (tk[index - 1].is(T_RPAREN)) {
- int i = index - 1;
- int count = 0;
- do {
- if (tk[i].is(T_LPAREN)) {
- if (! ++count)
- return i;
- } else if (tk[i].is(T_RPAREN))
- --count;
- --i;
- } while (count != 0 && tk[i].isNot(T_EOF_SYMBOL));
- } else if (tk[index - 1].is(T_RBRACKET)) {
- int i = index - 1;
- int count = 0;
- do {
- if (tk[i].is(T_LBRACKET)) {
- if (! ++count)
- return i;
- } else if (tk[i].is(T_RBRACKET))
- --count;
- --i;
- } while (count != 0 && tk[i].isNot(T_EOF_SYMBOL));
- } else if (tk[index - 1].is(T_GREATER)) {
- int i = index - 1;
- int count = 0;
- do {
- if (tk[i].is(T_LESS)) {
- if (! ++count)
- return i;
- } else if (tk[i].is(T_GREATER))
- --count;
- --i;
- } while (count != 0 && tk[i].isNot(T_EOF_SYMBOL));
- }
-
- return index;
-}
-
int ExpressionUnderCursor::startOfExpression(BackwardsScanner &tk, int index)
{
// tk is a reference to a const QList. So, don't worry about [] access.
@@ -122,10 +82,10 @@ int ExpressionUnderCursor::startOfExpression(BackwardsScanner &tk, int index)
}
return index - 1;
} else if (tk[index - 1].is(T_RPAREN)) {
- int rparenIndex = startOfMatchingBrace(tk, index);
+ int rparenIndex = tk.startOfMatchingBrace(index);
if (rparenIndex != index) {
if (tk[rparenIndex - 1].is(T_GREATER)) {
- int lessIndex = startOfMatchingBrace(tk, rparenIndex);
+ int lessIndex = tk.startOfMatchingBrace(rparenIndex);
if (lessIndex != rparenIndex - 1) {
if (tk[lessIndex - 1].is(T_DYNAMIC_CAST) ||
tk[lessIndex - 1].is(T_STATIC_CAST) ||
@@ -144,13 +104,13 @@ int ExpressionUnderCursor::startOfExpression(BackwardsScanner &tk, int index)
}
return index;
} else if (tk[index - 1].is(T_RBRACKET)) {
- int rbracketIndex = startOfMatchingBrace(tk, index);
+ int rbracketIndex = tk.startOfMatchingBrace(index);
if (rbracketIndex != index)
return startOfExpression(tk, rbracketIndex);
return index;
} else if (tk[index - 1].is(T_COLON_COLON)) {
if (tk[index - 2].is(T_GREATER)) { // ### not exactly
- int lessIndex = startOfMatchingBrace(tk, index - 1);
+ int lessIndex = tk.startOfMatchingBrace(index - 1);
if (lessIndex != index - 1)
return startOfExpression(tk, lessIndex);
return index - 1;
@@ -185,7 +145,7 @@ QString ExpressionUnderCursor::operator()(const QTextCursor &cursor)
_jumpedComma = false;
- const int initialSize = scanner.tokens().size();
+ const int initialSize = scanner.startToken();
const int i = startOfExpression(scanner, initialSize);
if (i == initialSize)
return QString();
@@ -199,7 +159,7 @@ int ExpressionUnderCursor::startOfFunctionCall(const QTextCursor &cursor)
BackwardsScanner scanner(cursor);
- int index = scanner.tokens().size();
+ int index = scanner.startToken();
forever {
const SimpleToken &tk = scanner[index - 1];
@@ -209,7 +169,7 @@ int ExpressionUnderCursor::startOfFunctionCall(const QTextCursor &cursor)
else if (tk.is(T_LPAREN))
return scanner.startPosition() + tk.position();
else if (tk.is(T_RPAREN)) {
- int matchingBrace = startOfMatchingBrace(scanner, index);
+ int matchingBrace = scanner.startOfMatchingBrace(index);
if (matchingBrace == index) // If no matching brace found
return -1;