Subversion Repositories spk

Rev

Rev 86 | Rev 101 | 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(); }
10 cycrow 62
	inline operator const bool () const				{ return (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
 
115
	bool Compare(const String &str, bool bCaseSensative = false) const;
116
	bool Compare(const unsigned char *str, bool bCaseSensative = false) const;
117
	bool Compare(const char *str, bool bCaseSensative = false) const;
118
 
39 cycrow 119
	// file handling
8 cycrow 120
	unsigned char *readToEndOfLine(unsigned char *data);
121
	char *readToEndOfLine(char *data);
39 cycrow 122
	const String &readToEndOfLine(FILE *id, int *line, bool upper);
8 cycrow 123
 
124
	// tokens
125
	int countToken(const char *token) const;
126
	String token(const char *token, int tok) const;
127
	String tokens(const char *token, int from, int to = 0) const;
10 cycrow 128
	String *tokenise(const char *token, int *max) const;
39 cycrow 129
	String replaceToken(const char *token, int from, const String &replace) const;
130
	String remToken(const char *token, int t) const;
131
	String word(int word) const;
132
	String words(int from, int to = 0) const;
14 cycrow 133
 
39 cycrow 134
	// find/replacement
135
	int findPos(const String &find, int iStartPos = 0) const;
8 cycrow 136
	String findReplace(const String &find, const String &replace ) const;
39 cycrow 137
	String remove(char c) const;
138
	const String &removeChar(char c);
69 cycrow 139
	const String &removeChar(const char *cs);
48 cycrow 140
	String findRemove(const String &find) const;
141
	String stripHtml() const;
58 cycrow 142
	String removeIf(int iChar, char c) const;
8 cycrow 143
 
144
	bool isin(const String &str, bool bCaseSensative = false) const;
145
	bool isin(char c, bool bCaseSensative = false) const;
50 cycrow 146
	int compareVersion(const Utils::String &v) const;
8 cycrow 147
 
39 cycrow 148
	// sub string
8 cycrow 149
	String left(long num) const;
150
	String right(int num) const;
39 cycrow 151
	String mid(int start, int end) const;
56 cycrow 152
	String between(const String &before, const String &after) const;
8 cycrow 153
 
13 cycrow 154
	bool isNumber(bool integer = false) const;
155
	bool isCharNumber(int c) const;
14 cycrow 156
	const String &removeFirstSpace();
39 cycrow 157
	const String &removeEndSpace();
34 cycrow 158
	const String &truncate(int iNum);
50 cycrow 159
	const String &padNumber(int iNum);
160
	const String &pad(int iAmoumt, char cWith);
13 cycrow 161
 
43 cycrow 162
	String lower() const;
163
	String upper() const;
164
	const String &toLower();
165
	const String &toUpper();
166
 
81 cycrow 167
	const String &toFilename();
168
	String asFilename() const;
169
 
8 cycrow 170
private:
13 cycrow 171
	bool _isCharNumber(char c) const;
86 cycrow 172
	Utils::String::size_type _token_nextPos(const char *token, Utils::String::size_type curPos) const;
8 cycrow 173
};
174
 
175
String operator+(const char *str1, const String &str2);
176
}