[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kate/part
From: Tim Hutt <tdh29 () cam ! ac ! uk>
Date: 2006-08-27 22:54:41
Message-ID: 1156719281.136062.7427.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 577948 by thutt:
CCBUG: 113033
Fix in KDE 4.
M +50 -27 kateautoindent.cpp
--- trunk/KDE/kdelibs/kate/part/kateautoindent.cpp #577947:577948
@@ -33,6 +33,8 @@
#include <kdebug.h>
#include <kmenu.h>
+#include <cctype>
+
//BEGIN KateAutoIndent
KateAutoIndent *KateAutoIndent::createIndenter (KateDocument *doc, const QString &name)
@@ -1641,42 +1643,63 @@
*/
bool KateCSAndSIndent::startsWithLabel( int line )
{
- KateTextLine::Ptr indentLine = doc->plainKateTextLine( line );
+ // Get the current line.
+ KateTextLine::Ptr indentLine = doc->plainKateTextLine(line);
const int indentFirst = indentLine->firstChar();
-
+
+ // This kind of messes up Q_OBJECT\n public: but I'll leave it for now.
+ // Otherwise it messes up other cases.
int attrib = indentLine->attribute(indentFirst);
if (attrib != 0 && attrib != keywordAttrib && attrib != normalAttrib && attrib != extensionAttrib)
return false;
+
+ // Get the line text.
+ const QString lineContents = indentLine->string();
+ const int indentLast = indentLine->lastChar();
+ bool whitespaceFound = false;
- const QString lineContents = indentLine->string();
- static const QString symbols = QLatin1String(";:[]{}");
- const int last = indentLine->lastChar();
- for ( int n = indentFirst + 1; n <= last; ++n )
+ // Extra checks needed as indentFirst can be -1 in KDE4.
+ for ( int n = indentFirst; n <= indentLast && n >= 0 && n < lineContents.length(); ++n )
{
- QChar c = lineContents[n];
- // FIXME: symbols inside comments are not skipped
- if ( !symbols.contains(c) )
- continue;
-
- // if we find a symbol other than a :, this is not a label.
- if ( c != ':' )
- return false;
-
- // : but not ::, this is a label.
- if ( lineContents[n+1] != ':' )
+ // Get the character as latin1. Can't use QChar::isLetterOrNumber()
+ // as that includes non 0-9 numbers.
+ char c = lineContents[n].toLatin1();
+ if ( c == ':' )
+ {
+ // See if the next character is ':' - if so, skip to the character after it.
+ if ( n < lineContents.length() - 1 )
+ {
+ if ( lineContents[n+1].toLatin1() == ':' )
+ {
+ n += 2;
+ continue;
+ }
+ }
+ // Right this is the relevent ':'.
+ if ( n == indentFirst)
+ {
+ // Just a line with a : on it.
+ return false;
+ }
+ // It is a label of some kind!
return true;
-
- // xy::[^:] is a scope-resolution operator. can occur in case X::Y: for instance.
- // skip both :s and keep going.
- if ( lineContents[n+2] != ':' )
+ }
+ if (isspace(c))
{
- ++n;
- continue;
+ if (!whitespaceFound)
+ {
+ if (lineContents.mid(indentFirst, n - indentFirst) == "case")
+ return true;
+ else if (lineContents.mid(indentFirst, n - indentFirst) == "class")
+ return false;
+ whitespaceFound = true;
+ }
}
-
- // xy::: outside a continuation is a label followed by a scope-resolution operator.
- // more than 3 :s is illegal, so we don't care that's not indented.
- return true;
+ // All other characters don't indent.
+ else if ( !isalnum(c) && c != '_' )
+ {
+ return false;
+ }
}
return false;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic