Subversion Repositories spk

Rev

Rev 101 | Rev 109 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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