31 #define _VSTRING_TCC 1
33 #pragma GCC system_header
37 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
41 template<
typename _CharT,
typename _Traits,
typename _Alloc,
42 template <
typename,
typename,
typename>
class _Base>
43 const typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
44 __versa_string<_CharT, _Traits, _Alloc, _Base>::npos;
46 template<
typename _CharT,
typename _Traits,
typename _Alloc,
47 template <
typename,
typename,
typename>
class _Base>
52 const size_type __size = this->
size();
54 this->append(__n - __size, __c);
55 else if (__n < __size)
56 this->_M_erase(__n, __size - __n);
59 template<
typename _CharT,
typename _Traits,
typename _Alloc,
60 template <
typename,
typename,
typename>
class _Base>
63 _M_append(
const _CharT* __s, size_type __n)
65 const size_type __len = __n + this->
size();
67 if (__len <= this->capacity() && !this->_M_is_shared())
70 this->_S_copy(this->_M_data() + this->
size(), __s, __n);
73 this->_M_mutate(this->
size(), size_type(0), __s, __n);
75 this->_M_set_length(__len);
79 template<
typename _CharT,
typename _Traits,
typename _Alloc,
80 template <
typename,
typename,
typename>
class _Base>
81 template<
typename _InputIterator>
82 __versa_string<_CharT, _Traits, _Alloc, _Base>&
83 __versa_string<_CharT, _Traits, _Alloc, _Base>::
84 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
85 _InputIterator __k2, std::__false_type)
87 const __versa_string __s(__k1, __k2);
88 const size_type __n1 = __i2 - __i1;
89 return _M_replace(__i1 - _M_ibegin(), __n1, __s._M_data(),
93 template<
typename _CharT,
typename _Traits,
typename _Alloc,
94 template <
typename,
typename,
typename>
class _Base>
95 __versa_string<_CharT, _Traits, _Alloc, _Base>&
96 __versa_string<_CharT, _Traits, _Alloc, _Base>::
97 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
100 _M_check_length(__n1, __n2,
"__versa_string::_M_replace_aux");
102 const size_type __old_size = this->
size();
103 const size_type __new_size = __old_size + __n2 - __n1;
105 if (__new_size <= this->capacity() && !this->_M_is_shared())
107 _CharT* __p = this->_M_data() + __pos1;
109 const size_type __how_much = __old_size - __pos1 - __n1;
110 if (__how_much && __n1 != __n2)
111 this->_S_move(__p + __n2, __p + __n1, __how_much);
114 this->_M_mutate(__pos1, __n1, 0, __n2);
117 this->_S_assign(this->_M_data() + __pos1, __n2, __c);
119 this->_M_set_length(__new_size);
123 template<
typename _CharT,
typename _Traits,
typename _Alloc,
124 template <
typename,
typename,
typename>
class _Base>
125 __versa_string<_CharT, _Traits, _Alloc, _Base>&
126 __versa_string<_CharT, _Traits, _Alloc, _Base>::
127 _M_replace(size_type __pos, size_type __len1,
const _CharT* __s,
128 const size_type __len2)
130 _M_check_length(__len1, __len2,
"__versa_string::_M_replace");
132 const size_type __old_size = this->
size();
133 const size_type __new_size = __old_size + __len2 - __len1;
135 if (__new_size <= this->capacity() && !this->_M_is_shared())
137 _CharT* __p = this->_M_data() + __pos;
139 const size_type __how_much = __old_size - __pos - __len1;
140 if (_M_disjunct(__s))
142 if (__how_much && __len1 != __len2)
143 this->_S_move(__p + __len2, __p + __len1, __how_much);
145 this->_S_copy(__p, __s, __len2);
150 if (__len2 && __len2 <= __len1)
151 this->_S_move(__p, __s, __len2);
152 if (__how_much && __len1 != __len2)
153 this->_S_move(__p + __len2, __p + __len1, __how_much);
156 if (__s + __len2 <= __p + __len1)
157 this->_S_move(__p, __s, __len2);
158 else if (__s >= __p + __len1)
159 this->_S_copy(__p, __s + __len2 - __len1, __len2);
162 const size_type __nleft = (__p + __len1) - __s;
163 this->_S_move(__p, __s, __nleft);
164 this->_S_copy(__p + __nleft, __p + __len2,
171 this->_M_mutate(__pos, __len1, __s, __len2);
173 this->_M_set_length(__new_size);
177 template<
typename _CharT,
typename _Traits,
typename _Alloc,
178 template <
typename,
typename,
typename>
class _Base>
179 __versa_string<_CharT, _Traits, _Alloc, _Base>
190 template<
typename _CharT,
typename _Traits,
typename _Alloc,
191 template <
typename,
typename,
typename>
class _Base>
192 __versa_string<_CharT, _Traits, _Alloc, _Base>
193 operator+(
const _CharT* __lhs,
196 __glibcxx_requires_string(__lhs);
198 typedef typename __string_type::size_type __size_type;
199 const __size_type __len = _Traits::length(__lhs);
201 __str.reserve(__len + __rhs.
size());
202 __str.append(__lhs, __len);
207 template<
typename _CharT,
typename _Traits,
typename _Alloc,
208 template <
typename,
typename,
typename>
class _Base>
209 __versa_string<_CharT, _Traits, _Alloc, _Base>
210 operator+(_CharT __lhs,
220 template<
typename _CharT,
typename _Traits,
typename _Alloc,
221 template <
typename,
typename,
typename>
class _Base>
222 __versa_string<_CharT, _Traits, _Alloc, _Base>
226 __glibcxx_requires_string(__rhs);
228 typedef typename __string_type::size_type __size_type;
229 const __size_type __len = _Traits::length(__rhs);
231 __str.reserve(__lhs.
size() + __len);
233 __str.append(__rhs, __len);
237 template<
typename _CharT,
typename _Traits,
typename _Alloc,
238 template <
typename,
typename,
typename>
class _Base>
239 __versa_string<_CharT, _Traits, _Alloc, _Base>
250 template<
typename _CharT,
typename _Traits,
typename _Alloc,
251 template <
typename,
typename,
typename>
class _Base>
252 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
254 copy(_CharT* __s, size_type __n, size_type __pos)
const
256 _M_check(__pos,
"__versa_string::copy");
257 __n = _M_limit(__pos, __n);
258 __glibcxx_requires_string_len(__s, __n);
260 this->_S_copy(__s, this->_M_data() + __pos, __n);
265 template<
typename _CharT,
typename _Traits,
typename _Alloc,
266 template <
typename,
typename,
typename>
class _Base>
267 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
269 find(
const _CharT* __s, size_type __pos, size_type __n)
const
271 __glibcxx_requires_string_len(__s, __n);
272 const size_type __size = this->
size();
273 const _CharT* __data = this->_M_data();
276 return __pos <= __size ? __pos : npos;
280 for (; __pos <= __size - __n; ++__pos)
281 if (traits_type::eq(__data[__pos], __s[0])
282 && traits_type::compare(__data + __pos + 1,
283 __s + 1, __n - 1) == 0)
289 template<
typename _CharT,
typename _Traits,
typename _Alloc,
290 template <
typename,
typename,
typename>
class _Base>
291 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
293 find(_CharT __c, size_type __pos)
const _GLIBCXX_NOEXCEPT
295 size_type __ret = npos;
296 const size_type __size = this->
size();
299 const _CharT* __data = this->_M_data();
300 const size_type __n = __size - __pos;
301 const _CharT* __p = traits_type::find(__data + __pos, __n, __c);
303 __ret = __p - __data;
308 template<
typename _CharT,
typename _Traits,
typename _Alloc,
309 template <
typename,
typename,
typename>
class _Base>
310 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
312 rfind(
const _CharT* __s, size_type __pos, size_type __n)
const
314 __glibcxx_requires_string_len(__s, __n);
315 const size_type __size = this->
size();
318 __pos =
std::min(size_type(__size - __n), __pos);
319 const _CharT* __data = this->_M_data();
322 if (traits_type::compare(__data + __pos, __s, __n) == 0)
330 template<
typename _CharT,
typename _Traits,
typename _Alloc,
331 template <
typename,
typename,
typename>
class _Base>
332 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
334 rfind(_CharT __c, size_type __pos)
const _GLIBCXX_NOEXCEPT
336 size_type __size = this->
size();
339 if (--__size > __pos)
341 for (++__size; __size-- > 0; )
342 if (traits_type::eq(this->_M_data()[__size], __c))
348 template<
typename _CharT,
typename _Traits,
typename _Alloc,
349 template <
typename,
typename,
typename>
class _Base>
350 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
354 __glibcxx_requires_string_len(__s, __n);
355 for (; __n && __pos < this->
size(); ++__pos)
357 const _CharT* __p = traits_type::find(__s, __n,
358 this->_M_data()[__pos]);
365 template<
typename _CharT,
typename _Traits,
typename _Alloc,
366 template <
typename,
typename,
typename>
class _Base>
367 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
371 __glibcxx_requires_string_len(__s, __n);
372 size_type __size = this->
size();
375 if (--__size > __pos)
379 if (traits_type::find(__s, __n, this->_M_data()[__size]))
382 while (__size-- != 0);
387 template<
typename _CharT,
typename _Traits,
typename _Alloc,
388 template <
typename,
typename,
typename>
class _Base>
389 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
393 __glibcxx_requires_string_len(__s, __n);
394 for (; __pos < this->
size(); ++__pos)
395 if (!traits_type::find(__s, __n, this->_M_data()[__pos]))
400 template<
typename _CharT,
typename _Traits,
typename _Alloc,
401 template <
typename,
typename,
typename>
class _Base>
402 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
406 for (; __pos < this->
size(); ++__pos)
407 if (!traits_type::eq(this->_M_data()[__pos], __c))
412 template<
typename _CharT,
typename _Traits,
typename _Alloc,
413 template <
typename,
typename,
typename>
class _Base>
414 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
418 __glibcxx_requires_string_len(__s, __n);
419 size_type __size = this->
size();
422 if (--__size > __pos)
426 if (!traits_type::find(__s, __n, this->_M_data()[__size]))
434 template<
typename _CharT,
typename _Traits,
typename _Alloc,
435 template <
typename,
typename,
typename>
class _Base>
436 typename __versa_string<_CharT, _Traits, _Alloc, _Base>::size_type
440 size_type __size = this->
size();
443 if (--__size > __pos)
447 if (!traits_type::eq(this->_M_data()[__size], __c))
455 template<
typename _CharT,
typename _Traits,
typename _Alloc,
456 template <
typename,
typename,
typename>
class _Base>
461 _M_check(__pos,
"__versa_string::compare");
462 __n = _M_limit(__pos, __n);
463 const size_type __osize = __str.
size();
464 const size_type __len =
std::min(__n, __osize);
465 int __r = traits_type::compare(this->_M_data() + __pos,
466 __str.
data(), __len);
468 __r = this->_S_compare(__n, __osize);
472 template<
typename _CharT,
typename _Traits,
typename _Alloc,
473 template <
typename,
typename,
typename>
class _Base>
477 size_type __pos2, size_type __n2)
const
479 _M_check(__pos1,
"__versa_string::compare");
480 __str._M_check(__pos2,
"__versa_string::compare");
481 __n1 = _M_limit(__pos1, __n1);
482 __n2 = __str._M_limit(__pos2, __n2);
483 const size_type __len =
std::min(__n1, __n2);
484 int __r = traits_type::compare(this->_M_data() + __pos1,
485 __str.
data() + __pos2, __len);
487 __r = this->_S_compare(__n1, __n2);
491 template<
typename _CharT,
typename _Traits,
typename _Alloc,
492 template <
typename,
typename,
typename>
class _Base>
497 __glibcxx_requires_string(__s);
498 const size_type __size = this->
size();
499 const size_type __osize = traits_type::length(__s);
500 const size_type __len =
std::min(__size, __osize);
501 int __r = traits_type::compare(this->_M_data(), __s, __len);
503 __r = this->_S_compare(__size, __osize);
507 template<
typename _CharT,
typename _Traits,
typename _Alloc,
508 template <
typename,
typename,
typename>
class _Base>
511 compare(size_type __pos, size_type __n1,
const _CharT* __s)
const
513 __glibcxx_requires_string(__s);
514 _M_check(__pos,
"__versa_string::compare");
515 __n1 = _M_limit(__pos, __n1);
516 const size_type __osize = traits_type::length(__s);
517 const size_type __len =
std::min(__n1, __osize);
518 int __r = traits_type::compare(this->_M_data() + __pos, __s, __len);
520 __r = this->_S_compare(__n1, __osize);
524 template<
typename _CharT,
typename _Traits,
typename _Alloc,
525 template <
typename,
typename,
typename>
class _Base>
528 compare(size_type __pos, size_type __n1,
const _CharT* __s,
529 size_type __n2)
const
531 __glibcxx_requires_string_len(__s, __n2);
532 _M_check(__pos,
"__versa_string::compare");
533 __n1 = _M_limit(__pos, __n1);
534 const size_type __len =
std::min(__n1, __n2);
535 int __r = traits_type::compare(this->_M_data() + __pos, __s, __len);
537 __r = this->_S_compare(__n1, __n2);
541 _GLIBCXX_END_NAMESPACE_VERSION
544 namespace std _GLIBCXX_VISIBILITY(default)
546 _GLIBCXX_BEGIN_NAMESPACE_VERSION
548 template<
typename _CharT,
typename _Traits,
typename _Alloc,
549 template <
typename,
typename,
typename>
class _Base>
550 basic_istream<_CharT, _Traits>&
553 _Alloc, _Base>& __str)
556 typedef typename __istream_type::ios_base __ios_base;
559 typedef typename __istream_type::int_type __int_type;
560 typedef typename __string_type::size_type __size_type;
562 typedef typename __ctype_type::ctype_base __ctype_base;
564 __size_type __extracted = 0;
565 typename __ios_base::iostate __err = __ios_base::goodbit;
566 typename __istream_type::sentry __cerb(__in,
false);
574 __size_type __len = 0;
576 const __size_type __n = __w > 0 ?
static_cast<__size_type
>(__w)
578 const __ctype_type& __ct = use_facet<__ctype_type>(__in.
getloc());
579 const __int_type __eof = _Traits::eof();
580 __int_type __c = __in.
rdbuf()->sgetc();
582 while (__extracted < __n
583 && !_Traits::eq_int_type(__c, __eof)
584 && !__ct.is(__ctype_base::space,
585 _Traits::to_char_type(__c)))
587 if (__len ==
sizeof(__buf) /
sizeof(_CharT))
589 __str.append(__buf,
sizeof(__buf) /
sizeof(_CharT));
592 __buf[__len++] = _Traits::to_char_type(__c);
594 __c = __in.
rdbuf()->snextc();
596 __str.append(__buf, __len);
598 if (_Traits::eq_int_type(__c, __eof))
599 __err |= __ios_base::eofbit;
604 __in._M_setstate(__ios_base::badbit);
605 __throw_exception_again;
612 __in._M_setstate(__ios_base::badbit);
617 __err |= __ios_base::failbit;
623 template<
typename _CharT,
typename _Traits,
typename _Alloc,
624 template <
typename,
typename,
typename>
class _Base>
625 basic_istream<_CharT, _Traits>&
631 typedef typename __istream_type::ios_base __ios_base;
634 typedef typename __istream_type::int_type __int_type;
635 typedef typename __string_type::size_type __size_type;
637 __size_type __extracted = 0;
638 const __size_type __n = __str.
max_size();
639 typename __ios_base::iostate __err = __ios_base::goodbit;
640 typename __istream_type::sentry __cerb(__in,
true);
648 __size_type __len = 0;
649 const __int_type __idelim = _Traits::to_int_type(__delim);
650 const __int_type __eof = _Traits::eof();
651 __int_type __c = __in.
rdbuf()->sgetc();
653 while (__extracted < __n
654 && !_Traits::eq_int_type(__c, __eof)
655 && !_Traits::eq_int_type(__c, __idelim))
657 if (__len ==
sizeof(__buf) /
sizeof(_CharT))
659 __str.
append(__buf,
sizeof(__buf) /
sizeof(_CharT));
662 __buf[__len++] = _Traits::to_char_type(__c);
664 __c = __in.
rdbuf()->snextc();
666 __str.
append(__buf, __len);
668 if (_Traits::eq_int_type(__c, __eof))
669 __err |= __ios_base::eofbit;
670 else if (_Traits::eq_int_type(__c, __idelim))
673 __in.
rdbuf()->sbumpc();
676 __err |= __ios_base::failbit;
680 __in._M_setstate(__ios_base::badbit);
681 __throw_exception_again;
688 __in._M_setstate(__ios_base::badbit);
692 __err |= __ios_base::failbit;
698 _GLIBCXX_END_NAMESPACE_VERSION
701 #endif // _VSTRING_TCC