Subversion Repositories spk

Rev

Rev 185 | Rev 188 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 185 Rev 186
Line 1... Line 1...
1
#pragma once
1
#pragma once
2
 
2
 
3
#include <string>
3
#include <string>
4
#include "../spkdll.h"
4
#include "../spkdll.h"
5
#include "../spkdef.h"
5
#include "../spkdef.h"
6
 
-
 
7
//#define STRING_WCHAR
-
 
8
 
6
 
9
enum {
7
enum {
10
	COMPARE_SAME		= 0,
8
	COMPARE_SAME		= 0,
11
	COMPARE_NEWER		= 1,
9
	COMPARE_NEWER		= 1,
12
	COMPARE_OLDER		= -1,
10
	COMPARE_OLDER		= -1,
13
};
11
};
14
 
12
 
15
#pragma warning( push )
13
#pragma warning( push )
16
#pragma warning( disable : 4251)
14
#pragma warning( disable : 4251)
17
 
15
 
18
namespace Utils {
16
namespace Utils {
19
	std::wstring s2ws(const std::string& str);
17
	std::wstring s2ws(const std::string& str);
20
	std::string ws2s(const std::wstring& wstr);
18
	std::string ws2s(const std::wstring& wstr);
21
 
19
 
22
/**
20
/**
23
 * String wrapper class
21
 * String wrapper class
24
 */
22
 */
25
#ifdef STRING_WCHAR
-
 
26
	class SPKEXPORT String : public std::wstring
-
 
27
#else
-
 
28
	class SPKEXPORT String : public std::string
23
	class SPKEXPORT String : public std::string
29
#endif
-
 
30
{
24
{
31
private:
-
 
32
#ifdef STRING_WCHAR
-
 
33
	std::string		_str;
-
 
34
#else
-
 
35
	std::wstring	_str;
-
 
36
#endif
-
 
37
 
-
 
38
public:
25
public:
39
	// constructors
26
	// constructors
40
	String(void);
27
	String(void);
41
	String(const char *str);
28
	String(const char *str);
42
	String(const unsigned char *str);
29
	String(const unsigned char *str);
Line 81... Line 68...
81
	long toLong() const;
68
	long toLong() const;
82
	int toInt() const;
69
	int toInt() const;
83
	double toDouble() const;
70
	double toDouble() const;
84
	float toFloat() const;
71
	float toFloat() const;
85
 
72
 
86
#ifdef STRING_WCHAR
-
 
87
	inline const std::wstring& toWString() const { return *this; }
73
	inline const std::wstring toWString() const { return s2ws(*this); }
88
	inline const std::string& toString() const { return _str; }
-
 
89
	inline const wchar_t* toWChar() const { return this->c_str(); }
-
 
90
	inline const char* toChar() const { return _str.c_str(); }
-
 
91
#else
-
 
92
	inline const std::wstring& toWString() const { return _str; }
-
 
93
	inline const std::string& toString() const { return *this; }
-
 
94
	inline const wchar_t* toWChar() const { return _str.c_str(); }
-
 
95
	inline const char* toChar() const { return this->c_str(); }
-
 
96
#endif
-
 
97
 
74
 
98
	// casting operators
75
	// casting operators
99
	inline operator const char *() const			{ return (const char *)toChar(); }
76
	inline operator const char *() const			{ return (const char *)c_str(); }
100
	inline operator char *() const					{ return (char *)toChar(); }
77
	inline operator char *() const					{ return (char *)c_str(); }
101
	inline operator const unsigned char *() const	{ return (const unsigned char *)toChar(); }
78
	inline operator const unsigned char *() const	{ return (const unsigned char *)c_str(); }
102
	inline operator unsigned char *() const			{ return (unsigned char *)toChar(); }
79
	inline operator unsigned char *() const			{ return (unsigned char *)c_str(); }
103
	inline operator const std::string &() const		{ return (const std::string &)toString(); }
80
	inline operator const std::string &() const		{ return (const std::string &)*this; }
104
	inline operator const int () const				{ return this->toLong(); }
81
	inline operator const int () const				{ return this->toLong(); }
105
	inline operator const long () const				{ return this->toLong(); }
82
	inline operator const long () const				{ return this->toLong(); }
106
	inline operator const double () const			{ return this->toDouble(); }
83
	inline operator const double () const			{ return this->toDouble(); }
107
	inline operator const float () const			{ return this->toFloat(); }
84
	inline operator const float () const			{ return this->toFloat(); }
108
	inline operator const bool () const				{ return (this->empty() ? false : ((this->toLong()) ? true : false)); }
85
	inline operator const bool () const				{ return (this->empty() ? false : ((this->toLong()) ? true : false)); }
Line 196... Line 173...
196
	bool contains(char c, bool bCaseSensative = false) const;
173
	bool contains(char c, bool bCaseSensative = false) const;
197
	bool isin(const String &str, bool bCaseSensative = false) const;
174
	bool isin(const String &str, bool bCaseSensative = false) const;
198
	bool isin(char c, bool bCaseSensative = false) const;
175
	bool isin(char c, bool bCaseSensative = false) const;
199
	int compareVersion(const Utils::String &v) const;
176
	int compareVersion(const Utils::String &v) const;
200
	bool match(const Utils::String &pattern) const;
177
	bool match(const Utils::String &pattern) const;
201
 
178
 
202
	// sub string
179
	// sub string
203
	String left(long num) const;
180
	String left(long num) const;
204
	String right(int num) const;
181
	String right(int num) const;
205
	String mid(int start, int end) const;
182
	String mid(int start, int end) const;
206
	String between(const String &before, const String &after) const;
183
	String between(const String &before, const String &after) const;
207
 
184
 
208
	bool isNumber(bool integer = false) const;
185
	bool isNumber(bool integer = false) const;
209
	bool isCharNumber(int c) const;
186
	bool isCharNumber(int c) const;
210
	const String &removeFirstSpace();
187
	const String &removeFirstSpace();
211
	const String &removeEndSpace();
188
	const String &removeEndSpace();
212
	const String &truncate(int iNum);
189
	const String &truncate(int iNum);
Line 220... Line 197...
220
 
197
 
221
	const String &toFilename();
198
	const String &toFilename();
222
	String asFilename() const;
199
	String asFilename() const;
223
 
200
 
224
private:
201
private:
225
#ifdef STRING_WCHAR
-
 
226
	void _assign(const std::string& str) { this->assign(s2ws(str)); _str = str; }
-
 
227
	void _assign(const std::wstring& str) { this->assign(str); _str = ws2s(str); }
-
 
228
	void _assign(const wchar_t* str) { this->assign(str); _str = ws2s(*this); }
-
 
229
	void _assign(const wchar_t* str, size_t len) { this->assign(str, len); _str = ws2s(*this); }
-
 
230
	void _assign(const char c) { this->assign(1, c); _str = ws2s(*this); }
-
 
231
//	void _assign(const wchar_t c) { this->assign(1, c); _str = ws2s(*this); }
-
 
232
#else
-
 
233
	void _assign(const std::string& str) { this->assign(str); /*_str = s2ws(str); */}
-
 
234
	void _assign(const char *str) 
-
 
235
	{ 
-
 
236
		this->assign(str);
-
 
237
		//_str = s2ws(str);
-
 
238
	}
-
 
239
	//void _assign(const std::wstring& str) { this->assign(ws2s(str)); _str = str; }
-
 
240
	void _assign(const wchar_t* str) { this->assign(ws2s(str)); _str = str; }
202
	void _assign(const wchar_t* str) { this->assign(ws2s(str)); }
241
	void _assign(const wchar_t* str, size_t len) { this->assign(ws2s(str), len); _str = str; }
203
	void _assign(const wchar_t* str, size_t len) { this->assign(ws2s(str), len); }
242
	void _assign(const char c) { this->assign(1, c); /*_str = s2ws(*this);*/ }
-
 
243
//	void _assign(const wchar_t c) { _str.assign(1, c); this->assign(ws2s(_str)); }
-
 
244
#endif
-
 
245
	bool _isCharNumber(char c) const;
204
	bool _isCharNumber(char c) const;
246
	Utils::String::size_type _token_nextPos(const char *token, Utils::String::size_type curPos) const;
205
	Utils::String::size_type _token_nextPos(const char *token, Utils::String::size_type curPos) const;
247
};
206
};
248
 
207
 
249
SPKEXPORT String operator+(const char* str1, const String& str2);
208
SPKEXPORT String operator+(const char* str1, const String& str2);