summaryrefslogtreecommitdiffstats
path: root/akregator/src/mk4storage/metakit/include/mk4str.inl
blob: eddbefb8db11a857b4b99da3af2cea42259fefca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// mk4str.inl --
// $Id$
// This is part of Metakit, the homepage is http://www.equi4.com/metakit/

/** @file
 * Members of the string package which are usually inlined
 */

/////////////////////////////////////////////////////////////////////////////
// c4_String

#if q4_MFC                      // Microsoft Foundation Classes
    
#elif q4_STD                    // STL and standard strings

/// Construct empty string
d4_inline c4_String::c4_String ()
{
}

d4_inline c4_String::c4_String (char ch_, int nDup_)
    : string (nDup_, ch_)
{
}

d4_inline c4_String::c4_String (const char* str_)
    : string (str_)
{
}

d4_inline c4_String::c4_String (const void* ptr_, int len_)
    : string ((const char*) ptr_, len_)
{
}

d4_inline c4_String::c4_String (const d4_std::string& s_)
    : string (s_)
{
}

d4_inline c4_String::c4_String (const c4_String& s_)
    : string (s_)
{
}

d4_inline c4_String::~c4_String ()
{
}

d4_inline const c4_String& c4_String::operator= (const c4_String& s_)
{
    *(string*) this = s_;
    return *this;
}

d4_inline c4_String::operator const char* () const
{
    return c_str();
}

d4_inline char c4_String::operator[] (int i) const
{
    return at(i);
}
    
d4_inline c4_String operator+ (const c4_String& a_, const c4_String& b_)
{
    return (d4_std::string) a_ + (d4_std::string) b_; 
}

d4_inline c4_String operator+ (const c4_String& a_, const char* b_)
{
    return (d4_std::string) a_ + (d4_std::string) b_; 
}

d4_inline c4_String operator+ (const char* a_, const c4_String& b_)
{
    return (d4_std::string) a_ + (d4_std::string) b_; 
}

d4_inline const c4_String& c4_String::operator+= (const c4_String& s_)
{
    *(string*) this += s_;
    return *this;
}

d4_inline const c4_String& c4_String::operator+= (const char* s_)
{
    *(string*) this += s_;
    return *this;
}

d4_inline int c4_String::GetLength() const
{
    return length();
}

d4_inline bool c4_String::IsEmpty() const
{
    return empty();
}

d4_inline void c4_String::Empty()
{
    erase();
}

d4_inline c4_String c4_String::Left(int nCount_) const
{
    if (nCount_ > length())
        nCount_ = length();
    return substr(0, nCount_);
}

d4_inline c4_String c4_String::Right(int nCount_) const
{
    if (nCount_ > length())
        nCount_ = length();
    return substr(length() - nCount_, nCount_);
}
                
d4_inline int c4_String::Compare(const char* str_) const
{
    return compare(str_);
}

d4_inline bool c4_String::operator< (const c4_String& str_) const
{
    return compare(str_) < 0;
}

d4_inline int c4_String::Find(char ch_) const
{
    return tqfind(ch_);
}

d4_inline int c4_String::ReverseFind(char ch_) const
{
    return rtqfind(ch_);
}

d4_inline int c4_String::FindOneOf(const char* set_) const
{
    return find_first_of(set_);
}

d4_inline int c4_String::Find(const char* sub_) const
{
    return tqfind(sub_);
}

d4_inline c4_String c4_String::SpanIncluding(const char* set_) const
{
    return substr(0, find_first_not_of(set_));
}

d4_inline c4_String c4_String::SpanExcluding(const char* set_) const
{
    return substr(0, find_first_of(set_));
}

d4_inline bool operator== (const c4_String& a_, const c4_String& b_)
{
    return (d4_std::string) a_ == (d4_std::string) b_;
}

d4_inline bool operator!= (const c4_String& a_, const c4_String& b_)
{
    return (d4_std::string) a_ != (d4_std::string) b_;
}
    
d4_inline bool operator== (const c4_String& a_, const char* b_)
{
    return (d4_std::string) a_ == (d4_std::string) b_;
}

d4_inline bool operator== (const char* a_, const c4_String& b_)
{
    return (d4_std::string) a_ == (d4_std::string) b_;
}

d4_inline bool operator!= (const c4_String& a_, const char* b_)
{
    return (d4_std::string) a_ != (d4_std::string) b_;
}

d4_inline bool operator!= (const char* a_, const c4_String& b_)
{
    return (d4_std::string) a_ != (d4_std::string) b_;
}

#else                           // Universal replacement classes

/// Construct empty string
d4_inline c4_String::c4_String ()
{
    Init(0, 0);
}

/// Construct string from Pascal-style <count,chars...> data
d4_inline c4_String::c4_String (const unsigned char* ptr)
{
    Init(ptr + 1, ptr ? *ptr : 0);
}

/// Construct string from a specified area in memory
d4_inline c4_String::c4_String (const void* ptr, int len)
{
    Init(ptr, len);
}

d4_inline const c4_String& c4_String::operator+= (const c4_String& s)
{
    return *this = *this + s;
}

d4_inline const c4_String& c4_String::operator+= (const char* s)
{
    return *this += (c4_String) s;
}

d4_inline const char* c4_String::Data() const
{
    return (const char*) (_value + 2);
}

d4_inline c4_String::operator const char* () const
{
    return Data();
}

d4_inline c4_String::operator const unsigned char* () const
{
    return (unsigned char*) Data() - 1;
}

d4_inline char c4_String::operator[] (int i) const
{
    return Data()[i];
}
    
d4_inline int c4_String::GetLength() const
{
    return _value[1] != 255 ? _value[1] : FullLength();
}

d4_inline bool c4_String::IsEmpty() const
{
    return GetLength() == 0;
}

d4_inline void c4_String::Empty()
{
    *this = "";
}

d4_inline bool c4_String::operator< (const c4_String& a) const
{
    return Compare(a) < 0;
}

d4_inline c4_String operator+ (const char* a, const c4_String& b)
{
    return (c4_String) a + b;
}

d4_inline c4_String operator+ (const c4_String& a, const char* b)
{
    return a + (c4_String) b;
}

d4_inline bool operator== (const char* a, const c4_String& b)
{
    return b.Compare(a) == 0;
}

d4_inline bool operator== (const c4_String& a, const char* b)
{
    return a.Compare(b) == 0;
}

d4_inline bool operator!= (const c4_String& a, const c4_String& b)
{
    return !(a == b);
}

d4_inline bool operator!= (const char* a, const c4_String& b)
{
    return b.Compare(a) != 0;
}

d4_inline bool operator!= (const c4_String& a, const char* b)
{
    return a.Compare(b) != 0;
}

#endif // q4_UNIV

/////////////////////////////////////////////////////////////////////////////