File: stringhelpers.h

package info (click to toggle)
kdevelop 4%3A5.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 57,892 kB
  • sloc: cpp: 278,773; javascript: 3,558; python: 3,385; sh: 1,317; ansic: 689; xml: 273; php: 95; makefile: 40; lisp: 13; sed: 12
file content (148 lines) | stat: -rw-r--r-- 5,348 bytes parent folder | download
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
   Copyright 2007 David Nolden <david.nolden.kdevelop@art-master.de>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
 */

#ifndef KDEVPLATFORM_STRINGHELPERS_H
#define KDEVPLATFORM_STRINGHELPERS_H

#include <language/languageexport.h>

#include <QChar>
#include <QScopedPointer>

class QByteArray;
class QString;
class QStringList;

namespace KDevelop {
class ParamIteratorPrivate;

/**
 * Searches a fitting closing brace from left to right: a ')' for '(', ']' for '[', ...
 */
int KDEVPLATFORMLANGUAGE_EXPORT findClose(const QString& str, int pos);

/**
 * Searches in the given string for a ',' or closing brace,
 * while skipping everything between opened braces.
 * @param str string to search
 * @param pos position where to start searching
 * @param validEnd when this is set differently, the function will stop when it finds a comma or the given character, and not at closing-braces.
 * @return  On fail, str.length() is returned, else the position of the closing character.
 */
int KDEVPLATFORMLANGUAGE_EXPORT findCommaOrEnd(const QString& str, int pos, QChar validEnd = QLatin1Char( ' ' ));

/**
 * Skips in the string backwards over function-arguments, and stops at the right side of a "("
 * @param str string to skip
 * @param skippedArguments Will contain all skipped arguments
 * @param argumentsStart Should be set to the position where the seeking should start, will be changed to the right side of a "(" when found. Should be at the right side of a '(', and may be max. str.length()
 */
void KDEVPLATFORMLANGUAGE_EXPORT skipFunctionArguments(const QString& str, QStringList& skippedArguments,
                                                       int& argumentsStart);

/**
 * Removes white space at the beginning and end, and replaces contiguous inner white-spaces with single white-spaces. Newlines are treated as whitespaces, the returned text will have no more newlines.
 */
QString KDEVPLATFORMLANGUAGE_EXPORT reduceWhiteSpace(const QString& str);

QString KDEVPLATFORMLANGUAGE_EXPORT stripFinalWhitespace(const QString& str);
//
/**
 * Fills all c++-style comments  within the given code with the given 'replacement' character
 * Newlines are preserved.
 */
QString KDEVPLATFORMLANGUAGE_EXPORT clearComments(const QString& str, QChar replacement = QLatin1Char( ' ' ));
/**
 * Fills all c++-strings within the given code with the given 'replacement' character
 * Comments should have been removed before.
 */
QString KDEVPLATFORMLANGUAGE_EXPORT clearStrings(const QString& str, QChar replacement = QLatin1Char( ' ' ));

/**
 * Extracts the interesting information out of a comment.
 * For example it removes all the stars at the beginning, and re-indents the text.
 */
QString KDEVPLATFORMLANGUAGE_EXPORT formatComment(const QString& comment);

/**
 * Extracts the interesting information out of a comment.
 * For example it removes all the stars at the beginning, and re-indents the text.
 */
QByteArray KDEVPLATFORMLANGUAGE_EXPORT formatComment(const QByteArray& comment);

/**
 * Remove characters in @p str from the end of @p from
 *
 * @return number of stripped characters
 */
int KDEVPLATFORMLANGUAGE_EXPORT rStrip(const QByteArray& str, QByteArray& from);

/**
 * Remove characters in @p str from the beginning of @p from
 *
 * @return number of stripped characters
 */
int KDEVPLATFORMLANGUAGE_EXPORT strip(const QByteArray& str, QByteArray& from);

/**
 * Removes all whitespace from the string
 */
QString KDEVPLATFORMLANGUAGE_EXPORT removeWhitespace(const QString& str);

/**
 * Can be used to iterate through different kinds of parameters, for example template-parameters
 */
class KDEVPLATFORMLANGUAGE_EXPORT ParamIterator
{
public:
    /**
     * @param parens Should be a string containing the two parens between which the parameters are searched.
     * Example: "<>" or "()" Optionally it can also contain one third end-character.
     * If that end-character is encountered in the prefix, the iteration will be stopped.
     *
     * Example: When "<>:" is given, ParamIterator will only parse the first identifier of a C++ scope
     */
    ParamIterator(const QString& parens, const QString& source, int start = 0);
    ~ParamIterator();

    ParamIterator& operator ++();

    /**
     * Returns current found parameter
     */
    QString operator *();

    /**
     * Returns whether there is a current found parameter
     */
    operator bool() const;

    /**
     * Returns the text in front of the first opening-paren(if none found then the whole text)
     */
    QString prefix() const;

    uint position() const;

private:
    const QScopedPointer<class ParamIteratorPrivate> d_ptr;
    Q_DECLARE_PRIVATE(ParamIterator)
};
}

#endif