| 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);
 | 
        
           | 243 | cycrow | 29 | 	static WString ConvertTime(time_t whattime, bool shortdesc = false);
 | 
        
           | 186 | cycrow | 30 |   | 
        
           |  |  | 31 | public:
 | 
        
           |  |  | 32 | 	// constructors
 | 
        
           |  |  | 33 | 	WString(void);
 | 
        
           |  |  | 34 | 	WString(const char* str);
 | 
        
           |  |  | 35 | 	WString(const wchar_t* 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);
 | 
        
           | 213 | cycrow | 58 | 	const WString& fromFloat(float f, int dp = -1);
 | 
        
           |  |  | 59 | 	const WString& fromString(const char* str);
 | 
        
           |  |  | 60 | 	const WString& fromString(const unsigned char* str);
 | 
        
           | 186 | cycrow | 61 | 	void fromDouble(double f);
 | 
        
           |  |  | 62 | 	const WString &fromDouble(double f, int dp);
 | 
        
           |  |  | 63 | 	const WString &format(const wchar_t *sFormat, ...);
 | 
        
           | 198 | cycrow | 64 | 	const WString args(const WString* args, int max) const;
 | 
        
           |  |  | 65 | 	const WString args(const WStringList& args) const;
 | 
        
           |  |  | 66 | 	const WString args(const std::vector<Utils::WString>& args) const;
 | 
        
           | 186 | cycrow | 67 | 	const WString &arg(const WString &s1);
 | 
        
           |  |  | 68 | 	const WString &arg(const WString &s1, const WString &s2);
 | 
        
           |  |  | 69 | 	const WString &arg(const WString &s1, const WString &s2, const WString &s3);
 | 
        
           |  |  | 70 | 	const WString &arg(const WString &s1, const WString &s2, const WString &s3, const WString &s4);
 | 
        
           |  |  | 71 | 	const WString &arg(const WString &s1, const WString &s2, const WString &s3, const WString &s4, const WString &s5);
 | 
        
           | 243 | cycrow | 72 | 	const WString& convertTime(time_t whattime, bool shortdesc = false);
 | 
        
           | 186 | cycrow | 73 |   | 
        
           |  |  | 74 | 	static WString PadNumber(long iNum, int iAmount);
 | 
        
           |  |  | 75 | 	static WString Number(long l) { return WString(l); }
 | 
        
           |  |  | 76 | 	static WString Format(const wchar_t *sFormat, ...);
 | 
        
           |  |  | 77 | 	static WString Null();
 | 
        
           |  |  | 78 | 	static WString FromFloat(float f, int dp = -1);
 | 
        
           | 213 | cycrow | 79 | 	static WString FromString(const char* data);
 | 
        
           |  |  | 80 | 	static WString FromString(const unsigned char* data);
 | 
        
           | 186 | cycrow | 81 |   | 
        
           |  |  | 82 | 	bool toBool() const;
 | 
        
           |  |  | 83 | 	long toLong() const;
 | 
        
           |  |  | 84 | 	int toInt() const;
 | 
        
           |  |  | 85 | 	double toDouble() const;
 | 
        
           |  |  | 86 | 	float toFloat() const;
 | 
        
           |  |  | 87 |   | 
        
           | 188 | cycrow | 88 | 	const SString toString() const;
 | 
        
           | 186 | cycrow | 89 |   | 
        
           |  |  | 90 | 	// casting operators
 | 
        
           |  |  | 91 | 	inline operator const wchar_t *() const			{ return (const wchar_t *)c_str(); }
 | 
        
           |  |  | 92 | 	inline operator wchar_t *() const				{ return (wchar_t *)c_str(); }
 | 
        
           |  |  | 93 | 	inline operator const std::wstring &() const	{ return (const std::wstring &)*this; }
 | 
        
           |  |  | 94 | 	inline operator const int () const				{ return this->toLong(); }
 | 
        
           |  |  | 95 | 	inline operator const long () const				{ return this->toLong(); }
 | 
        
           |  |  | 96 | 	inline operator const double () const			{ return this->toDouble(); }
 | 
        
           |  |  | 97 | 	inline operator const float () const			{ return this->toFloat(); }
 | 
        
           |  |  | 98 | 	inline operator const bool () const				{ return (this->empty() ? false : ((this->toLong()) ? true : false)); }
 | 
        
           |  |  | 99 |   | 
        
           |  |  | 100 | 	// assignment operators
 | 
        
           |  |  | 101 | 	const WString &operator= ( const WString &str );
 | 
        
           |  |  | 102 | 	const WString &operator= ( const std::wstring &str );
 | 
        
           |  |  | 103 | 	const WString &operator= ( const wchar_t *str );
 | 
        
           |  |  | 104 | 	const WString &operator= ( wchar_t c );
 | 
        
           |  |  | 105 | 	const WString &operator= ( long l );
 | 
        
           |  |  | 106 | 	const WString &operator= ( unsigned long l );
 | 
        
           |  |  | 107 | 	const WString &operator= ( float l );
 | 
        
           |  |  | 108 | 	const WString &operator= ( double l );
 | 
        
           |  |  | 109 |   | 
        
           |  |  | 110 | 	// subscript operators
 | 
        
           |  |  | 111 | 	const wchar_t operator[] ( int num ) const;
 | 
        
           |  |  | 112 | 	wchar_t &operator[] ( int num );
 | 
        
           |  |  | 113 |   | 
        
           |  |  | 114 | 	// addition operators
 | 
        
           | 189 | cycrow | 115 | 	WString operator+ (const wchar_t* str) const;
 | 
        
           |  |  | 116 | 	WString operator+ (const char* str) const;
 | 
        
           | 186 | cycrow | 117 | 	WString operator+ ( const std::wstring &str ) const;
 | 
        
           |  |  | 118 | 	WString operator+ ( const WString &str ) const;
 | 
        
           |  |  | 119 | 	WString operator+ ( const wchar_t c ) const;
 | 
        
           |  |  | 120 | 	WString operator+ ( const long l ) const;
 | 
        
           |  |  | 121 | 	WString operator+ ( const unsigned long l ) const;
 | 
        
           |  |  | 122 | 	WString operator+ ( const float f ) const;
 | 
        
           |  |  | 123 | 	WString operator+ ( const double f ) const;
 | 
        
           |  |  | 124 |   | 
        
           |  |  | 125 | 	// compound operators
 | 
        
           |  |  | 126 | 	const WString &operator+= ( const wchar_t *str );
 | 
        
           |  |  | 127 | 	const WString &operator+= ( const std::wstring &str );
 | 
        
           |  |  | 128 | 	const WString &operator+= ( const WString &str );
 | 
        
           |  |  | 129 | 	const WString &operator+= ( const wchar_t c );
 | 
        
           |  |  | 130 | 	const WString &operator+= ( const long l );
 | 
        
           |  |  | 131 | 	const WString &operator+= ( const unsigned long l );
 | 
        
           |  |  | 132 | 	const WString &operator+= ( const float f );
 | 
        
           |  |  | 133 | 	const WString &operator+= ( const double f );
 | 
        
           |  |  | 134 |   | 
        
           |  |  | 135 | 	// comparison operators
 | 
        
           |  |  | 136 | 	bool operator== ( const wchar_t *str ) const;
 | 
        
           |  |  | 137 | 	bool operator== ( const std::wstring &str ) const;
 | 
        
           |  |  | 138 | 	bool operator== ( const WString &str ) const;
 | 
        
           |  |  | 139 |   | 
        
           |  |  | 140 | 	bool operator!= ( const wchar_t *str ) const;
 | 
        
           |  |  | 141 | 	bool operator!= ( const std::wstring &str ) const;
 | 
        
           |  |  | 142 | 	bool operator!= ( const WString &str ) const;
 | 
        
           |  |  | 143 |   | 
        
           |  |  | 144 | 	bool operator !() const;
 | 
        
           |  |  | 145 |   | 
        
           |  |  | 146 | 	bool Compare(const WString &str, bool bCaseSensative = false) const;
 | 
        
           |  |  | 147 | 	bool Compare(const wchar_t *str, bool bCaseSensative = false) const;
 | 
        
           |  |  | 148 |   | 
        
           |  |  | 149 | 	// file handling
 | 
        
           |  |  | 150 | 	wchar_t *readToEndOfLine(wchar_t *data);
 | 
        
           |  |  | 151 | 	const WString &readToEndOfLine(FILE *id, int *line, bool upper);
 | 
        
           |  |  | 152 |   | 
        
           |  |  | 153 | 	// tokens
 | 
        
           |  |  | 154 | 	int countToken(const wchar_t *token) const;
 | 
        
           |  |  | 155 | 	WString token(const wchar_t *token, int tok) const;
 | 
        
           |  |  | 156 | 	WString tokens(const wchar_t *token, int from, int to = 0) const;
 | 
        
           |  |  | 157 | 	WString *tokenise(const wchar_t *token, int *max) const;
 | 
        
           | 197 | cycrow | 158 | 	size_t tokenise(const wchar_t* token, std::vector<WString> &str) const;
 | 
        
           | 186 | cycrow | 159 | 	WString replaceToken(const wchar_t *token, int from, const WString &replace) const;
 | 
        
           |  |  | 160 | 	WString remToken(const wchar_t* token, int from) const;
 | 
        
           |  |  | 161 | 	WString remTokens(const wchar_t* token, int from, int to = -1) const;
 | 
        
           |  |  | 162 | 	WString word(int word) const;
 | 
        
           |  |  | 163 | 	WString words(int from, int to = 0) const;
 | 
        
           |  |  | 164 | 	WString addToken(const wchar_t *token, const Utils::WString &str) const;
 | 
        
           |  |  | 165 |   | 
        
           |  |  | 166 | 	// find/replacement
 | 
        
           |  |  | 167 | 	int findPos(const WString &find, int iStartPos = 0) const;
 | 
        
           |  |  | 168 | 	WString findReplace(const WString &find, const WString &replace ) const;
 | 
        
           |  |  | 169 | 	WString remove(wchar_t c) const;
 | 
        
           |  |  | 170 | 	const WString &removeChar(wchar_t c);
 | 
        
           |  |  | 171 | 	const WString &removeChar(const wchar_t *cs);
 | 
        
           |  |  | 172 | 	WString findRemove(const WString &find) const;
 | 
        
           |  |  | 173 | 	WString stripHtml() const;
 | 
        
           |  |  | 174 | 	WString removeIf(int iChar, wchar_t c) const;
 | 
        
           |  |  | 175 |   | 
        
           |  |  | 176 | 	bool containsAny(const WString &str, bool bCaseSensative = false) const;
 | 
        
           |  |  | 177 | 	bool contains(const WString &str, bool bCaseSensative = false) const;
 | 
        
           |  |  | 178 | 	bool contains(wchar_t c, bool bCaseSensative = false) const;
 | 
        
           |  |  | 179 | 	bool isin(const WString &str, bool bCaseSensative = false) const;
 | 
        
           |  |  | 180 | 	bool isin(wchar_t c, bool bCaseSensative = false) const;
 | 
        
           |  |  | 181 | 	int compareVersion(const Utils::WString &v) const;
 | 
        
           |  |  | 182 | 	bool match(const Utils::WString &pattern) const;
 | 
        
           |  |  | 183 |   | 
        
           | 204 | cycrow | 184 | 	WString& prepend(const WString &str);
 | 
        
           |  |  | 185 |   | 
        
           | 186 | cycrow | 186 | 	// sub string
 | 
        
           |  |  | 187 | 	WString left(long num) const;
 | 
        
           |  |  | 188 | 	WString right(int num) const;
 | 
        
           |  |  | 189 | 	WString mid(int start, int end) const;
 | 
        
           |  |  | 190 | 	WString between(const WString &before, const WString &after) const;
 | 
        
           |  |  | 191 |   | 
        
           |  |  | 192 | 	bool isNumber(bool integer = false) const;
 | 
        
           |  |  | 193 | 	bool isCharNumber(int c) const;
 | 
        
           |  |  | 194 | 	const WString &removeFirstSpace();
 | 
        
           |  |  | 195 | 	const WString &removeEndSpace();
 | 
        
           |  |  | 196 | 	const WString &truncate(int iNum);
 | 
        
           |  |  | 197 | 	const WString &padNumber(int iNum);
 | 
        
           |  |  | 198 | 	const WString &pad(int iAmoumt, wchar_t cWith);
 | 
        
           |  |  | 199 |   | 
        
           |  |  | 200 | 	WString lower() const;
 | 
        
           |  |  | 201 | 	WString upper() const;
 | 
        
           |  |  | 202 | 	const WString &toLower();
 | 
        
           |  |  | 203 | 	const WString &toUpper();
 | 
        
           |  |  | 204 |   | 
        
           |  |  | 205 | 	const WString &toFilename();
 | 
        
           |  |  | 206 | 	WString asFilename() const;
 | 
        
           |  |  | 207 |   | 
        
           |  |  | 208 | private:
 | 
        
           |  |  | 209 | 	void _assign(const wchar_t* str) { this->assign(str); }
 | 
        
           |  |  | 210 | 	void _assign(const wchar_t* str, size_t len) { this->assign(str, len); }
 | 
        
           |  |  | 211 | 	bool _isCharNumber(wchar_t c) const;
 | 
        
           |  |  | 212 | 	Utils::WString::size_type _token_nextPos(const wchar_t *token, Utils::WString::size_type curPos) const;
 | 
        
           |  |  | 213 | };
 | 
        
           |  |  | 214 |   | 
        
           |  |  | 215 | SPKEXPORT WString operator+(const wchar_t* str1, const WString& str2);
 | 
        
           | 189 | cycrow | 216 | SPKEXPORT WString operator+(const char* str1, const WString& str2);
 | 
        
           | 186 | cycrow | 217 |   | 
        
           |  |  | 218 | #pragma warning( pop )
 | 
        
           |  |  | 219 |   | 
        
           |  |  | 220 | }
 |