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