3
*************************************************************************
5
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
Copyright (C) 2000 Manuel Moos (manuel@moosnet.de)
8
**************************************************************************
10
This program is free software; you can redistribute it and/or
11
modify it under the terms of the GNU General Public License
12
as published by the Free Software Foundation; either version 2
13
of the License, or (at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
***************************************************************************
28
#ifndef ArmageTron_STRING_H
29
#define ArmageTron_STRING_H
34
#include "tMemStack.h"
40
//typedef tArray<char> string;
43
class tString:public tArray<char>{
47
tString(const tString &);
48
explicit tString(const char *);
49
explicit tString(const tOutput &);
51
void ReadLine(std::istream &s, bool enableEscapeSequences=false);
53
tString & operator+=(const char *c);
54
tString & operator=(const char *c);
55
tString & operator<<(const char *c);
56
tString operator+(const char *c) const;
57
tString & operator<<(char c);
58
tString & operator+=(char c);
59
tString operator+(char c) const;
61
// comparison operators
62
int Compare( const char* other ) const; // wrapper for strcmp
63
int Compare( const char* other, bool ignoreCase ) const; // strcasecmp
65
bool operator==( const char* other ) const;
66
bool operator!=( const char* other ) const;
67
bool operator<( const char* other ) const;
68
bool operator>( const char* other ) const;
69
bool operator<=( const char* other ) const;
70
bool operator>=( const char* other ) const;
72
operator const char*() const;
74
tString & operator =(const tString &s);
75
tString & operator =(const tOutput &s);
76
tString & operator+=(const tString &s);
78
// Z-Man: stupid, stupid disambiguation for Visual C++.
79
// not harmful to GCC, but not required.
81
template<class I> char& operator[](I i) {
82
return tArray<char>::operator [](i);
86
// bool operator==(const tString &other) const;
87
// bool operator>=(const tString &other) const;
89
// static char * ReserveTempString();
90
// static int TempStringLength();
91
// static void MakeTempStringLonger();
92
// static void FreeTempString();
95
tArray<char>::Clear();
98
//! makes this string exactly of length len.
99
void SetPos( int len, bool cut );
101
//! determines whether this string starts with the argument string
102
bool StartsWith( const tString & other ) const;
103
bool StartsWith( const char * other ) const;
105
//Get the position of a substring within a string...
106
int StrPos( const tString &tofind ) const;
107
int StrPos( const char * tofind ) const;
109
//Get a substring within a string...
110
tString SubStr( const int start, int len) const;
111
tString SubStr( const int start ) const;
113
//toInt as getInt is funky...
114
int toInt( const int pos ) const;
117
//! compares two strings alphanumerically
118
static int CompareAlphaNumerical( const tString& a, const tString &b);
120
//! strips all whitespace from a string
121
tString StripWhitespace( void ) const;
123
int PosWordRight(int start); //! Computes the position of the next delimiter relative to start
124
int PosWordLeft(int start); //! Computes the position of the previous delimiter relative to start
125
int RemoveWordRight(int start); //! Remove word right according to the delimiters
126
int RemoveWordLeft(int start); //! Remove word left according to the delimiters
127
void RemoveSubStr(int start, int length); //! Remove a substring, in-place
128
tString Reverse(); //! Reverses strings
130
tString ExtractNonBlankSubString( int &pos ) const; //!< Extract non blank char sequence starting at pos
132
//! Truncate a string
133
tString Truncate( int truncateAt ) const;
135
void NetFilter(); //!< filters strings from the net for strange things like newlines
138
//! proxy class for inserting color markings
139
struct tColoredStringProxy
143
tColoredStringProxy( REAL r, REAL g, REAL b )
144
: r_(r), g_(g), b_(b)
148
//!< strings that know about color markings
149
class tColoredString: public tString
152
~tColoredString(); //!< Destructor
153
tColoredString(); //!< Default constructor
154
tColoredString( const tColoredString& other ); //!< Copy constructor
155
explicit tColoredString( const tString& other ); //!< Base copy constructor
156
explicit tColoredString( const char * other ); //!< Constructor from raw C string
157
explicit tColoredString( const tOutput & other ); //!< Constructor from output gatherer
159
//! Assignment operators
160
tString & operator = ( const char * c );
161
tString & operator = ( const tString & s );
162
tString & operator = ( const tOutput & s );
164
static tString RemoveColors( const char *c ); //!< Removes the color codes from a string
165
static tString RemoveColors( const char *c, bool darkonly ); //!< Removes the color codes from a string
166
void SetPos( int len, bool cut=false ); //!< Makes sure string has length len when color codes are removed
168
void RemoveTrailingColor(); //!< Removes trailing, unfinished color code
170
void RemoveHex(); //!< ?
172
//! Creates a color string inserter
173
inline static tColoredStringProxy ColorString( REAL r,REAL g,REAL b )
175
return tColoredStringProxy( r, g, b );
179
std::ostream & operator<< (std::ostream &s,const tString &x);
180
std::istream & operator>> (std::istream &s,tString &x);
182
//! check whether item is in a comma or whitespace separated list
183
bool tIsInList( tString const & list, tString const & item );
185
//! converts a string to lowercase
186
void tToLower( tString & toTransform );
188
//! converts a string to uppercase
189
void tToUpper( tString & toTransform );
191
//#define tMAX_STRING_OUTPUT 1000
192
//extern char st_stringOutputBuffer[tMAX_STRING_OUTPUT];
195
tString & operator <<(tString &s,const char* c){
199
tString & operator <<(tString &s,char c){
204
//! string building streaming operator
205
template<class T> tString & operator <<(tString &s,const T &c)
207
std::ostringstream S;
211
return s+=S.str().c_str();
214
//! string building streaming operator
215
tColoredString & operator <<(tColoredString &s, const tColoredStringProxy &colorCode );
217
//! string building streaming operator
218
template<class T> tColoredString & operator <<(tColoredString &s,const T &c)
220
// delegate to basic string function...
221
static_cast< tString& >( s ) << c;
223
// but don't allow overhanging color codes
224
s.RemoveTrailingColor();
229
std::stringstream& operator<<(std::stringstream& s,const tString &t);
230
//std::stringstream& operator<<(std::stringstream& s, const int &t);
231
//std::stringstream& operator<<(std::stringstream& s, const float &t);
232
//std::stringstream& operator<<(std::stringstream& s, const short unsigned int &t);
233
//std::stringstream& operator<<(std::stringstream& s, const short int &t);
234
//std::stringstream& operator<<(std::stringstream& s, const unsigned int &t);
235
//std::stringstream& operator<<(std::stringstream& s, const unsigned long &t);
236
//std::stringstream& operator<<(std::stringstream& s, char t);
237
//std::stringstream& operator<<(std::stringstream& s, bool t);
238
//std::stringstream& operator<<(std::stringstream& s, const char * const &t);
240
bool operator==( const char* first, const tString& second );
241
bool operator!=( const char* first, const tString& second );
242
bool operator<( const char* first, const tString& second );
243
bool operator>( const char* first, const tString& second );
244
bool operator<=( const char* first, const tString& second );
245
bool operator>=( const char* first, const tString& second );
247
bool operator==( const tString& first, const tString& second );
248
bool operator!=( const tString& first, const tString& second );
249
bool operator<( const tString& first, const tString& second );
250
bool operator>( const tString& first, const tString& second );
251
bool operator<=( const tString& first, const tString& second );
252
bool operator>=( const tString& first, const tString& second );
256
void operator <<(tString &s,const char * c);
257
void operator <<(tString &s,const unsigned char * c);
258
void operator <<(tString &s,int c);
259
void operator <<(tString &s,float c);
262
tString st_GetCurrentTime(char const *szFormat);
264
// replacement for tString::EndsWith from the trunk
265
bool st_StringEndsWith( tString const & test, tString const & end );
266
bool st_StringEndsWith( tString const & test, char const * end );