Subversion Repositories spk

Rev

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