| 57 } while (buf == null); |
71 } while (buf == null); |
| 58 |
72 |
| 59 return buf; |
73 return buf; |
| 60 } |
74 } |
| 61 |
75 |
| |
76 void String::append (const char* data) { |
| |
77 m_string.append (data); |
| |
78 } |
| |
79 |
| |
80 void String::append (const char data) { |
| |
81 m_string.push_back (data); |
| |
82 } |
| |
83 |
| |
84 void String::append (const String data) { |
| |
85 m_string.append (data.chars ()); |
| |
86 } |
| |
87 |
| |
88 String::it String::begin () { |
| |
89 return m_string.begin (); |
| |
90 } |
| |
91 |
| |
92 String::c_it String::begin () const { |
| |
93 return m_string.cbegin (); |
| |
94 } |
| |
95 |
| |
96 const char* String::c () const { |
| |
97 return chars (); |
| |
98 } |
| |
99 |
| |
100 size_t String::capacity () const { |
| |
101 return m_string.capacity (); |
| |
102 } |
| |
103 |
| |
104 const char* String::chars () const { |
| |
105 return m_string.c_str (); |
| |
106 } |
| |
107 |
| |
108 int String::compare (const char* other) const { |
| |
109 return m_string.compare (other); |
| |
110 } |
| |
111 |
| |
112 int String::compare (String other) const { |
| |
113 return m_string.compare (other); |
| |
114 } |
| |
115 |
| |
116 String::it String::end () { |
| |
117 return m_string.end (); |
| |
118 } |
| |
119 |
| |
120 String::c_it String::end () const { |
| |
121 return m_string.end (); |
| |
122 } |
| |
123 |
| |
124 void String::clear () { |
| |
125 m_string.clear (); |
| |
126 } |
| |
127 |
| |
128 bool String::empty() const { |
| |
129 return m_string.empty (); |
| |
130 } |
| |
131 |
| |
132 void String::erase (size_t pos) { |
| |
133 m_string.erase (m_string.begin () + pos); |
| |
134 } |
| |
135 |
| |
136 void String::insert (size_t pos, char c) { |
| |
137 m_string.insert (m_string.begin () + pos, c); |
| |
138 } |
| |
139 |
| |
140 size_t String::len () const { |
| |
141 return m_string.length (); |
| |
142 } |
| |
143 |
| |
144 size_t String::maxSize () const { |
| |
145 return m_string.max_size (); |
| |
146 } |
| |
147 |
| |
148 void String::resize (size_t n) { |
| |
149 m_string.resize (n); |
| |
150 } |
| |
151 |
| |
152 void String::shrinkToFit () { |
| |
153 m_string.shrink_to_fit (); |
| |
154 } |
| |
155 |
| |
156 |
| |
157 |
| 62 void String::trim (short n) { |
158 void String::trim (short n) { |
| 63 if (n > 0) |
159 if (n > 0) |
| 64 for (short i = 0; i < n; ++i) |
160 for (short i = 0; i < n; ++i) |
| 65 m_string.erase (m_string.end () - 1 - i); |
161 m_string.erase (m_string.end () - 1 - i); |
| 66 else |
162 else |
| 67 for (short i = abs (n) - 1; i >= 0; ++i) |
163 for (short i = abs (n) - 1; i >= 0; ++i) |
| 68 m_string.erase (m_string.begin () + i); |
164 m_string.erase (m_string.begin () + i); |
| 69 } |
165 } |
| 70 |
166 |
| |
167 String String::strip (char unwanted) { |
| |
168 return strip ({unwanted}); |
| |
169 } |
| |
170 |
| 71 String String::strip (std::initializer_list<char> unwanted) { |
171 String String::strip (std::initializer_list<char> unwanted) { |
| 72 String copy (m_string); |
172 String copy (m_string); |
| 73 |
173 |
| 74 for (char c : unwanted) { |
174 for (char c : unwanted) { |
| 75 for (long i = len (); i >= 0; --i) |
175 for (long i = len (); i >= 0; --i) |
| 223 } |
323 } |
| 224 } |
324 } |
| 225 |
325 |
| 226 return -1; |
326 return -1; |
| 227 } |
327 } |
| |
328 |
| |
329 String String::operator+ (const String data) const { |
| |
330 String newstr = *this; |
| |
331 newstr += data; |
| |
332 return newstr; |
| |
333 } |
| |
334 |
| |
335 String String::operator+ (const char* data) const { |
| |
336 String newstr = *this; |
| |
337 newstr += data; |
| |
338 return newstr; |
| |
339 } |
| |
340 |
| |
341 String& String::operator+= (const String data) { |
| |
342 append (data); |
| |
343 return *this; |
| |
344 } |
| |
345 |
| |
346 String& String::operator+= (const char* data) { |
| |
347 append (data); |
| |
348 return *this; |
| |
349 } |
| |
350 |
| |
351 String& String::operator+= (const char data) { |
| |
352 append (data); |
| |
353 return *this; |
| |
354 } |
| |
355 |
| |
356 String String::operator+ () const { |
| |
357 return upper (); |
| |
358 } |
| |
359 |
| |
360 String String::operator- () const { |
| |
361 return lower (); |
| |
362 } |
| |
363 |
| |
364 String String::operator- (size_t n) const { |
| |
365 String newstr = m_string; |
| |
366 newstr -= n; |
| |
367 return newstr; |
| |
368 } |
| |
369 |
| |
370 String& String::operator-= (size_t n) { |
| |
371 trim (n); |
| |
372 return *this; |
| |
373 } |
| |
374 |
| |
375 size_t String::operator~ () const { |
| |
376 return len (); |
| |
377 } |
| |
378 |
| |
379 vector<String> String::operator/ (String del) const { |
| |
380 return split (del); |
| |
381 } |
| |
382 |
| |
383 char& String::operator[] (size_t n) { |
| |
384 return m_string[n]; |
| |
385 } |
| |
386 |
| |
387 const char& String::operator[] (size_t n) const { |
| |
388 return m_string[n]; |
| |
389 } |
| |
390 |
| |
391 bool String::operator== (const String other) const { |
| |
392 return compare (other) == 0; |
| |
393 } |
| |
394 |
| |
395 bool String::operator== (const char* other) const { |
| |
396 return compare (other) == 0; |
| |
397 } |
| |
398 |
| |
399 bool String::operator!= (const String other) const { |
| |
400 return compare (other) != 0; |
| |
401 } |
| |
402 |
| |
403 bool String::operator!= (const char* other) const { |
| |
404 return compare (other) != 0; |
| |
405 } |
| |
406 |
| |
407 bool String::operator! () const { |
| |
408 return empty (); |
| |
409 } |
| |
410 |
| |
411 String::operator const char* () const { |
| |
412 return chars (); |
| |
413 } |
| |
414 |
| |
415 String::operator QString () { |
| |
416 return chars (); |
| |
417 } |
| |
418 |
| |
419 String::operator const QString () const { |
| |
420 return chars (); |
| |
421 } |