Subversion Repositories spk

Rev

Rev 94 | Rev 104 | 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, ...);
41
 
50 cycrow 42
	static String PadNumber(long iNum, int iAmount);
43
	static String Number(long l) { return String(l); }
44
	static String Format(const char *sFormat, ...);
85 cycrow 45
	static String Null();
50 cycrow 46
 
94 cycrow 47
	bool toBool() const;
8 cycrow 48
	long toLong() const;
49
	double toDouble() const;
50
	float toFloat() const;
51
 
52
	// casting operators
53
	inline operator const char *() const			{ return (const char *)this->c_str(); }
54
	inline operator char *() const					{ return (char *)this->c_str(); }
55
	inline operator const unsigned char *() const	{ return (const unsigned char *)this->c_str(); }
56
	inline operator unsigned char *() const			{ return (unsigned char *)this->c_str(); }
57
	inline operator const std::string &() const		{ return (const std::string &)*this; }
10 cycrow 58
	inline operator const int () const				{ return this->toLong(); }
8 cycrow 59
	inline operator const long () const				{ return this->toLong(); }
60
	inline operator const double () const			{ return this->toDouble(); }
61
	inline operator const float () const			{ return this->toFloat(); }
101 cycrow 62
	inline operator const bool () const				{ return (this->empty() ? false : ((this->toLong()) ? true : false)); }
8 cycrow 63
 
64
	// assignment operators
65
	const String &operator= ( const String &str );
66
	const String &operator= ( const std::string &str );
67
	const String &operator= ( const char *str );
68
	const String &operator= ( const unsigned char *str );
69
	const String &operator= ( unsigned char c );
70
	const String &operator= ( char c );
71
	const String &operator= ( long l );
72
	const String &operator= ( unsigned long l );
73
	const String &operator= ( float l );
74
	const String &operator= ( double l );
75
 
76
	// subscript operators
77
	const unsigned char operator[] ( int num ) const;
78
	unsigned char &operator[] ( int num );
79
 
80
	// addition operators
81
	String operator+ ( const char *str ) const;
82
	String operator+ ( const unsigned char *str ) const;
83
	String operator+ ( const std::string &str ) const;
84
	String operator+ ( const String &str ) const;
85
	String operator+ ( const char c ) const;
86
	String operator+ ( const unsigned char c ) const;
87
	String operator+ ( const long l ) const;
88
	String operator+ ( const unsigned long l ) const;
89
	String operator+ ( const float f ) const;
90
	String operator+ ( const double f ) const;
91
 
92
	// compound operators
93
	const String &operator+= ( const char *str );
94
	const String &operator+= ( const unsigned char *str );
95
	const String &operator+= ( const std::string &str );
96
	const String &operator+= ( const String &str );
97
	const String &operator+= ( const char c );
98
	const String &operator+= ( const unsigned char c );
99
	const String &operator+= ( const long l );
100
	const String &operator+= ( const unsigned long l );
101
	const String &operator+= ( const float f );
102
	const String &operator+= ( const double f );
103
 
104
	// comparison operators
105
	bool operator== ( const char *str ) const;
106
	bool operator== ( const unsigned char *str ) const;
107
	bool operator== ( const std::string &str ) const;
108
	bool operator== ( const String &str ) const;
109
 
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
 
101 cycrow 115
	bool operator !() const;
116
 
8 cycrow 117
	bool Compare(const String &str, bool bCaseSensative = false) const;
118
	bool Compare(const unsigned char *str, bool bCaseSensative = false) const;
119
	bool Compare(const char *str, bool bCaseSensative = false) const;
120
 
39 cycrow 121
	// file handling
8 cycrow 122
	unsigned char *readToEndOfLine(unsigned char *data);
123
	char *readToEndOfLine(char *data);
39 cycrow 124
	const String &readToEndOfLine(FILE *id, int *line, bool upper);
8 cycrow 125
 
126
	// tokens
127
	int countToken(const char *token) const;
128
	String token(const char *token, int tok) const;
129
	String tokens(const char *token, int from, int to = 0) const;
10 cycrow 130
	String *tokenise(const char *token, int *max) const;
39 cycrow 131
	String replaceToken(const char *token, int from, const String &replace) const;
132
	String remToken(const char *token, int t) const;
133
	String word(int word) const;
134
	String words(int from, int to = 0) const;
14 cycrow 135
 
39 cycrow 136
	// find/replacement
137
	int findPos(const String &find, int iStartPos = 0) const;
8 cycrow 138
	String findReplace(const String &find, const String &replace ) const;
39 cycrow 139
	String remove(char c) const;
140
	const String &removeChar(char c);
69 cycrow 141
	const String &removeChar(const char *cs);
48 cycrow 142
	String findRemove(const String &find) const;
143
	String stripHtml() const;
58 cycrow 144
	String removeIf(int iChar, char c) const;
8 cycrow 145
 
146
	bool isin(const String &str, bool bCaseSensative = false) const;
147
	bool isin(char c, bool bCaseSensative = false) const;
50 cycrow 148
	int compareVersion(const Utils::String &v) const;
8 cycrow 149
 
39 cycrow 150
	// sub string
8 cycrow 151
	String left(long num) const;
152
	String right(int num) const;
39 cycrow 153
	String mid(int start, int end) const;
56 cycrow 154
	String between(const String &before, const String &after) const;
8 cycrow 155
 
13 cycrow 156
	bool isNumber(bool integer = false) const;
157
	bool isCharNumber(int c) const;
14 cycrow 158
	const String &removeFirstSpace();
39 cycrow 159
	const String &removeEndSpace();
34 cycrow 160
	const String &truncate(int iNum);
50 cycrow 161
	const String &padNumber(int iNum);
162
	const String &pad(int iAmoumt, char cWith);
13 cycrow 163
 
43 cycrow 164
	String lower() const;
165
	String upper() const;
166
	const String &toLower();
167
	const String &toUpper();
168
 
81 cycrow 169
	const String &toFilename();
170
	String asFilename() const;
171
 
8 cycrow 172
private:
13 cycrow 173
	bool _isCharNumber(char c) const;
86 cycrow 174
	Utils::String::size_type _token_nextPos(const char *token, Utils::String::size_type curPos) const;
8 cycrow 175
};
176
 
177
String operator+(const char *str1, const String &str2);
178
}