Subversion Repositories spk

Rev

Rev 126 | Rev 130 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8 cycrow 1
#pragma once
2
 
3
#include <string>
4
#include "../spkdll.h"
5
 
50 cycrow 6
enum {
7
	COMPARE_SAME		= 0,
8
	COMPARE_NEWER		= 1,
9
	COMPARE_OLDER		= -1,
10
};
11
 
121 cycrow 12
#pragma warning( push )
13
#pragma warning( disable : 4251)
14
 
8 cycrow 15
namespace Utils {
16
/**
17
 * String wrapper class
18
 */
19
class SPKEXPORT String : public std::string
20
{
21
public:
22
	// constructors
23
	String(void);
24
	String(const char *str);
25
	String(const unsigned char *str);
26
	String(const std::string &str);
14 cycrow 27
	String(const char c);
8 cycrow 28
	String(const unsigned char c);
29
	String(const String &str);
30
	String(long l);
31
	String(unsigned long l);
32
	String(float f);
33
	String(double f);
34
 
35
	virtual ~String(void);
36
 
37
	// conversion functions
38
	void fromLong(long l);
126 cycrow 39
	const String &fromFloat(float f, int dp = -1);
8 cycrow 40
	void fromDouble(double f);
41
	void fromDouble(double f, int dp);
42
	const String &format(const char *sFormat, ...);
104 cycrow 43
	const String &arg(const String &s1);
44
	const String &arg(const String &s1, const String &s2);
45
	const String &arg(const String &s1, const String &s2, const String &s3);
46
	const String &arg(const String &s1, const String &s2, const String &s3, const String &s4);
47
	const String &arg(const String &s1, const String &s2, const String &s3, const String &s4, const String &s5);
8 cycrow 48
 
50 cycrow 49
	static String PadNumber(long iNum, int iAmount);
50
	static String Number(long l) { return String(l); }
51
	static String Format(const char *sFormat, ...);
85 cycrow 52
	static String Null();
109 cycrow 53
	static String FromFloat(float f, int dp = -1);
50 cycrow 54
 
94 cycrow 55
	bool toBool() const;
8 cycrow 56
	long toLong() const;
121 cycrow 57
	int toInt() const;
8 cycrow 58
	double toDouble() const;
59
	float toFloat() const;
60
 
61
	// casting operators
62
	inline operator const char *() const			{ return (const char *)this->c_str(); }
63
	inline operator char *() const					{ return (char *)this->c_str(); }
64
	inline operator const unsigned char *() const	{ return (const unsigned char *)this->c_str(); }
65
	inline operator unsigned char *() const			{ return (unsigned char *)this->c_str(); }
66
	inline operator const std::string &() const		{ return (const std::string &)*this; }
10 cycrow 67
	inline operator const int () const				{ return this->toLong(); }
8 cycrow 68
	inline operator const long () const				{ return this->toLong(); }
69
	inline operator const double () const			{ return this->toDouble(); }
70
	inline operator const float () const			{ return this->toFloat(); }
101 cycrow 71
	inline operator const bool () const				{ return (this->empty() ? false : ((this->toLong()) ? true : false)); }
8 cycrow 72
 
73
	// assignment operators
74
	const String &operator= ( const String &str );
75
	const String &operator= ( const std::string &str );
76
	const String &operator= ( const char *str );
77
	const String &operator= ( const unsigned char *str );
78
	const String &operator= ( unsigned char c );
79
	const String &operator= ( char c );
80
	const String &operator= ( long l );
81
	const String &operator= ( unsigned long l );
82
	const String &operator= ( float l );
83
	const String &operator= ( double l );
84
 
85
	// subscript operators
86
	const unsigned char operator[] ( int num ) const;
87
	unsigned char &operator[] ( int num );
88
 
89
	// addition operators
90
	String operator+ ( const char *str ) const;
91
	String operator+ ( const unsigned char *str ) const;
92
	String operator+ ( const std::string &str ) const;
93
	String operator+ ( const String &str ) const;
94
	String operator+ ( const char c ) const;
95
	String operator+ ( const unsigned char c ) const;
96
	String operator+ ( const long l ) const;
97
	String operator+ ( const unsigned long l ) const;
98
	String operator+ ( const float f ) const;
99
	String operator+ ( const double f ) const;
100
 
101
	// compound operators
102
	const String &operator+= ( const char *str );
103
	const String &operator+= ( const unsigned char *str );
104
	const String &operator+= ( const std::string &str );
105
	const String &operator+= ( const String &str );
106
	const String &operator+= ( const char c );
107
	const String &operator+= ( const unsigned char c );
108
	const String &operator+= ( const long l );
109
	const String &operator+= ( const unsigned long l );
110
	const String &operator+= ( const float f );
111
	const String &operator+= ( const double f );
112
 
113
	// comparison operators
114
	bool operator== ( const char *str ) const;
115
	bool operator== ( const unsigned char *str ) const;
116
	bool operator== ( const std::string &str ) const;
117
	bool operator== ( const String &str ) const;
118
 
119
	bool operator!= ( const char *str ) const;
120
	bool operator!= ( const unsigned char *str ) const;
121
	bool operator!= ( const std::string &str ) const;
122
	bool operator!= ( const String &str ) const;
123
 
101 cycrow 124
	bool operator !() const;
125
 
8 cycrow 126
	bool Compare(const String &str, bool bCaseSensative = false) const;
127
	bool Compare(const unsigned char *str, bool bCaseSensative = false) const;
128
	bool Compare(const char *str, bool bCaseSensative = false) const;
129
 
39 cycrow 130
	// file handling
8 cycrow 131
	unsigned char *readToEndOfLine(unsigned char *data);
132
	char *readToEndOfLine(char *data);
39 cycrow 133
	const String &readToEndOfLine(FILE *id, int *line, bool upper);
8 cycrow 134
 
135
	// tokens
136
	int countToken(const char *token) const;
137
	String token(const char *token, int tok) const;
138
	String tokens(const char *token, int from, int to = 0) const;
10 cycrow 139
	String *tokenise(const char *token, int *max) const;
39 cycrow 140
	String replaceToken(const char *token, int from, const String &replace) const;
141
	String remToken(const char *token, int t) const;
142
	String word(int word) const;
143
	String words(int from, int to = 0) const;
126 cycrow 144
	String addToken(const char *token, const Utils::String &str) const;
14 cycrow 145
 
39 cycrow 146
	// find/replacement
147
	int findPos(const String &find, int iStartPos = 0) const;
8 cycrow 148
	String findReplace(const String &find, const String &replace ) const;
39 cycrow 149
	String remove(char c) const;
150
	const String &removeChar(char c);
69 cycrow 151
	const String &removeChar(const char *cs);
48 cycrow 152
	String findRemove(const String &find) const;
153
	String stripHtml() const;
58 cycrow 154
	String removeIf(int iChar, char c) const;
8 cycrow 155
 
127 cycrow 156
	bool containsAny(const String &str, bool bCaseSensative = false) const;
126 cycrow 157
	bool contains(const String &str, bool bCaseSensative = false) const;
158
	bool contains(char c, bool bCaseSensative = false) const;
8 cycrow 159
	bool isin(const String &str, bool bCaseSensative = false) const;
160
	bool isin(char c, bool bCaseSensative = false) const;
50 cycrow 161
	int compareVersion(const Utils::String &v) const;
127 cycrow 162
	bool match(const Utils::String &pattern) const;
8 cycrow 163
 
39 cycrow 164
	// sub string
8 cycrow 165
	String left(long num) const;
166
	String right(int num) const;
39 cycrow 167
	String mid(int start, int end) const;
56 cycrow 168
	String between(const String &before, const String &after) const;
8 cycrow 169
 
13 cycrow 170
	bool isNumber(bool integer = false) const;
171
	bool isCharNumber(int c) const;
14 cycrow 172
	const String &removeFirstSpace();
39 cycrow 173
	const String &removeEndSpace();
34 cycrow 174
	const String &truncate(int iNum);
50 cycrow 175
	const String &padNumber(int iNum);
176
	const String &pad(int iAmoumt, char cWith);
13 cycrow 177
 
43 cycrow 178
	String lower() const;
179
	String upper() const;
180
	const String &toLower();
181
	const String &toUpper();
182
 
81 cycrow 183
	const String &toFilename();
184
	String asFilename() const;
185
 
8 cycrow 186
private:
13 cycrow 187
	bool _isCharNumber(char c) const;
86 cycrow 188
	Utils::String::size_type _token_nextPos(const char *token, Utils::String::size_type curPos) const;
8 cycrow 189
};
190
 
104 cycrow 191
SPKEXPORT String operator+(const char *str1, const String &str2);
121 cycrow 192
 
193
#pragma warning( pop )
194
 
8 cycrow 195
}