8 |
cycrow |
1 |
#pragma once
|
|
|
2 |
|
|
|
3 |
#include <string>
|
|
|
4 |
#include "../spkdll.h"
|
|
|
5 |
|
|
|
6 |
namespace Utils {
|
|
|
7 |
/**
|
|
|
8 |
* String wrapper class
|
|
|
9 |
*/
|
|
|
10 |
class SPKEXPORT String : public std::string
|
|
|
11 |
{
|
|
|
12 |
public:
|
|
|
13 |
// constructors
|
|
|
14 |
String(void);
|
|
|
15 |
String(const char *str);
|
|
|
16 |
String(const unsigned char *str);
|
|
|
17 |
String(const std::string &str);
|
14 |
cycrow |
18 |
String(const char c);
|
8 |
cycrow |
19 |
String(const unsigned char c);
|
|
|
20 |
String(const String &str);
|
|
|
21 |
String(long l);
|
|
|
22 |
String(unsigned long l);
|
|
|
23 |
String(float f);
|
|
|
24 |
String(double f);
|
|
|
25 |
|
|
|
26 |
virtual ~String(void);
|
|
|
27 |
|
|
|
28 |
// conversion functions
|
|
|
29 |
void fromLong(long l);
|
|
|
30 |
void fromFloat(float f);
|
|
|
31 |
void fromFloat(float f, int dp);
|
|
|
32 |
void fromDouble(double f);
|
|
|
33 |
void fromDouble(double f, int dp);
|
|
|
34 |
const String &format(const char *sFormat, ...);
|
|
|
35 |
|
10 |
cycrow |
36 |
static String number(long l) { return String(l); }
|
8 |
cycrow |
37 |
static String fromFormat(const char *sFormat, ...);
|
|
|
38 |
long toLong() const;
|
|
|
39 |
double toDouble() const;
|
|
|
40 |
float toFloat() const;
|
|
|
41 |
|
|
|
42 |
// casting operators
|
|
|
43 |
inline operator const char *() const { return (const char *)this->c_str(); }
|
|
|
44 |
inline operator char *() const { return (char *)this->c_str(); }
|
|
|
45 |
inline operator const unsigned char *() const { return (const unsigned char *)this->c_str(); }
|
|
|
46 |
inline operator unsigned char *() const { return (unsigned char *)this->c_str(); }
|
|
|
47 |
inline operator const std::string &() const { return (const std::string &)*this; }
|
10 |
cycrow |
48 |
inline operator const int () const { return this->toLong(); }
|
8 |
cycrow |
49 |
inline operator const long () const { return this->toLong(); }
|
|
|
50 |
inline operator const double () const { return this->toDouble(); }
|
|
|
51 |
inline operator const float () const { return this->toFloat(); }
|
10 |
cycrow |
52 |
inline operator const bool () const { return (this->toLong()) ? true : false; }
|
8 |
cycrow |
53 |
|
|
|
54 |
// assignment operators
|
|
|
55 |
const String &operator= ( const String &str );
|
|
|
56 |
const String &operator= ( const std::string &str );
|
|
|
57 |
const String &operator= ( const char *str );
|
|
|
58 |
const String &operator= ( const unsigned char *str );
|
|
|
59 |
const String &operator= ( unsigned char c );
|
|
|
60 |
const String &operator= ( char c );
|
|
|
61 |
const String &operator= ( long l );
|
|
|
62 |
const String &operator= ( unsigned long l );
|
|
|
63 |
const String &operator= ( float l );
|
|
|
64 |
const String &operator= ( double l );
|
|
|
65 |
|
|
|
66 |
// subscript operators
|
|
|
67 |
const unsigned char operator[] ( int num ) const;
|
|
|
68 |
unsigned char &operator[] ( int num );
|
|
|
69 |
|
|
|
70 |
// addition operators
|
|
|
71 |
String operator+ ( const char *str ) const;
|
|
|
72 |
String operator+ ( const unsigned char *str ) const;
|
|
|
73 |
String operator+ ( const std::string &str ) const;
|
|
|
74 |
String operator+ ( const String &str ) const;
|
|
|
75 |
String operator+ ( const char c ) const;
|
|
|
76 |
String operator+ ( const unsigned char c ) const;
|
|
|
77 |
String operator+ ( const long l ) const;
|
|
|
78 |
String operator+ ( const unsigned long l ) const;
|
|
|
79 |
String operator+ ( const float f ) const;
|
|
|
80 |
String operator+ ( const double f ) const;
|
|
|
81 |
|
|
|
82 |
// compound operators
|
|
|
83 |
const String &operator+= ( const char *str );
|
|
|
84 |
const String &operator+= ( const unsigned char *str );
|
|
|
85 |
const String &operator+= ( const std::string &str );
|
|
|
86 |
const String &operator+= ( const String &str );
|
|
|
87 |
const String &operator+= ( const char c );
|
|
|
88 |
const String &operator+= ( const unsigned char c );
|
|
|
89 |
const String &operator+= ( const long l );
|
|
|
90 |
const String &operator+= ( const unsigned long l );
|
|
|
91 |
const String &operator+= ( const float f );
|
|
|
92 |
const String &operator+= ( const double f );
|
|
|
93 |
|
|
|
94 |
// comparison operators
|
|
|
95 |
bool operator== ( const char *str ) const;
|
|
|
96 |
bool operator== ( const unsigned char *str ) const;
|
|
|
97 |
bool operator== ( const std::string &str ) const;
|
|
|
98 |
bool operator== ( const String &str ) const;
|
|
|
99 |
|
|
|
100 |
bool operator!= ( const char *str ) const;
|
|
|
101 |
bool operator!= ( const unsigned char *str ) const;
|
|
|
102 |
bool operator!= ( const std::string &str ) const;
|
|
|
103 |
bool operator!= ( const String &str ) const;
|
|
|
104 |
|
|
|
105 |
bool Compare(const String &str, bool bCaseSensative = false) const;
|
|
|
106 |
bool Compare(const unsigned char *str, bool bCaseSensative = false) const;
|
|
|
107 |
bool Compare(const char *str, bool bCaseSensative = false) const;
|
|
|
108 |
|
|
|
109 |
unsigned char *readToEndOfLine(unsigned char *data);
|
|
|
110 |
char *readToEndOfLine(char *data);
|
|
|
111 |
|
|
|
112 |
// tokens
|
|
|
113 |
int countToken(const char *token) const;
|
|
|
114 |
String token(const char *token, int tok) const;
|
|
|
115 |
String tokens(const char *token, int from, int to = 0) const;
|
10 |
cycrow |
116 |
String *tokenise(const char *token, int *max) const;
|
14 |
cycrow |
117 |
String String::replaceToken(const char *token, int from, const String &replace) const;
|
|
|
118 |
|
|
|
119 |
// replacement
|
8 |
cycrow |
120 |
String findReplace(const String &find, const String &replace ) const;
|
10 |
cycrow |
121 |
const String &remove(char c);
|
|
|
122 |
String removeChar(char c) const;
|
8 |
cycrow |
123 |
|
|
|
124 |
bool isin(const String &str, bool bCaseSensative = false) const;
|
|
|
125 |
bool isin(char c, bool bCaseSensative = false) const;
|
|
|
126 |
|
|
|
127 |
String left(long num) const;
|
|
|
128 |
String right(int num) const;
|
|
|
129 |
|
13 |
cycrow |
130 |
bool isNumber(bool integer = false) const;
|
|
|
131 |
bool isCharNumber(int c) const;
|
14 |
cycrow |
132 |
const String &removeFirstSpace();
|
13 |
cycrow |
133 |
|
8 |
cycrow |
134 |
private:
|
13 |
cycrow |
135 |
bool _isCharNumber(char c) const;
|
8 |
cycrow |
136 |
std::string::size_type _token_nextPos(const char *token, std::string::size_type curPos) const;
|
|
|
137 |
};
|
|
|
138 |
|
|
|
139 |
String operator+(const char *str1, const String &str2);
|
|
|
140 |
}
|