~evan-nelson/armagetronad/armagetronad+pcm

« back to all changes in this revision

Viewing changes to src/tools/tString.h

Attempting to create a timeout for PLAYER_CENTER_MESSAGE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 
3
 
*************************************************************************
4
 
 
5
 
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
 
Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
7
 
 
8
 
**************************************************************************
9
 
 
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.
14
 
 
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.
19
 
 
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.
23
 
 
24
 
***************************************************************************
25
 
 
26
 
*/
27
 
 
28
 
#ifndef ArmageTron_STRING_H
29
 
#define ArmageTron_STRING_H
30
 
 
31
 
#include "config.h"
32
 
 
33
 
#include "tArray.h"
34
 
#include "tMemStack.h"
35
 
 
36
 
#include <sstream>
37
 
#include <iostream>
38
 
#include <iosfwd>
39
 
 
40
 
//typedef tArray<char> string;
41
 
class tOutput;
42
 
 
43
 
class tString:public tArray<char>{
44
 
private:
45
 
public:
46
 
    tString();
47
 
    tString(const tString &);
48
 
    explicit tString(const char *);
49
 
    explicit tString(const tOutput &);
50
 
 
51
 
    void ReadLine(std::istream &s, bool enableEscapeSequences=false);
52
 
 
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;
60
 
 
61
 
    // comparison operators
62
 
    int Compare( const char* other ) const;             // wrapper for strcmp
63
 
    int Compare( const char* other, bool ignoreCase ) const; // strcasecmp
64
 
 
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;
71
 
 
72
 
    operator const char*() const;
73
 
 
74
 
    tString & operator =(const tString &s);
75
 
    tString & operator =(const tOutput &s);
76
 
    tString & operator+=(const tString &s);
77
 
 
78
 
    // Z-Man: stupid, stupid disambiguation for Visual C++.
79
 
    // not harmful to GCC, but not required.
80
 
#ifdef _MSC_VER
81
 
    template<class I> char& operator[](I i) {
82
 
        return tArray<char>::operator [](i);
83
 
    };
84
 
#endif
85
 
 
86
 
    // bool operator==(const tString &other) const;
87
 
    //  bool operator>=(const tString &other) const;
88
 
 
89
 
    //  static char * ReserveTempString();
90
 
    //  static int    TempStringLength();
91
 
    //  static void   MakeTempStringLonger();
92
 
    //  static void   FreeTempString();
93
 
 
94
 
    void Clear(){
95
 
        tArray<char>::Clear();
96
 
    }
97
 
 
98
 
    //! makes this string exactly of length len.
99
 
    void SetPos( int len, bool cut );
100
 
 
101
 
    //! determines whether this string starts with the argument string
102
 
    bool StartsWith( const tString & other ) const;
103
 
    bool StartsWith( const char * other ) const;
104
 
 
105
 
    //Get the position of a substring within a string...
106
 
    int StrPos( const tString &tofind ) const;
107
 
    int StrPos( const char * tofind ) const;
108
 
 
109
 
    //Get a substring within a string...
110
 
    tString SubStr( const int start, int len) const;
111
 
    tString SubStr( const int start ) const;
112
 
 
113
 
    //toInt as getInt is funky...
114
 
    int toInt( const int pos ) const;
115
 
    int toInt() const;
116
 
 
117
 
    //! compares two strings alphanumerically
118
 
    static int CompareAlphaNumerical( const tString& a, const tString &b);
119
 
 
120
 
    //! strips all whitespace from a string
121
 
    tString StripWhitespace( void ) const;
122
 
 
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
129
 
 
130
 
    tString ExtractNonBlankSubString( int &pos ) const; //!< Extract non blank char sequence starting at pos
131
 
 
132
 
    //! Truncate a string
133
 
    tString Truncate( int truncateAt ) const;
134
 
 
135
 
    void NetFilter();                           //!< filters strings from the net for strange things like newlines
136
 
};
137
 
 
138
 
//! proxy class for inserting color markings
139
 
struct tColoredStringProxy
140
 
{
141
 
    REAL r_, g_, b_;
142
 
 
143
 
    tColoredStringProxy( REAL r, REAL g, REAL b )
144
 
            : r_(r), g_(g), b_(b)
145
 
    {}
146
 
};
147
 
 
148
 
//!< strings that know about color markings
149
 
class tColoredString: public tString
150
 
{
151
 
public:
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
158
 
 
159
 
    //! Assignment operators
160
 
    tString & operator = ( const char * c );
161
 
    tString & operator = ( const tString & s );
162
 
    tString & operator = ( const tOutput & s );
163
 
 
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
167
 
 
168
 
    void RemoveTrailingColor();                             //!< Removes trailing, unfinished color code
169
 
 
170
 
    void RemoveHex();                                       //!< ?
171
 
 
172
 
    //! Creates a color string inserter
173
 
    inline static tColoredStringProxy ColorString( REAL r,REAL g,REAL b )
174
 
    {
175
 
        return tColoredStringProxy( r, g, b );
176
 
    }
177
 
};
178
 
 
179
 
std::ostream & operator<< (std::ostream &s,const tString &x);
180
 
std::istream & operator>> (std::istream &s,tString &x);
181
 
 
182
 
//! check whether item is in a comma or whitespace separated list
183
 
bool tIsInList( tString const & list, tString const & item );
184
 
 
185
 
//! converts a string to lowercase
186
 
void tToLower( tString & toTransform );
187
 
 
188
 
//! converts a string to uppercase
189
 
void tToUpper( tString & toTransform );
190
 
 
191
 
//#define tMAX_STRING_OUTPUT 1000
192
 
//extern char st_stringOutputBuffer[tMAX_STRING_OUTPUT];
193
 
 
194
 
/*
195
 
  tString & operator <<(tString &s,const char* c){
196
 
  return s+=c;
197
 
  }
198
 
 
199
 
  tString & operator <<(tString &s,char c){
200
 
  return s+=c;
201
 
  }
202
 
*/
203
 
 
204
 
//! string building streaming operator
205
 
template<class T> tString & operator <<(tString &s,const T &c)
206
 
{
207
 
    std::ostringstream S;
208
 
 
209
 
    S << c << '\0';
210
 
 
211
 
    return s+=S.str().c_str();
212
 
}
213
 
 
214
 
//! string building streaming operator
215
 
tColoredString & operator <<(tColoredString &s, const tColoredStringProxy &colorCode );
216
 
 
217
 
//! string building streaming operator
218
 
template<class T> tColoredString & operator <<(tColoredString &s,const T &c)
219
 
{
220
 
    // delegate to basic string function...
221
 
    static_cast< tString& >( s ) << c;
222
 
 
223
 
    // but don't allow overhanging color codes
224
 
    s.RemoveTrailingColor();
225
 
 
226
 
    return s;
227
 
}
228
 
 
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);
239
 
 
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 );
246
 
 
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 );
253
 
 
254
 
 
255
 
/*
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);
260
 
*/
261
 
 
262
 
tString st_GetCurrentTime(char const *szFormat);
263
 
 
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 );
267
 
 
268
 
 
269
 
#endif
270
 
 
271