32 #define _VSTRING_TCC 1
34 #pragma GCC system_header
36 #include <cxxabi-forced.h>
38 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
40 template<typename _CharT, typename _Traits, typename _Alloc,
41 template <typename, typename, typename> class _Base>
42 const typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
43 __versa_string<_CharT, _Traits, _Alloc, _Base>::npos;
45 template<typename _CharT, typename _Traits, typename _Alloc,
46 template <typename, typename, typename> class _Base>
48 __versa_string<_CharT, _Traits, _Alloc, _Base>::
49 resize(size_type __n, _CharT __c)
51 const size_type __size = this->size();
53 this->append(__n - __size, __c);
54 else if (__n < __size)
55 this->_M_erase(__n, __size - __n);
58 template<
typename _CharT,
typename _Traits,
typename _Alloc,
59 template <
typename,
typename,
typename>
class _Base>
62 _M_append(
const _CharT* __s, size_type __n)
64 const size_type __len = __n + this->size();
66 if (__len <= this->capacity() && !this->_M_is_shared())
69 this->_S_copy(this->_M_data() + this->size(), __s, __n);
72 this->_M_mutate(this->size(), size_type(0), __s, __n);
74 this->_M_set_length(__len);
78 template<
typename _CharT,
typename _Traits,
typename _Alloc,
79 template <
typename,
typename,
typename>
class _Base>
80 template<
typename _InputIterator>
81 __versa_string<_CharT, _Traits, _Alloc, _Base>&
82 __versa_string<_CharT, _Traits, _Alloc, _Base>::
83 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
84 _InputIterator __k2, std::__false_type)
86 const __versa_string __s(__k1, __k2);
87 const size_type __n1 = __i2 - __i1;
88 return _M_replace(__i1 - _M_ibegin(), __n1, __s._M_data(),
92 template<
typename _CharT,
typename _Traits,
typename _Alloc,
93 template <
typename,
typename,
typename>
class _Base>
94 __versa_string<_CharT, _Traits, _Alloc, _Base>&
95 __versa_string<_CharT, _Traits, _Alloc, _Base>::
96 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
99 _M_check_length(__n1, __n2,
"__versa_string::_M_replace_aux");
101 const size_type __old_size = this->size();
102 const size_type __new_size = __old_size + __n2 - __n1;
104 if (__new_size <= this->capacity() && !this->_M_is_shared())
106 _CharT* __p = this->_M_data() + __pos1;
108 const size_type __how_much = __old_size - __pos1 - __n1;
109 if (__how_much && __n1 != __n2)
110 this->_S_move(__p + __n2, __p + __n1, __how_much);
113 this->_M_mutate(__pos1, __n1, 0, __n2);
116 this->_S_assign(this->_M_data() + __pos1, __n2, __c);
118 this->_M_set_length(__new_size);
122 template<
typename _CharT,
typename _Traits,
typename _Alloc,
123 template <
typename,
typename,
typename>
class _Base>
124 __versa_string<_CharT, _Traits, _Alloc, _Base>&
125 __versa_string<_CharT, _Traits, _Alloc, _Base>::
126 _M_replace(size_type __pos, size_type __len1,
const _CharT* __s,
127 const size_type __len2)
129 _M_check_length(__len1, __len2,
"__versa_string::_M_replace");
131 const size_type __old_size = this->size();
132 const size_type __new_size = __old_size + __len2 - __len1;
134 if (__new_size <= this->capacity() && !this->_M_is_shared())
136 _CharT* __p = this->_M_data() + __pos;
138 const size_type __how_much = __old_size - __pos - __len1;
139 if (_M_disjunct(__s))
141 if (__how_much && __len1 != __len2)
142 this->_S_move(__p + __len2, __p + __len1, __how_much);
144 this->_S_copy(__p, __s, __len2);
149 if (__len2 && __len2 <= __len1)
150 this->_S_move(__p, __s, __len2);
151 if (__how_much && __len1 != __len2)
152 this->_S_move(__p + __len2, __p + __len1, __how_much);
155 if (__s + __len2 <= __p + __len1)
156 this->_S_move(__p, __s, __len2);
157 else if (__s >= __p + __len1)
158 this->_S_copy(__p, __s + __len2 - __len1, __len2);
161 const size_type __nleft = (__p + __len1) - __s;
162 this->_S_move(__p, __s, __nleft);
163 this->_S_copy(__p + __nleft, __p + __len2,
170 this->_M_mutate(__pos, __len1, __s, __len2);
172 this->_M_set_length(__new_size);
176 template<
typename _CharT,
typename _Traits,
typename _Alloc,
177 template <
typename,
typename,
typename>
class _Base>
178 __versa_string<_CharT, _Traits, _Alloc, _Base>
189 template<
typename _CharT,
typename _Traits,
typename _Alloc,
190 template <
typename,
typename,
typename>
class _Base>
191 __versa_string<_CharT, _Traits, _Alloc, _Base>
192 operator+(
const _CharT* __lhs,
195 __glibcxx_requires_string(__lhs);
197 typedef typename __string_type::size_type __size_type;
198 const __size_type __len = _Traits::length(__lhs);
200 __str.reserve(__len + __rhs.
size());
201 __str.append(__lhs, __len);
206 template<
typename _CharT,
typename _Traits,
typename _Alloc,
207 template <
typename,
typename,
typename>
class _Base>
208 __versa_string<_CharT, _Traits, _Alloc, _Base>
209 operator+(_CharT __lhs,
219 template<
typename _CharT,
typename _Traits,
typename _Alloc,
220 template <
typename,
typename,
typename>
class _Base>
221 __versa_string<_CharT, _Traits, _Alloc, _Base>
225 __glibcxx_requires_string(__rhs);
227 typedef typename __string_type::size_type __size_type;
228 const __size_type __len = _Traits::length(__rhs);
230 __str.reserve(__lhs.
size() + __len);
232 __str.append(__rhs, __len);
236 template<
typename _CharT,
typename _Traits,
typename _Alloc,
237 template <
typename,
typename,
typename>
class _Base>
238 __versa_string<_CharT, _Traits, _Alloc, _Base>
249 template<
typename _CharT,
typename _Traits,
typename _Alloc,
250 template <
typename,
typename,
typename>
class _Base>
251 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
252 __versa_string<_CharT, _Traits, _Alloc, _Base>::
253 copy(_CharT* __s, size_type __n, size_type __pos)
const
255 _M_check(__pos,
"__versa_string::copy");
256 __n = _M_limit(__pos, __n);
257 __glibcxx_requires_string_len(__s, __n);
259 this->_S_copy(__s, this->_M_data() + __pos, __n);
264 template<
typename _CharT,
typename _Traits,
typename _Alloc,
265 template <
typename,
typename,
typename>
class _Base>
266 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
268 find(
const _CharT* __s, size_type __pos, size_type __n)
const
270 __glibcxx_requires_string_len(__s, __n);
271 const size_type __size = this->size();
272 const _CharT* __data = this->_M_data();
275 return __pos <= __size ? __pos : npos;
279 for (; __pos <= __size - __n; ++__pos)
280 if (traits_type::eq(__data[__pos], __s[0])
281 && traits_type::compare(__data + __pos + 1,
282 __s + 1, __n - 1) == 0)
288 template<
typename _CharT,
typename _Traits,
typename _Alloc,
289 template <
typename,
typename,
typename>
class _Base>
290 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
292 find(_CharT __c, size_type __pos)
const
294 size_type __ret = npos;
295 const size_type __size = this->size();
298 const _CharT* __data = this->_M_data();
299 const size_type __n = __size - __pos;
300 const _CharT* __p = traits_type::find(__data + __pos, __n, __c);
302 __ret = __p - __data;
307 template<
typename _CharT,
typename _Traits,
typename _Alloc,
308 template <
typename,
typename,
typename>
class _Base>
309 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
311 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
313 __glibcxx_requires_string_len(__s, __n);
314 const size_type __size = this->size();
317 __pos =
std::min(size_type(__size - __n), __pos);
318 const _CharT* __data = this->_M_data();
321 if (traits_type::compare(__data + __pos, __s, __n) == 0)
329 template<
typename _CharT,
typename _Traits,
typename _Alloc,
330 template <
typename,
typename,
typename>
class _Base>
331 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
333 rfind(_CharT __c, size_type __pos)
const
335 size_type __size = this->size();
338 if (--__size > __pos)
340 for (++__size; __size-- > 0; )
341 if (traits_type::eq(this->_M_data()[__size], __c))
347 template<
typename _CharT,
typename _Traits,
typename _Alloc,
348 template <
typename,
typename,
typename>
class _Base>
349 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
353 __glibcxx_requires_string_len(__s, __n);
354 for (; __n && __pos < this->size(); ++__pos)
356 const _CharT* __p = traits_type::find(__s, __n,
357 this->_M_data()[__pos]);
364 template<
typename _CharT,
typename _Traits,
typename _Alloc,
365 template <
typename,
typename,
typename>
class _Base>
366 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
370 __glibcxx_requires_string_len(__s, __n);
371 size_type __size = this->size();
374 if (--__size > __pos)
378 if (traits_type::find(__s, __n, this->_M_data()[__size]))
381 while (__size-- != 0);
386 template<
typename _CharT,
typename _Traits,
typename _Alloc,
387 template <
typename,
typename,
typename>
class _Base>
388 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
392 __glibcxx_requires_string_len(__s, __n);
393 for (; __pos < this->size(); ++__pos)
394 if (!traits_type::find(__s, __n, this->_M_data()[__pos]))
399 template<
typename _CharT,
typename _Traits,
typename _Alloc,
400 template <
typename,
typename,
typename>
class _Base>
401 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
405 for (; __pos < this->size(); ++__pos)
406 if (!traits_type::eq(this->_M_data()[__pos], __c))
411 template<
typename _CharT,
typename _Traits,
typename _Alloc,
412 template <
typename,
typename,
typename>
class _Base>
413 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
417 __glibcxx_requires_string_len(__s, __n);
418 size_type __size = this->size();
421 if (--__size > __pos)
425 if (!traits_type::find(__s, __n, this->_M_data()[__size]))
433 template<
typename _CharT,
typename _Traits,
typename _Alloc,
434 template <
typename,
typename,
typename>
class _Base>
435 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
439 size_type __size = this->size();
442 if (--__size > __pos)
446 if (!traits_type::eq(this->_M_data()[__size], __c))
454 template<
typename _CharT,
typename _Traits,
typename _Alloc,
455 template <
typename,
typename,
typename>
class _Base>
460 _M_check(__pos,
"__versa_string::compare");
461 __n = _M_limit(__pos, __n);
462 const size_type __osize = __str.
size();
463 const size_type __len =
std::min(__n, __osize);
464 int __r = traits_type::compare(this->_M_data() + __pos,
465 __str.
data(), __len);
467 __r = _S_compare(__n, __osize);
471 template<
typename _CharT,
typename _Traits,
typename _Alloc,
472 template <
typename,
typename,
typename>
class _Base>
476 size_type __pos2, size_type __n2)
const
478 _M_check(__pos1,
"__versa_string::compare");
479 __str._M_check(__pos2,
"__versa_string::compare");
480 __n1 = _M_limit(__pos1, __n1);
481 __n2 = __str._M_limit(__pos2, __n2);
482 const size_type __len =
std::min(__n1, __n2);
483 int __r = traits_type::compare(this->_M_data() + __pos1,
484 __str.
data() + __pos2, __len);
486 __r = _S_compare(__n1, __n2);
490 template<
typename _CharT,
typename _Traits,
typename _Alloc,
491 template <
typename,
typename,
typename>
class _Base>
496 __glibcxx_requires_string(__s);
497 const size_type __size = this->size();
498 const size_type __osize = traits_type::length(__s);
499 const size_type __len =
std::min(__size, __osize);
500 int __r = traits_type::compare(this->_M_data(), __s, __len);
502 __r = _S_compare(__size, __osize);
506 template<
typename _CharT,
typename _Traits,
typename _Alloc,
507 template <
typename,
typename,
typename>
class _Base>
510 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const
512 __glibcxx_requires_string(__s);
513 _M_check(__pos,
"__versa_string::compare");
514 __n1 = _M_limit(__pos, __n1);
515 const size_type __osize = traits_type::length(__s);
516 const size_type __len =
std::min(__n1, __osize);
517 int __r = traits_type::compare(this->_M_data() + __pos, __s, __len);
519 __r = _S_compare(__n1, __osize);
523 template<
typename _CharT,
typename _Traits,
typename _Alloc,
524 template <
typename,
typename,
typename>
class _Base>
527 compare(size_type __pos, size_type __n1,
const _CharT* __s,
528 size_type __n2)
const
530 __glibcxx_requires_string_len(__s, __n2);
531 _M_check(__pos,
"__versa_string::compare");
532 __n1 = _M_limit(__pos, __n1);
533 const size_type __len =
std::min(__n1, __n2);
534 int __r = traits_type::compare(this->_M_data() + __pos, __s, __len);
536 __r = _S_compare(__n1, __n2);
540 _GLIBCXX_END_NAMESPACE
542 _GLIBCXX_BEGIN_NAMESPACE(std)
544 template<typename _CharT, typename _Traits, typename _Alloc,
545 template <typename, typename, typename> class _Base>
546 basic_istream<_CharT, _Traits>&
548 __gnu_cxx::__versa_string<_CharT, _Traits,
549 _Alloc, _Base>& __str)
552 typedef typename __istream_type::ios_base __ios_base;
555 typedef typename __istream_type::int_type __int_type;
556 typedef typename __string_type::size_type __size_type;
558 typedef typename __ctype_type::ctype_base __ctype_base;
560 __size_type __extracted = 0;
561 typename __ios_base::iostate __err = __ios_base::goodbit;
562 typename __istream_type::sentry __cerb(__in,
false);
570 __size_type __len = 0;
572 const __size_type __n = __w > 0 ?
static_cast<__size_type
>(__w)
574 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
575 const __int_type __eof = _Traits::eof();
576 __int_type __c = __in.rdbuf()->sgetc();
578 while (__extracted < __n
579 && !_Traits::eq_int_type(__c, __eof)
580 && !__ct.is(__ctype_base::space,
581 _Traits::to_char_type(__c)))
583 if (__len ==
sizeof(__buf) /
sizeof(_CharT))
585 __str.append(__buf,
sizeof(__buf) /
sizeof(_CharT));
588 __buf[__len++] = _Traits::to_char_type(__c);
590 __c = __in.rdbuf()->snextc();
592 __str.append(__buf, __len);
594 if (_Traits::eq_int_type(__c, __eof))
595 __err |= __ios_base::eofbit;
600 __in._M_setstate(__ios_base::badbit);
601 __throw_exception_again;
608 __in._M_setstate(__ios_base::badbit);
613 __err |= __ios_base::failbit;
615 __in.setstate(__err);
619 template<
typename _CharT,
typename _Traits,
typename _Alloc,
620 template <
typename,
typename,
typename>
class _Base>
621 basic_istream<_CharT, _Traits>&
627 typedef typename __istream_type::ios_base __ios_base;
630 typedef typename __istream_type::int_type __int_type;
631 typedef typename __string_type::size_type __size_type;
633 __size_type __extracted = 0;
634 const __size_type __n = __str.
max_size();
635 typename __ios_base::iostate __err = __ios_base::goodbit;
636 typename __istream_type::sentry __cerb(__in,
true);
644 __size_type __len = 0;
645 const __int_type __idelim = _Traits::to_int_type(__delim);
646 const __int_type __eof = _Traits::eof();
647 __int_type __c = __in.
rdbuf()->sgetc();
649 while (__extracted < __n
650 && !_Traits::eq_int_type(__c, __eof)
651 && !_Traits::eq_int_type(__c, __idelim))
653 if (__len ==
sizeof(__buf) /
sizeof(_CharT))
655 __str.
append(__buf,
sizeof(__buf) /
sizeof(_CharT));
658 __buf[__len++] = _Traits::to_char_type(__c);
660 __c = __in.
rdbuf()->snextc();
662 __str.
append(__buf, __len);
664 if (_Traits::eq_int_type(__c, __eof))
665 __err |= __ios_base::eofbit;
666 else if (_Traits::eq_int_type(__c, __idelim))
669 __in.
rdbuf()->sbumpc();
672 __err |= __ios_base::failbit;
676 __in._M_setstate(__ios_base::badbit);
677 __throw_exception_again;
684 __in._M_setstate(__ios_base::badbit);
688 __err |= __ios_base::failbit;
694 _GLIBCXX_END_NAMESPACE
696 #endif // _VSTRING_TCC
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
size_type size() const
Returns the number of characters in the string, not including any null-termination.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
void setstate(iostate __state)
Sets additional flags in the error state.
void push_back(_CharT __c)
Append a single character.
Thrown as part of forced unwinding.A magic placeholder class that can be caught by reference to recog...
__versa_string & erase(size_type __pos=0, size_type __n=npos)
Remove characters.
size_type max_size() const
Returns the size() of the largest possible string.
__versa_string & append(const __versa_string &__str)
Append a string to this string.
Managing sequences of characters and character-like objects.
basic_streambuf< _CharT, _Traits > * rdbuf() const
Accessing the underlying buffer.
const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
Controlling input.This is the base class for all input streams. It provides text formatting of all bu...
const _CharT * data() const
Return const pointer to contents.