Subversion Repositories spk

Rev

Rev 291 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 291 Rev 346
Line 1... Line 1...
1
#pragma once
1
#pragma once
2
 
2
 
3
#include <string>
3
#include <string>
4
#include <vector>
4
#include <vector>
-
 
5
#include <cstdlib>
5
#include "../spkdll.h"
6
#include "../spkdll.h"
6
#include "../spkdef.h"
7
#include "../spkdef.h"
7
 
8
 
8
enum WStringCompare {
9
enum WStringCompare {
9
	Same		= 0,
10
	Same		= 0,
Line 16... Line 17...
16
 
17
 
17
namespace Utils {
18
namespace Utils {
18
 
19
 
19
	class SString;
20
	class SString;
20
	class WStringList;
21
	class WStringList;
-
 
22
 
21
/**
23
/**
22
 * String wrapper class
24
 * String wrapper class
23
 */
25
 */
24
	class SPKEXPORT WString
26
	class SPKEXPORT WString
25
{
27
{
Line 31... Line 33...
31
private:
33
private:
32
	std::wstring _data;
34
	std::wstring _data;
33
 
35
 
34
public:
36
public:
35
	// constructors
37
	// constructors
36
	WString(void);
38
	WString();
37
	WString(const char* str);
39
	WString(const char* str);
38
	WString(const wchar_t* str);
40
	WString(const wchar_t* str);
39
	WString(const std::string& str);
41
	WString(const std::string& str);
40
	WString(const std::wstring& str);
42
	WString(const std::wstring& str);
41
	WString(const char c);
43
	WString(const char c);
42
	WString(const unsigned char c);
44
	WString(const unsigned char c);
43
	WString(const wchar_t c);
45
	WString(const wchar_t c);
44
	WString(const WString &str);
46
	WString(const WString &str);
-
 
47
	WString(WString&&) noexcept = default;               // enable efficient move
45
	WString(long long l);
48
	WString(long long l);
46
	WString(unsigned long long l);
49
	WString(unsigned long long l);
47
	WString(long l);
50
	WString(long l);
48
	WString(unsigned long l);
51
	WString(unsigned long l);
49
	WString(float f);
52
	WString(float f);
50
	WString(double f);
53
	WString(double f);
51
	WString(wchar_t* str, int len = -1)
-
 
52
	{
-
 
53
		if(len > 0)
-
 
54
			this->_assign(str, len);
-
 
55
		else
-
 
56
			this->_assign(str);
-
 
57
	}
-
 
58
 
54
 
-
 
55
	// explicit sized constructor - no default len to avoid ambiguity with single-arg ctor
-
 
56
	WString(const wchar_t* str, int len);
-
 
57
 
59
	virtual ~WString(void);
58
	virtual ~WString() noexcept;
60
 
59
 
61
	// conversion functions
60
	// conversion functions
62
	void fromLong(long l);
61
	void fromLong(long l);
63
	void fromLong64(long long l);
62
	void fromLong64(long long l);
64
	const WString& fromFloat(float f, int dp = -1);
63
	const WString& fromFloat(float f, int dp = -1);
Line 90... Line 89...
90
	long long toLong64() const;
89
	long long toLong64() const;
91
	int toInt() const;
90
	int toInt() const;
92
	double toDouble() const;
91
	double toDouble() const;
93
	float toFloat() const;
92
	float toFloat() const;
94
	const wchar_t* toWChar() const;
93
	const wchar_t* toWChar() const;
95
	const wchar_t* c_str() const;
94
	const wchar_t* c_str() const noexcept;
96
	std::string toUTF8() const;
95
	std::string toUTF8() const;
97
	std::string toFileUTF8() const;
96
	std::string toFileUTF8() const;
98
	std::wstring toStdWString() const { return _data; }
97
	std::wstring toStdWString() const { return _data; }
99
 
98
 
100
	const SString toString() const;
99
	const SString toString() const;
101
	const std::string toStdString() const;
100
	const std::string toStdString() const;
102
 
101
 
103
	// casting operators
102
	// casting operators
104
	inline operator const wchar_t *() const			{ return _data.c_str(); }
103
	inline operator const wchar_t *() const noexcept	{ return _data.c_str(); }
105
	inline operator wchar_t *() const				{ return (wchar_t *)_data.c_str(); }
-
 
106
	inline operator const std::wstring &() const	{ return _data; }
104
	inline operator const std::wstring &() const noexcept	{ return _data; }
107
	inline operator const int () const				{ return static_cast<int>(this->toLong()); }
105
	inline operator const int () const				{ return static_cast<int>(this->toLong()); }
108
	inline operator const long () const				{ return this->toLong(); }
106
	inline operator const long () const				{ return this->toLong(); }
109
	inline operator const long long () const		{ return this->toLong64(); }
107
	inline operator const long long () const		{ return this->toLong64(); }
110
	inline operator const double () const			{ return this->toDouble(); }
108
	inline operator const double () const			{ return this->toDouble(); }
111
	inline operator const float () const			{ return this->toFloat(); }
109
	inline operator const float () const			{ return this->toFloat(); }
112
	inline operator const bool () const				{ return (this->empty() ? false : ((this->toLong()) ? true : false)); }
110
	inline operator const bool () const				{ return (this->empty() ? false : ((this->toLong()) ? true : false)); }
113
 
111
 
114
	// assignment operators
112
	// assignment operators
115
	const WString &operator= ( const WString &str );
113
	const WString &operator= ( const WString &str );
-
 
114
	WString& operator=(WString&&) noexcept = default;
116
	const WString &operator= ( const std::wstring &str );
115
	const WString &operator= ( const std::wstring &str );
117
	const WString &operator= ( const wchar_t *str );
116
	const WString &operator= ( const wchar_t *str );
118
	const WString &operator= ( wchar_t c );
117
	const WString &operator= ( wchar_t c );
119
	const WString &operator= ( long l );
118
	const WString &operator= ( long l );
120
	const WString &operator= ( unsigned long l );
119
	const WString &operator= ( unsigned long l );
Line 165... Line 164...
165
 
164
 
166
	bool Compare(const WString &str, bool bCaseSensative = false) const;
165
	bool Compare(const WString &str, bool bCaseSensative = false) const;
167
	bool Compare(const wchar_t *str, bool bCaseSensative = false) const;
166
	bool Compare(const wchar_t *str, bool bCaseSensative = false) const;
168
 
167
 
169
	//std::wstring functions
168
	//std::wstring functions
170
	bool empty() const;
169
	bool empty() const noexcept;
171
	void clear();
170
	void clear() noexcept;
172
	WString &erase(size_t offset, size_t count);
171
	WString &erase(size_t offset, size_t count);
173
	size_t length() const;
172
	size_t length() const noexcept;
174
	WString substr(size_t offset, size_t count) const;
173
	WString substr(size_t offset, size_t count) const;
175
	WString substr(size_t offset) const;
174
	WString substr(size_t offset) const;
176
	wchar_t back() const;
175
	wchar_t back() const;
177
 
176
 
178
	// file handling
177
	// file handling