@@ -41,6 +41,12 @@ class StringSumHelper;
41
41
// The string class
42
42
class String
43
43
{
44
+ // use a function pointer to allow for "if (s)" without the
45
+ // complications of an operator bool(). for more information, see:
46
+ // http://www.artima.com/cppsource/safebool.html
47
+ typedef void (String::*StringIfHelperType)() const ;
48
+ void StringIfHelper () const {}
49
+
44
50
public:
45
51
// constructors
46
52
// creates a copy of the initial value.
@@ -53,12 +59,12 @@ class String
53
59
String (String &&rval);
54
60
String (StringSumHelper &&rval);
55
61
#endif
56
- String (char c);
57
- String (unsigned char c );
58
- String (int , unsigned char base=10 );
59
- String (unsigned int , unsigned char base=10 );
60
- String (long , unsigned char base=10 );
61
- String (unsigned long , unsigned char base=10 );
62
+ explicit String (char c);
63
+ explicit String (unsigned char , unsigned char base= 10 );
64
+ explicit String (int , unsigned char base=10 );
65
+ explicit String (unsigned int , unsigned char base=10 );
66
+ explicit String (long , unsigned char base=10 );
67
+ explicit String (unsigned long , unsigned char base=10 );
62
68
~String (void );
63
69
64
70
// memory management
@@ -77,44 +83,26 @@ class String
77
83
String & operator = (String &&rval);
78
84
String & operator = (StringSumHelper &&rval);
79
85
#endif
80
- String & operator = (char c);
81
86
82
87
// concat
83
88
// returns true on success, false on failure (in which case, the string
84
89
// is left unchanged). if the argument is null or invalid, the
85
90
// concatenation is considered unsucessful.
86
91
unsigned char concat (const String &str);
87
92
unsigned char concat (const char *cstr);
88
- unsigned char concat (char c);
89
- unsigned char concat (unsigned char c) {return concat ((char )c);}
90
- unsigned char concat (int num);
91
- unsigned char concat (unsigned int num);
92
- unsigned char concat (long num);
93
- unsigned char concat (unsigned long num);
94
93
95
94
// if there's not enough memory for the concatenated value, the string
96
95
// will be left unchanged (but this isn't signalled in any way)
97
96
String & operator += (const String &rhs) {concat (rhs); return (*this );}
98
97
String & operator += (const char *cstr) {concat (cstr); return (*this );}
99
- String & operator += (char c) {concat (c); return (*this );}
100
- String & operator += (unsigned char c) {concat ((char )c); return (*this );}
101
- String & operator += (int num) {concat (num); return (*this );}
102
- String & operator += (unsigned int num) {concat (num); return (*this );}
103
- String & operator += (long num) {concat (num); return (*this );}
104
- String & operator += (unsigned long num) {concat (num); return (*this );}
105
98
106
99
// concatenate
107
100
friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
108
101
friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
109
- friend StringSumHelper & operator + (const StringSumHelper &lhs, char c);
110
- friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char c);
111
- friend StringSumHelper & operator + (const StringSumHelper &lhs, int num);
112
- friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num);
113
- friend StringSumHelper & operator + (const StringSumHelper &lhs, long num);
114
- friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num);
115
102
116
103
// comparison
117
- operator bool () const ;
104
+ operator StringIfHelperType () const { return buffer ? &String::StringIfHelper : 0 ; }
105
+
118
106
int compareTo (const String &s) const ;
119
107
unsigned char equals (const String &s) const ;
120
108
unsigned char equals (const char *cstr) const ;
@@ -185,48 +173,7 @@ class StringSumHelper : public String
185
173
public:
186
174
StringSumHelper (const String &s) : String(s) {}
187
175
StringSumHelper (const char *p) : String(p) {}
188
- StringSumHelper (char c) : String(c) {}
189
- StringSumHelper (unsigned char c) : String(c) {}
190
- StringSumHelper (int num) : String(num, 10 ) {}
191
- StringSumHelper (unsigned int num) : String(num, 10 ) {}
192
- StringSumHelper (long num) : String(num, 10 ) {}
193
- StringSumHelper (unsigned long num) : String(num, 10 ) {}
194
176
};
195
177
196
- inline StringSumHelper operator + (const String &lhs, const String &rhs)
197
- { return StringSumHelper (lhs) + rhs; }
198
-
199
- inline StringSumHelper operator + (const String &lhs, const char *cstr)
200
- { return StringSumHelper (lhs) + cstr; }
201
- inline StringSumHelper operator + (const String &lhs, char c)
202
- { return StringSumHelper (lhs) + c; }
203
- inline StringSumHelper operator + (const String &lhs, unsigned char c)
204
- { return StringSumHelper (lhs) + c; }
205
- inline StringSumHelper operator + (const String &lhs, int num)
206
- { return StringSumHelper (lhs) + num; }
207
- inline StringSumHelper operator + (const String &lhs, unsigned int num)
208
- { return StringSumHelper (lhs) + num; }
209
- inline StringSumHelper operator + (const String &lhs, long num)
210
- { return StringSumHelper (lhs) + num; }
211
- inline StringSumHelper operator + (const String &lhs, unsigned long num)
212
- { return StringSumHelper (lhs) + num; }
213
-
214
- inline StringSumHelper operator + (const char *cstr, const String &rhs)
215
- { return StringSumHelper (cstr) + rhs; }
216
- inline StringSumHelper operator + (char c, const String &rhs)
217
- { return StringSumHelper (c) + rhs; }
218
- inline StringSumHelper operator + (unsigned char c, const String &rhs)
219
- { return StringSumHelper (c) + rhs; }
220
- inline StringSumHelper operator + (int num, const String &rhs)
221
- { return StringSumHelper (num) + rhs; }
222
- inline StringSumHelper operator + (unsigned int num, const String &rhs)
223
- { return StringSumHelper (num) + rhs; }
224
- inline StringSumHelper operator + (long num, const String &rhs)
225
- { return StringSumHelper (num) + rhs; }
226
- inline StringSumHelper operator + (unsigned long num, const String &rhs)
227
- { return StringSumHelper (num) + rhs; }
228
-
229
-
230
-
231
178
#endif // __cplusplus
232
179
#endif // String_class_h
0 commit comments