~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/cpp/stringhelpers.h

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/***************************************************************************
3
 
   copyright            : (C) 2006 by David Nolden
4
 
   email                : david.nolden.kdevelop@art-master.de
5
 
***************************************************************************/
6
 
 
7
 
/***************************************************************************
8
 
 *                                                                         *
9
 
 *   This program is free software; you can redistribute it and/or modify  *
10
 
 *   it under the terms of the GNU General Public License as published by  *
11
 
 *   the Free Software Foundation; either version 2 of the License, or     *
12
 
 *   (at your option) any later version.                                   *
13
 
 *                                                                         *
14
 
 ***************************************************************************/
 
1
/* 
 
2
   Copyright 2007 David Nolden <david.nolden.kdevelop@art-master.de>
 
3
 
 
4
   This library is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public
 
6
   License version 2 as published by the Free Software Foundation.
 
7
 
 
8
   This library is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
   Library General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU Library General Public License
 
14
   along with this library; see the file COPYING.LIB.  If not, write to
 
15
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
16
   Boston, MA 02110-1301, USA.
 
17
*/
15
18
 
16
19
#ifndef __STRINGHELPERS_H__
17
20
#define __STRINGHELPERS_H__
18
21
 
19
 
 
20
 
#include "completiondebug.h"
21
 
#include "codeinformationrepository.h"
22
 
 
23
 
 
24
 
namespace StringHelpers {
25
 
 
26
 
void clearStr( QString& str, int start, int end );
27
 
 
28
 
///Fills all comments with whitespaces
29
 
QString clearComments( QString str );
30
 
 
31
 
QString cutTemplateParams( QString str );
32
 
 
33
 
QPair<QString, QString> splitTemplateParams( QString str );
34
 
 
35
 
bool parenFits( QChar c1, QChar c2 );
36
 
 
37
 
bool isParen( QChar c1 );
38
 
 
39
 
bool isTypeParen( QChar c1 );
40
 
 
41
 
bool isTypeOpenParen( QChar c1 );
42
 
 
43
 
bool isTypeCloseParen( QChar c1 );
44
 
 
45
 
bool isLeftParen( QChar c1 );
46
 
 
47
 
/*only from left to right
48
 
searches a fitting closing sign ( a ')' for a '(', ']' for '['
49
 
ignores quoted text
50
 
comments are currently not allowed */
51
 
int findClose( const QString& str , int pos ); //todo: make this respect strings
52
 
 
53
 
QString tagType( const Tag& tag );
54
 
 
55
 
int findCommaOrEnd( const QString& str , int pos, QChar validEnd = ' ' );
56
 
 
57
 
int countExtract( QChar c, const QString& str );
58
 
 
59
 
QString templateParamFromString( int num, QString str );
60
 
 
61
 
QStringList splitType( QString str ) ;
62
 
 
63
 
class ParamIterator {
64
 
  public:
65
 
    ParamIterator( QString parens, QString source ) : m_source( source ), m_parens( parens ), m_cur( 0 ), m_curEnd ( 0 ) {
66
 
      int begin = m_source.find( m_parens[ 0 ] );
67
 
      int end = m_source.findRev( m_parens[ 1 ] );
68
 
            m_prefix = m_source.left( begin );
69
 
            
70
 
      if ( begin == -1 || end == -1 && end - begin > 1 )
71
 
        m_cur = m_source.length();
72
 
      else {
73
 
        m_source = source.mid( begin + 1, end - begin );
74
 
        m_curEnd = next();
75
 
      }
76
 
    }
77
 
 
78
 
    ParamIterator& operator ++() {
79
 
      m_cur = m_curEnd + 1;
80
 
      if ( m_cur < ( int ) m_source.length() ) {
81
 
        m_curEnd = next();
82
 
      }
83
 
      return *this;
84
 
    }
85
 
 
86
 
    QString operator *() {
87
 
      return m_source.mid( m_cur, m_curEnd - m_cur ).stripWhiteSpace();
88
 
    }
89
 
 
90
 
    operator bool() const {
91
 
      return m_cur < ( int ) m_source.length();
92
 
    }
93
 
 
94
 
    QString prefix() const {
95
 
            return m_prefix;
96
 
    }
97
 
 
98
 
  private:
99
 
                QString m_prefix;
100
 
    QString m_source;
101
 
    QString m_parens;
102
 
    int m_cur;
103
 
    int m_curEnd;
104
 
 
105
 
    int next() {
106
 
      return findCommaOrEnd( m_source, m_cur, m_parens[ 1 ] );
107
 
    }
108
 
 
109
 
};
110
 
 
111
 
bool isValidIdentifierSign( const QChar& c );
112
 
 
113
 
QString stringMult( int count, QString str );
 
22
#include <language/duchain/stringhelpers.h>
 
23
 
 
24
class QString;
 
25
class QChar;
 
26
class QStringList;
 
27
 
 
28
namespace Utils {
 
29
 
 
30
/**
 
31
 * Copied from kdevelop-3.4, should be redone
 
32
 * @param index should be the index BEHIND the expression
 
33
 * */
 
34
int expressionAt( const QString& contents, int index );
 
35
 
114
36
}
115
 
 
116
 
 
117
37
#endif 
118
 
// kate: tab-width 2;