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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/***************************************************************************
* Copyright (C) 2004 by Paulo Moura Guedes *
* [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. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef STRING_H
#define STRING_H
#include <tqstring.h>
#include <vector>
#include <cctype>
class TQString;
typedef unsigned int uint;
/* Similar to std::string::find but return the next index of the last char
of the first word it finds.
Case insensitive.
e.g.
findWord("Biltre larvado", "biltre") => 6
*/
int findWord(TQString const& s, TQString const& palavra, uint a_partir_do_indice = 0);
/**
Similar to std::string::find but return the next index of the first char
it finds.
Case insensitive.
*/
int findChar(TQString const& s, TQChar letra, uint a_partir_do_indice = 0);
/**
Same as findWord but non space chars are eliminated.
e.g.
findWord("<a href=""></a>", "<a") => 2
findSeparableWord("<a href=""></a>", "<a") => 2
findWord("<\na href=""></a>", "<a") => -1
findSeparableWord("<\na href=""></a>", "<a") => 3
*/
int findSeparableWord(TQString const& s, TQString const& palavra, uint a_partir_do_indice = 0);
/**
Space means Unicode characters with decimal values
9 (TAB), 10 (LF), 11 (VT), 12 (FF), 13 (CR), and 32 (Space).
*/
bool isSpace(TQChar c);
/**
Return -1 if unsuccessful.
*/
int nextNonSpaceChar(TQString const& s, uint i);
int nextNonSpaceCharReverse(TQString const& s, uint i);
int nextSpaceChar(TQString const& s, uint i);
int nextCharDifferentThan(TQChar c, TQString const& s, uint i);
/** Return a vector with the words */
std::vector<TQString> tokenize(TQString s);
std::vector<TQString> tokenizeWordsSeparatedByDots(TQString s);
std::vector<TQString> tokenizeWordsSeparatedBy(TQString s, TQChar criteria);
/**
Returns a string that has whitespace removed from the start and the end,
and which has each sequence of internal whitespace replaced with a single space.
*/
TQString simplifyWhiteSpace(TQString const& s);
/**
If char 'caractere' is the last in the string 's' it is removed
*/
void removeLastCharIfExists(TQString& s, TQChar caractere);
TQString upperCase(TQString const& s);
TQString lowerCase(TQString const& s);
/**
Remove whitespaces from the end of the string
*/
void stripWhiteSpaceFromTheEnd(TQString& s);
/**
Returns a string that has whitespace removed from the start and the end.
*/
void stripWhiteSpace(TQString& s);
/**
Case insensitive comparisons
*/
bool equal(TQString const& s1, TQString const& s2);
bool notEqual(TQString const& s1, TQString const& s2);
bool equal(TQChar c1, TQChar c2);
bool notEqual(TQChar c1, TQChar c2);
//_________________________________________________________________________
inline bool isSpace(TQChar c)
{
return c.isSpace();
}
inline bool equal(TQString const& s1, TQString const& s2)
{
if(s1 == s2)
return true;
else
return s1.lower() == s2.lower();
}
inline bool notEqual(TQString const& s1, TQString const& s2)
{
return !(equal(s1, s2));
}
inline bool equal(TQChar c1, TQChar c2)
{
return c1.lower() == c2.lower();
}
inline bool notEqual(TQChar c1, TQChar c2)
{
return !(equal(c1, c2));
}
inline TQString upperCase(TQString const& s)
{
return s.upper();
}
inline TQString lowerCase(TQString const& s)
{
return s.lower();
}
inline TQString simplifyWhiteSpace(TQString const& s)
{
return s.simplifyWhiteSpace();
}
inline void removeLastCharIfExists(TQString& s, TQChar caractere)
{
int index = s.length() - 1;
if(s[index] == caractere)
s.remove(index);
}
inline void stripWhiteSpace(TQString& s)
{
s = s.stripWhiteSpace();
}
#endif
|