Subversion Repositories spk

Rev

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