Subversion Repositories spk

Rev

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

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