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