8 |
cycrow |
1 |
#pragma once
|
|
|
2 |
|
|
|
3 |
#include <string>
|
|
|
4 |
#include "../spkdll.h"
|
185 |
cycrow |
5 |
#include "../spkdef.h"
|
8 |
cycrow |
6 |
|
189 |
cycrow |
7 |
enum Compare {
|
50 |
cycrow |
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;
|
284 |
cycrow |
70 |
long long toLong64() const;
|
121 |
cycrow |
71 |
int toInt() const;
|
8 |
cycrow |
72 |
double toDouble() const;
|
|
|
73 |
float toFloat() const;
|
|
|
74 |
|
188 |
cycrow |
75 |
const Utils::WString toWString() const;
|
284 |
cycrow |
76 |
const long long lengthLL() const;
|
174 |
cycrow |
77 |
|
8 |
cycrow |
78 |
// casting operators
|
186 |
cycrow |
79 |
inline operator const char *() const { return (const char *)c_str(); }
|
|
|
80 |
inline operator char *() const { return (char *)c_str(); }
|
|
|
81 |
inline operator const unsigned char *() const { return (const unsigned char *)c_str(); }
|
|
|
82 |
inline operator unsigned char *() const { return (unsigned char *)c_str(); }
|
|
|
83 |
inline operator const std::string &() const { return (const std::string &)*this; }
|
10 |
cycrow |
84 |
inline operator const int () const { return this->toLong(); }
|
8 |
cycrow |
85 |
inline operator const long () const { return this->toLong(); }
|
|
|
86 |
inline operator const double () const { return this->toDouble(); }
|
|
|
87 |
inline operator const float () const { return this->toFloat(); }
|
101 |
cycrow |
88 |
inline operator const bool () const { return (this->empty() ? false : ((this->toLong()) ? true : false)); }
|
8 |
cycrow |
89 |
|
|
|
90 |
// assignment operators
|
188 |
cycrow |
91 |
const SString &operator= ( const SString &str );
|
|
|
92 |
const SString &operator= ( const std::string &str );
|
|
|
93 |
const SString &operator= ( const char *str );
|
|
|
94 |
const SString &operator= ( const unsigned char *str );
|
|
|
95 |
const SString &operator= ( unsigned char c );
|
|
|
96 |
const SString &operator= ( char c );
|
|
|
97 |
const SString &operator= ( long l );
|
|
|
98 |
const SString &operator= ( unsigned long l );
|
|
|
99 |
const SString &operator= ( float l );
|
|
|
100 |
const SString &operator= ( double l );
|
8 |
cycrow |
101 |
|
|
|
102 |
// subscript operators
|
285 |
cycrow |
103 |
#ifdef _WIN32
|
|
|
104 |
const unsigned char operator[] (int num) const;
|
|
|
105 |
unsigned char& operator[] (int num);
|
|
|
106 |
#else
|
|
|
107 |
const unsigned char operator[] (size_t num) const;
|
|
|
108 |
unsigned char& operator[] (size_t num);
|
|
|
109 |
#endif
|
8 |
cycrow |
110 |
|
|
|
111 |
// addition operators
|
188 |
cycrow |
112 |
SString operator+ ( const char *str ) const;
|
|
|
113 |
SString operator+ ( const unsigned char *str ) const;
|
|
|
114 |
SString operator+ ( const std::string &str ) const;
|
|
|
115 |
SString operator+ ( const SString &str ) const;
|
|
|
116 |
SString operator+ ( const char c ) const;
|
|
|
117 |
SString operator+ ( const unsigned char c ) const;
|
|
|
118 |
SString operator+ ( const long l ) const;
|
|
|
119 |
SString operator+ ( const unsigned long l ) const;
|
|
|
120 |
SString operator+ ( const float f ) const;
|
|
|
121 |
SString operator+ ( const double f ) const;
|
8 |
cycrow |
122 |
|
|
|
123 |
// compound operators
|
188 |
cycrow |
124 |
const SString &operator+= ( const char *str );
|
|
|
125 |
const SString &operator+= ( const unsigned char *str );
|
|
|
126 |
const SString &operator+= ( const std::string &str );
|
|
|
127 |
const SString &operator+= ( const SString &str );
|
|
|
128 |
const SString &operator+= ( const char c );
|
|
|
129 |
const SString &operator+= ( const unsigned char c );
|
|
|
130 |
const SString &operator+= ( const long l );
|
|
|
131 |
const SString &operator+= ( const unsigned long l );
|
|
|
132 |
const SString &operator+= ( const float f );
|
|
|
133 |
const SString &operator+= ( const double f );
|
8 |
cycrow |
134 |
|
|
|
135 |
// comparison operators
|
|
|
136 |
bool operator== ( const char *str ) const;
|
|
|
137 |
bool operator== ( const unsigned char *str ) const;
|
|
|
138 |
bool operator== ( const std::string &str ) const;
|
188 |
cycrow |
139 |
bool operator== ( const SString &str ) const;
|
8 |
cycrow |
140 |
|
|
|
141 |
bool operator!= ( const char *str ) const;
|
|
|
142 |
bool operator!= ( const unsigned char *str ) const;
|
|
|
143 |
bool operator!= ( const std::string &str ) const;
|
188 |
cycrow |
144 |
bool operator!= ( const SString &str ) const;
|
8 |
cycrow |
145 |
|
101 |
cycrow |
146 |
bool operator !() const;
|
|
|
147 |
|
188 |
cycrow |
148 |
bool Compare(const SString &str, bool bCaseSensative = false) const;
|
8 |
cycrow |
149 |
bool Compare(const unsigned char *str, bool bCaseSensative = false) const;
|
|
|
150 |
bool Compare(const char *str, bool bCaseSensative = false) const;
|
|
|
151 |
|
39 |
cycrow |
152 |
// file handling
|
8 |
cycrow |
153 |
unsigned char *readToEndOfLine(unsigned char *data);
|
|
|
154 |
char *readToEndOfLine(char *data);
|
188 |
cycrow |
155 |
const SString &readToEndOfLine(FILE *id, int *line, bool upper);
|
8 |
cycrow |
156 |
|
|
|
157 |
// tokens
|
|
|
158 |
int countToken(const char *token) const;
|
188 |
cycrow |
159 |
SString token(const char *token, int tok) const;
|
|
|
160 |
SString tokens(const char *token, int from, int to = 0) const;
|
|
|
161 |
SString *tokenise(const char *token, int *max) const;
|
|
|
162 |
SString replaceToken(const char *token, int from, const SString &replace) const;
|
|
|
163 |
SString remToken(const char* token, int from) const;
|
|
|
164 |
SString remTokens(const char* token, int from, int to = -1) const;
|
|
|
165 |
SString word(int word) const;
|
|
|
166 |
SString words(int from, int to = 0) const;
|
|
|
167 |
SString addToken(const char *token, const Utils::SString &str) const;
|
14 |
cycrow |
168 |
|
39 |
cycrow |
169 |
// find/replacement
|
284 |
cycrow |
170 |
long long findPos(const SString &find, size_t iStartPos = 0) const;
|
188 |
cycrow |
171 |
SString findReplace(const SString &find, const SString &replace ) const;
|
|
|
172 |
SString remove(char c) const;
|
|
|
173 |
const SString &removeChar(char c);
|
|
|
174 |
const SString &removeChar(const char *cs);
|
|
|
175 |
SString findRemove(const SString &find) const;
|
|
|
176 |
SString stripHtml() const;
|
|
|
177 |
SString removeIf(int iChar, char c) const;
|
8 |
cycrow |
178 |
|
188 |
cycrow |
179 |
bool containsAny(const SString &str, bool bCaseSensative = false) const;
|
|
|
180 |
bool contains(const SString &str, bool bCaseSensative = false) const;
|
126 |
cycrow |
181 |
bool contains(char c, bool bCaseSensative = false) const;
|
188 |
cycrow |
182 |
bool isin(const SString &str, bool bCaseSensative = false) const;
|
8 |
cycrow |
183 |
bool isin(char c, bool bCaseSensative = false) const;
|
188 |
cycrow |
184 |
int compareVersion(const Utils::SString &v) const;
|
|
|
185 |
bool match(const Utils::SString &pattern) const;
|
8 |
cycrow |
186 |
|
39 |
cycrow |
187 |
// sub string
|
284 |
cycrow |
188 |
SString left(long long num) const;
|
|
|
189 |
SString right(long long num) const;
|
|
|
190 |
SString mid(long long start, long long end) const;
|
188 |
cycrow |
191 |
SString between(const SString &before, const SString &after) const;
|
8 |
cycrow |
192 |
|
13 |
cycrow |
193 |
bool isNumber(bool integer = false) const;
|
|
|
194 |
bool isCharNumber(int c) const;
|
188 |
cycrow |
195 |
const SString &removeFirstSpace();
|
|
|
196 |
const SString &removeEndSpace();
|
|
|
197 |
const SString &truncate(int iNum);
|
|
|
198 |
const SString &padNumber(int iNum);
|
|
|
199 |
const SString &pad(int iAmoumt, char cWith);
|
13 |
cycrow |
200 |
|
188 |
cycrow |
201 |
SString lower() const;
|
|
|
202 |
SString upper() const;
|
|
|
203 |
const SString &toLower();
|
|
|
204 |
const SString &toUpper();
|
43 |
cycrow |
205 |
|
188 |
cycrow |
206 |
const SString &toFilename();
|
|
|
207 |
SString asFilename() const;
|
81 |
cycrow |
208 |
|
8 |
cycrow |
209 |
private:
|
196 |
cycrow |
210 |
void _assign(const wchar_t* str);
|
|
|
211 |
void _assign(const wchar_t* str, size_t len);
|
13 |
cycrow |
212 |
bool _isCharNumber(char c) const;
|
188 |
cycrow |
213 |
Utils::SString::size_type _token_nextPos(const char *token, Utils::SString::size_type curPos) const;
|
8 |
cycrow |
214 |
};
|
|
|
215 |
|
188 |
cycrow |
216 |
SPKEXPORT SString operator+(const char* str1, const SString& str2);
|
|
|
217 |
SPKEXPORT SString operator+(const unsigned char* str1, const SString& str2);
|
121 |
cycrow |
218 |
|
188 |
cycrow |
219 |
typedef SString String;
|
121 |
cycrow |
220 |
#pragma warning( pop )
|
|
|
221 |
|
8 |
cycrow |
222 |
}
|