[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdevelop/languages/cpp/parser
From: Nikolaus Sams <niko.sams () gmail ! com>
Date: 2008-09-20 21:03:20
Message-ID: 1221944600.929247.11263.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 863060 by nsams:
Moved formatComment into KDevPlatform so other languages can use it too
M +2 -83 commentformatter.cpp
M +0 -6 commentformatter.h
--- trunk/KDE/kdevelop/languages/cpp/parser/commentformatter.cpp #863059:863060
@@ -22,60 +22,14 @@
#include "parsesession.h"
#include "lexer.h"
#include "rpp/chartools.h"
+#include <language/duchain/stringhelpers.h>
-void CommentFormatter::rStrip( const QString& str, QString& from ) {
- if( str.isEmpty() ) return;
- int i = 0;
- int ip = from.length();
- int s = from.length();
-
- for( int a = s-1; a >= 0; a-- ) {
- if( isWhite( from[a] ) ) {
- continue;
- } else {
- if( from[a] == str[i] ) {
- i++;
- ip = a;
- if( i == (int)str.length() ) break;
- } else {
- break;
- }
- }
- }
-
- if( ip != (int)from.length() ) from = from.left( ip );
-}
-
-void CommentFormatter::strip( const QString& str, QString& from ) {
- if( str.isEmpty() ) return;
-
- int i = 0;
- int ip = 0;
- int s = from.length();
-
- for( int a = 0; a < s; a++ ) {
- if( isWhite( from[a] ) ) {
- continue;
- } else {
- if( from[a] == str[i] ) {
- i++;
- ip = a+1;
- if( i == (int)str.length() ) break;
- } else {
- break;
- }
- }
- }
-
- if( ip ) from = from.mid( ip );
-}
-
QString CommentFormatter::formatComment( size_t token, const ParseSession* session ) \
{ if( !token )
return QString();
const Token& commentToken( (*session->token_stream)[token] );
- return formatComment( stringFromContents(session->contentsVector(), \
commentToken.position, commentToken.size ) ); + return KDevelop::formatComment( \
stringFromContents(session->contentsVector(), commentToken.position, \
commentToken.size ) ); }
QString CommentFormatter::formatComment( const ListNode<size_t>* comments, const \
ParseSession* session ) { @@ -98,38 +52,3 @@
return ret;
}
-QString CommentFormatter::formatComment( const QString& comment ) {
- QString ret;
- int i = 0;
-
- if( i > 1 ) {
- ret = comment.mid( i );
- } else {
- ///remove the star in each line
- QStringList lines = comment.split( "\n", QString::KeepEmptyParts );
-
- if( lines.isEmpty() ) return ret;
-
- QStringList::iterator it = lines.begin();
- QStringList::iterator eit = lines.end();
-
- if( it != lines.end() ) {
-
- for( ; it != eit; ++it ) {
- strip( "//", *it );
- strip( "**", *it );
- rStrip( "/**", *it );
- }
-
- if( lines.front().trimmed().isEmpty() )
- lines.pop_front();
-
- if( !lines.isEmpty() && lines.back().trimmed().isEmpty() )
- lines.pop_back();
- }
-
- ret = lines.join( "\n" );
- }
-
- return ret;
-}
--- trunk/KDE/kdevelop/languages/cpp/parser/commentformatter.h #863059:863060
@@ -34,18 +34,12 @@
class KDEVCPPPARSER_EXPORT CommentFormatter {
public:
- static QString formatComment( const QString& comment );
///Processes the comment represented by the given token-number within the \
parse-session's token-stream
static QString formatComment( size_t token, const ParseSession* session );
///Processes the list of comments represented by the given token-number within \
the parse-session's token-stream
static QString formatComment( const ListNode<size_t>* node, const ParseSession* \
session ); private:
- static inline bool isWhite( QChar c ) {
- return c.isSpace();
- }
- static void rStrip( const QString& str, QString& from );
- static void strip( const QString& str, QString& from );
};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic