Subversion Repositories spk

Rev

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

Rev 170 Rev 174
Line 4... Line 4...
4
#include "../spkdll.h"
4
#include "../spkdll.h"
-
 
5
 
-
 
6
//#define STRING_WCHAR
5
 
7
 
6
enum {
8
enum {
7
	COMPARE_SAME		= 0,
9
	COMPARE_SAME		= 0,
8
	COMPARE_NEWER		= 1,
10
	COMPARE_NEWER		= 1,
9
	COMPARE_OLDER		= -1,
11
	COMPARE_OLDER		= -1,
Line 17... Line 19...
17
	std::string ws2s(const std::wstring& wstr);
19
	std::string ws2s(const std::wstring& wstr);
18
 
20
 
19
/**
21
/**
20
 * String wrapper class
22
 * String wrapper class
21
 */
23
 */
-
 
24
#ifdef STRING_WCHAR
-
 
25
	class SPKEXPORT String : public std::wstring
-
 
26
#else
22
class SPKEXPORT String : public std::string
27
	class SPKEXPORT String : public std::string
-
 
28
#endif
23
{
29
{
-
 
30
private:
-
 
31
#ifdef STRING_WCHAR
-
 
32
	std::string		_str;
-
 
33
#else
-
 
34
	std::wstring	_str;
-
 
35
#endif
-
 
36
 
24
public:
37
public:
25
	// constructors
38
	// constructors
26
	String(void);
39
	String(void);
27
	String(const char *str);
40
	String(const char *str);
28
	String(const unsigned char *str);
41
	String(const unsigned char *str);
Line 34... Line 47...
34
	String(unsigned long l);
47
	String(unsigned long l);
35
	String(float f);
48
	String(float f);
36
	String(double f);
49
	String(double f);
37
	String(wchar_t* str, int len = -1)
50
	String(wchar_t* str, int len = -1)
38
	{
51
	{
-
 
52
		if(len > 0)
39
		this->assign(ws2s(std::wstring(str)));
53
			this->_assign(str, len);
-
 
54
		else
-
 
55
			this->_assign(str);
40
	}
56
	}
41
 
57
 
42
	virtual ~String(void);
58
	virtual ~String(void);
43
 
59
 
44
	// conversion functions
60
	// conversion functions
Line 63... Line 79...
63
	bool toBool() const;
79
	bool toBool() const;
64
	long toLong() const;
80
	long toLong() const;
65
	int toInt() const;
81
	int toInt() const;
66
	double toDouble() const;
82
	double toDouble() const;
67
	float toFloat() const;
83
	float toFloat() const;
-
 
84
 
-
 
85
#ifdef STRING_WCHAR
-
 
86
	inline const std::wstring& toWString() const { return *this; }
-
 
87
	inline const std::string& toString() const { return _str; }
-
 
88
	inline const wchar_t* toWChar() const { return this->c_str(); }
-
 
89
	inline const char* toChar() const { return _str.c_str(); }
-
 
90
#else
-
 
91
	inline const std::wstring& toWString() const { return _str; }
-
 
92
	inline const std::string& toString() const { return *this; }
-
 
93
	inline const wchar_t* toWChar() const { return _str.c_str(); }
-
 
94
	inline const char* toChar() const { return this->c_str(); }
-
 
95
#endif
68
 
96
 
69
	// casting operators
97
	// casting operators
70
	inline operator const char *() const			{ return (const char *)this->c_str(); }
98
	inline operator const char *() const			{ return (const char *)toChar(); }
71
	inline operator char *() const					{ return (char *)this->c_str(); }
99
	inline operator char *() const					{ return (char *)toChar(); }
72
	inline operator const unsigned char *() const	{ return (const unsigned char *)this->c_str(); }
100
	inline operator const unsigned char *() const	{ return (const unsigned char *)toChar(); }
73
	inline operator unsigned char *() const			{ return (unsigned char *)this->c_str(); }
101
	inline operator unsigned char *() const			{ return (unsigned char *)toChar(); }
74
	inline operator const std::string &() const		{ return (const std::string &)*this; }
102
	inline operator const std::string &() const		{ return (const std::string &)toString(); }
75
	inline operator const int () const				{ return this->toLong(); }
103
	inline operator const int () const				{ return this->toLong(); }
76
	inline operator const long () const				{ return this->toLong(); }
104
	inline operator const long () const				{ return this->toLong(); }
77
	inline operator const double () const			{ return this->toDouble(); }
105
	inline operator const double () const			{ return this->toDouble(); }
78
	inline operator const float () const			{ return this->toFloat(); }
106
	inline operator const float () const			{ return this->toFloat(); }
79
	inline operator const bool () const				{ return (this->empty() ? false : ((this->toLong()) ? true : false)); }
107
	inline operator const bool () const				{ return (this->empty() ? false : ((this->toLong()) ? true : false)); }
Line 191... Line 219...
191
 
219
 
192
	const String &toFilename();
220
	const String &toFilename();
193
	String asFilename() const;
221
	String asFilename() const;
194
 
222
 
195
private:
223
private:
-
 
224
#ifdef STRING_WCHAR
-
 
225
	void _assign(const std::string& str) { this->assign(s2ws(str)); _str = str; }
-
 
226
	void _assign(const std::wstring& str) { this->assign(str); _str = ws2s(str); }
-
 
227
	void _assign(const wchar_t* str) { this->assign(str); _str = ws2s(*this); }
-
 
228
	void _assign(const wchar_t* str, size_t len) { this->assign(str, len); _str = ws2s(*this); }
-
 
229
	void _assign(const char c) { this->assign(1, c); _str = ws2s(*this); }
-
 
230
//	void _assign(const wchar_t c) { this->assign(1, c); _str = ws2s(*this); }
-
 
231
#else
-
 
232
	void _assign(const std::string& str) { this->assign(str); _str = s2ws(str); }
-
 
233
	void _assign(const std::wstring& str) { this->assign(ws2s(str)); _str = str; }
-
 
234
	void _assign(const wchar_t* str) { this->assign(ws2s(str)); _str = str; }
-
 
235
	void _assign(const wchar_t* str, size_t len) { this->assign(ws2s(str), len); _str = str; }
-
 
236
	void _assign(const char c) { this->assign(1, c); _str = s2ws(*this); }
-
 
237
//	void _assign(const wchar_t c) { _str.assign(1, c); this->assign(ws2s(_str)); }
-
 
238
#endif
196
	bool _isCharNumber(char c) const;
239
	bool _isCharNumber(char c) const;
197
	Utils::String::size_type _token_nextPos(const char *token, Utils::String::size_type curPos) const;
240
	Utils::String::size_type _token_nextPos(const char *token, Utils::String::size_type curPos) const;
198
};
241
};
199
 
242
 
200
SPKEXPORT String operator+(const char* str1, const String& str2);
243
SPKEXPORT String operator+(const char* str1, const String& str2);