summaryrefslogtreecommitdiffstats
path: root/languages/cpp/stringhelpers.h
blob: 33e0182700198f96e06264eea35fdd60218b8baf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

/***************************************************************************
   copyright            : (C) 2006 by David Nolden
   email                : [email protected]
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef __STRINGHELPERS_H__
#define __STRINGHELPERS_H__


#include "completiondebug.h"
#include "codeinformationrepository.h"


namespace StringHelpers {

void clearStr( TQString& str, int start, int end );

///Fills all comments with whitespaces
TQString clearComments( TQString str );

TQString cutTemplateParams( TQString str );

TQPair<TQString, TQString> splitTemplateParams( TQString str );

bool parenFits( TQChar c1, TQChar c2 );

bool isParen( TQChar c1 );

bool isTypeParen( TQChar c1 );

bool isTypeOpenParen( TQChar c1 );

bool isTypeCloseParen( TQChar c1 );

bool isLeftParen( TQChar c1 );

/*only from left to right
searches a fitting closing sign ( a ')' for a '(', ']' for '['
ignores quoted text
comments are currently not allowed */
int findClose( const TQString& str , int pos ); //todo: make this respect strings

TQString tagType( const Tag& tag );

int findCommaOrEnd( const TQString& str , int pos, TQChar validEnd = ' ' );

int countExtract( TQChar c, const TQString& str );

TQString templateParamFromString( int num, TQString str );

TQStringList splitType( TQString str ) ;

class ParamIterator {
  public:
    ParamIterator( TQString parens, TQString source ) : m_source( source ), m_parens( parens ), m_cur( 0 ), m_curEnd ( 0 ) {
      int begin = m_source.find( m_parens[ 0 ] );
      int end = m_source.findRev( m_parens[ 1 ] );
	    m_prefix = m_source.left( begin );
	    
      if ( begin == -1 || end == -1 && end - begin > 1 )
        m_cur = m_source.length();
      else {
        m_source = source.mid( begin + 1, end - begin );
        m_curEnd = next();
      }
    }

    ParamIterator& operator ++() {
      m_cur = m_curEnd + 1;
      if ( m_cur < ( int ) m_source.length() ) {
        m_curEnd = next();
      }
      return *this;
    }

    TQString operator *() {
      return m_source.mid( m_cur, m_curEnd - m_cur ).stripWhiteSpace();
    }

    operator bool() const {
      return m_cur < ( int ) m_source.length();
    }

    TQString prefix() const {
	    return m_prefix;
    }

  private:
		TQString m_prefix;
    TQString m_source;
    TQString m_parens;
    int m_cur;
    int m_curEnd;

    int next() {
      return findCommaOrEnd( m_source, m_cur, m_parens[ 1 ] );
    }

};

bool isValidIdentifierSign( const TQChar& c );

TQString stringMult( int count, TQString str );
}


#endif 
// kate: tab-width 2;