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