Subversion Repositories spk

Rev

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