1 // Versatile string -*- C++ -*- 2 3 // Copyright (C) 2005-2014 Free Software Foundation, Inc. 4 // 5 // This file is part of the GNU ISO C++ Library. This library is free 6 // software; you can redistribute it and/or modify it under the 7 // terms of the GNU General Public License as published by the 8 // Free Software Foundation; either version 3, or (at your option) 9 // any later version. 10 11 // This library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 16 // Under Section 7 of GPL version 3, you are granted additional 17 // permissions described in the GCC Runtime Library Exception, version 18 // 3.1, as published by the Free Software Foundation. 19 20 // You should have received a copy of the GNU General Public License and 21 // a copy of the GCC Runtime Library Exception along with this program; 22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23 // <http://www.gnu.org/licenses/>. 24 25 /** @file ext/vstring.h 26 * This file is a GNU extension to the Standard C++ Library. 27 */ 28 29 #ifndef _VSTRING_H 30 #define _VSTRING_H 1 31 32 #pragma GCC system_header 33 34 #if __cplusplus >= 201103L 35 #include <initializer_list> 36 #endif 37 38 #include <ext/vstring_util.h> 39 #include <ext/rc_string_base.h> 40 #include <ext/sso_string_base.h> 41 42 #if __google_stl_debug_string && !defined(_GLIBCXX_DEBUG) 43 # undef _GLIBCXX_DEBUG_ASSERT 44 # undef _GLIBCXX_DEBUG_PEDASSERT 45 // Perform additional checks (but only in this file). 46 # define _GLIBCXX_DEBUG_ASSERT(_Condition) \ 47 if (! (_Condition)) { \ 48 char buf[512]; \ 49 __builtin_snprintf(buf, sizeof(buf), \ 50 "%s:%d: %s: Assertion '%s' failed.\n", \ 51 __FILE__, __LINE__, __func__, # _Condition); \ 52 std::__throw_runtime_error(buf); \ 53 } 54 # define _GLIBCXX_DEBUG_PEDASSERT(_Condition) _GLIBCXX_DEBUG_ASSERT(_Condition) 55 #endif 56 57 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) 58 { 59 _GLIBCXX_BEGIN_NAMESPACE_VERSION 60 61 /** 62 * @class __versa_string vstring.h 63 * @brief Template class __versa_string. 64 * @ingroup extensions 65 * 66 * Data structure managing sequences of characters and 67 * character-like objects. 68 */ 69 template<typename _CharT, typename _Traits, typename _Alloc, 70 template <typename, typename, typename> class _Base> 71 class __versa_string 72 : private _Base<_CharT, _Traits, _Alloc> 73 { 74 typedef _Base<_CharT, _Traits, _Alloc> __vstring_base; 75 typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type; 76 77 // Types: 78 public: 79 typedef _Traits traits_type; 80 typedef typename _Traits::char_type value_type; 81 typedef _Alloc allocator_type; 82 typedef typename _CharT_alloc_type::size_type size_type; 83 typedef typename _CharT_alloc_type::difference_type difference_type; 84 typedef value_type& reference; 85 typedef const value_type& const_reference; 86 typedef typename _CharT_alloc_type::pointer pointer; 87 typedef typename _CharT_alloc_type::const_pointer const_pointer; 88 typedef __gnu_cxx::__normal_iterator<pointer, __versa_string> iterator; 89 typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string> 90 const_iterator; 91 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 92 typedef std::reverse_iterator<iterator> reverse_iterator; 93 94 // Data Member (public): 95 /// Value returned by various member functions when they fail. 96 static const size_type npos = static_cast<size_type>(-1); 97 98 private: 99 size_type 100 _M_check(size_type __pos, const char* __s) const 101 { 102 if (__pos > this->size()) 103 std::__throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > " 104 "this->size() (which is %zu)"), 105 __s, __pos, this->size()); 106 return __pos; 107 } 108 109 void 110 _M_check_length(size_type __n1, size_type __n2, const char* __s) const 111 { 112 if (this->max_size() - (this->size() - __n1) < __n2) 113 std::__throw_length_error(__N(__s)); 114 } 115 116 // NB: _M_limit doesn't check for a bad __pos value. 117 size_type 118 _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT 119 { 120 const bool __testoff = __off < this->size() - __pos; 121 return __testoff ? __off : this->size() - __pos; 122 } 123 124 // True if _Rep and source do not overlap. 125 bool 126 _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT 127 { 128 return (std::less<const _CharT*>()(__s, this->_M_data()) 129 || std::less<const _CharT*>()(this->_M_data() 130 + this->size(), __s)); 131 } 132 133 // For the internal use we have functions similar to `begin'/`end' 134 // but they do not call _M_leak. 135 iterator 136 _M_ibegin() const _GLIBCXX_NOEXCEPT 137 { return iterator(this->_M_data()); } 138 139 iterator 140 _M_iend() const _GLIBCXX_NOEXCEPT 141 { return iterator(this->_M_data() + this->_M_length()); } 142 143 public: 144 // Construct/copy/destroy: 145 // NB: We overload ctors in some cases instead of using default 146 // arguments, per 17.4.4.4 para. 2 item 2. 147 148 /** 149 * @brief Construct an empty string using allocator @a a. 150 */ 151 explicit 152 __versa_string(const _Alloc& __a = _Alloc()) _GLIBCXX_NOEXCEPT 153 : __vstring_base(__a) { } 154 155 // NB: per LWG issue 42, semantics different from IS: 156 /** 157 * @brief Construct string with copy of value of @a __str. 158 * @param __str Source string. 159 */ 160 __versa_string(const __versa_string& __str) 161 : __vstring_base(__str) { } 162 163 #if __cplusplus >= 201103L 164 /** 165 * @brief String move constructor. 166 * @param __str Source string. 167 * 168 * The newly-constructed %string contains the exact contents of 169 * @a __str. The contents of @a __str are a valid, but unspecified 170 * string. 171 */ 172 __versa_string(__versa_string&& __str) noexcept 173 : __vstring_base(std::move(__str)) { } 174 175 /** 176 * @brief Construct string from an initializer list. 177 * @param __l std::initializer_list of characters. 178 * @param __a Allocator to use (default is default allocator). 179 */ 180 __versa_string(std::initializer_list<_CharT> __l, 181 const _Alloc& __a = _Alloc()) 182 : __vstring_base(__l.begin(), __l.end(), __a) { } 183 #endif 184 185 /** 186 * @brief Construct string as copy of a substring. 187 * @param __str Source string. 188 * @param __pos Index of first character to copy from. 189 * @param __n Number of characters to copy (default remainder). 190 */ 191 __versa_string(const __versa_string& __str, size_type __pos, 192 size_type __n = npos) 193 : __vstring_base(__str._M_data() 194 + __str._M_check(__pos, 195 "__versa_string::__versa_string"), 196 __str._M_data() + __str._M_limit(__pos, __n) 197 + __pos, _Alloc()) { } 198 199 /** 200 * @brief Construct string as copy of a substring. 201 * @param __str Source string. 202 * @param __pos Index of first character to copy from. 203 * @param __n Number of characters to copy. 204 * @param __a Allocator to use. 205 */ 206 __versa_string(const __versa_string& __str, size_type __pos, 207 size_type __n, const _Alloc& __a) 208 : __vstring_base(__str._M_data() 209 + __str._M_check(__pos, 210 "__versa_string::__versa_string"), 211 __str._M_data() + __str._M_limit(__pos, __n) 212 + __pos, __a) { } 213 214 /** 215 * @brief Construct string initialized by a character array. 216 * @param __s Source character array. 217 * @param __n Number of characters to copy. 218 * @param __a Allocator to use (default is default allocator). 219 * 220 * NB: @a __s must have at least @a __n characters, '\\0' has no special 221 * meaning. 222 */ 223 __versa_string(const _CharT* __s, size_type __n, 224 const _Alloc& __a = _Alloc()) 225 : __vstring_base(__s, __s + __n, __a) { } 226 227 /** 228 * @brief Construct string as copy of a C string. 229 * @param __s Source C string. 230 * @param __a Allocator to use (default is default allocator). 231 */ 232 __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc()) 233 : __vstring_base(__s, __s ? __s + traits_type::length(__s) : 234 __s + npos, __a) { } 235 236 /** 237 * @brief Construct string as multiple characters. 238 * @param __n Number of characters. 239 * @param __c Character to use. 240 * @param __a Allocator to use (default is default allocator). 241 */ 242 __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()) 243 : __vstring_base(__n, __c, __a) { } 244 245 /** 246 * @brief Construct string as copy of a range. 247 * @param __beg Start of range. 248 * @param __end End of range. 249 * @param __a Allocator to use (default is default allocator). 250 */ 251 #if __cplusplus >= 201103L 252 template<class _InputIterator, 253 typename = std::_RequireInputIter<_InputIterator>> 254 #else 255 template<class _InputIterator> 256 #endif 257 __versa_string(_InputIterator __beg, _InputIterator __end, 258 const _Alloc& __a = _Alloc()) 259 : __vstring_base(__beg, __end, __a) { } 260 261 /** 262 * @brief Destroy the string instance. 263 */ 264 ~__versa_string() _GLIBCXX_NOEXCEPT { } 265 266 /** 267 * @brief Assign the value of @a str to this string. 268 * @param __str Source string. 269 */ 270 __versa_string& 271 operator=(const __versa_string& __str) 272 { return this->assign(__str); } 273 274 #if __cplusplus >= 201103L 275 /** 276 * @brief String move assignment operator. 277 * @param __str Source string. 278 * 279 * The contents of @a __str are moved into this string (without 280 * copying). @a __str is a valid, but unspecified string. 281 */ 282 __versa_string& 283 operator=(__versa_string&& __str) noexcept 284 { 285 // NB: DR 1204. 286 this->swap(__str); 287 return *this; 288 } 289 290 /** 291 * @brief Set value to string constructed from initializer list. 292 * @param __l std::initializer_list. 293 */ 294 __versa_string& 295 operator=(std::initializer_list<_CharT> __l) 296 { 297 this->assign(__l.begin(), __l.end()); 298 return *this; 299 } 300 #endif 301 302 /** 303 * @brief Copy contents of @a __s into this string. 304 * @param __s Source null-terminated string. 305 */ 306 __versa_string& 307 operator=(const _CharT* __s) 308 { return this->assign(__s); } 309 310 /** 311 * @brief Set value to string of length 1. 312 * @param __c Source character. 313 * 314 * Assigning to a character makes this string length 1 and 315 * (*this)[0] == @a __c. 316 */ 317 __versa_string& 318 operator=(_CharT __c) 319 { 320 this->assign(1, __c); 321 return *this; 322 } 323 324 // Iterators: 325 /** 326 * Returns a read/write iterator that points to the first character in 327 * the %string. Unshares the string. 328 */ 329 iterator 330 begin() _GLIBCXX_NOEXCEPT 331 { 332 this->_M_leak(); 333 return iterator(this->_M_data()); 334 } 335 336 /** 337 * Returns a read-only (constant) iterator that points to the first 338 * character in the %string. 339 */ 340 const_iterator 341 begin() const _GLIBCXX_NOEXCEPT 342 { return const_iterator(this->_M_data()); } 343 344 /** 345 * Returns a read/write iterator that points one past the last 346 * character in the %string. Unshares the string. 347 */ 348 iterator 349 end() _GLIBCXX_NOEXCEPT 350 { 351 this->_M_leak(); 352 return iterator(this->_M_data() + this->size()); 353 } 354 355 /** 356 * Returns a read-only (constant) iterator that points one past the 357 * last character in the %string. 358 */ 359 const_iterator 360 end() const _GLIBCXX_NOEXCEPT 361 { return const_iterator(this->_M_data() + this->size()); } 362 363 /** 364 * Returns a read/write reverse iterator that points to the last 365 * character in the %string. Iteration is done in reverse element 366 * order. Unshares the string. 367 */ 368 reverse_iterator 369 rbegin() _GLIBCXX_NOEXCEPT 370 { return reverse_iterator(this->end()); } 371 372 /** 373 * Returns a read-only (constant) reverse iterator that points 374 * to the last character in the %string. Iteration is done in 375 * reverse element order. 376 */ 377 const_reverse_iterator 378 rbegin() const _GLIBCXX_NOEXCEPT 379 { return const_reverse_iterator(this->end()); } 380 381 /** 382 * Returns a read/write reverse iterator that points to one before the 383 * first character in the %string. Iteration is done in reverse 384 * element order. Unshares the string. 385 */ 386 reverse_iterator 387 rend() _GLIBCXX_NOEXCEPT 388 { return reverse_iterator(this->begin()); } 389 390 /** 391 * Returns a read-only (constant) reverse iterator that points 392 * to one before the first character in the %string. Iteration 393 * is done in reverse element order. 394 */ 395 const_reverse_iterator 396 rend() const _GLIBCXX_NOEXCEPT 397 { return const_reverse_iterator(this->begin()); } 398 399 #if __cplusplus >= 201103L 400 /** 401 * Returns a read-only (constant) iterator that points to the first 402 * character in the %string. 403 */ 404 const_iterator 405 cbegin() const noexcept 406 { return const_iterator(this->_M_data()); } 407 408 /** 409 * Returns a read-only (constant) iterator that points one past the 410 * last character in the %string. 411 */ 412 const_iterator 413 cend() const noexcept 414 { return const_iterator(this->_M_data() + this->size()); } 415 416 /** 417 * Returns a read-only (constant) reverse iterator that points 418 * to the last character in the %string. Iteration is done in 419 * reverse element order. 420 */ 421 const_reverse_iterator 422 crbegin() const noexcept 423 { return const_reverse_iterator(this->end()); } 424 425 /** 426 * Returns a read-only (constant) reverse iterator that points 427 * to one before the first character in the %string. Iteration 428 * is done in reverse element order. 429 */ 430 const_reverse_iterator 431 crend() const noexcept 432 { return const_reverse_iterator(this->begin()); } 433 #endif 434 435 public: 436 // Capacity: 437 /// Returns the number of characters in the string, not including any 438 /// null-termination. 439 size_type 440 size() const _GLIBCXX_NOEXCEPT 441 { return this->_M_length(); } 442 443 /// Returns the number of characters in the string, not including any 444 /// null-termination. 445 size_type 446 length() const _GLIBCXX_NOEXCEPT 447 { return this->_M_length(); } 448 449 /// Returns the size() of the largest possible %string. 450 size_type 451 max_size() const _GLIBCXX_NOEXCEPT 452 { return this->_M_max_size(); } 453 454 /** 455 * @brief Resizes the %string to the specified number of characters. 456 * @param __n Number of characters the %string should contain. 457 * @param __c Character to fill any new elements. 458 * 459 * This function will %resize the %string to the specified 460 * number of characters. If the number is smaller than the 461 * %string's current size the %string is truncated, otherwise 462 * the %string is extended and new elements are set to @a __c. 463 */ 464 void 465 resize(size_type __n, _CharT __c); 466 467 /** 468 * @brief Resizes the %string to the specified number of characters. 469 * @param __n Number of characters the %string should contain. 470 * 471 * This function will resize the %string to the specified 472 * length. If the new size is smaller than the %string's 473 * current size the %string is truncated, otherwise the %string 474 * is extended and new characters are default-constructed. For 475 * basic types such as char, this means setting them to 0. 476 */ 477 void 478 resize(size_type __n) 479 { this->resize(__n, _CharT()); } 480 481 #if __cplusplus >= 201103L 482 /// A non-binding request to reduce capacity() to size(). 483 void 484 shrink_to_fit() noexcept 485 { 486 if (capacity() > size()) 487 { 488 __try 489 { this->reserve(0); } 490 __catch(...) 491 { } 492 } 493 } 494 #endif 495 496 /** 497 * Returns the total number of characters that the %string can 498 * hold before needing to allocate more memory. 499 */ 500 size_type 501 capacity() const _GLIBCXX_NOEXCEPT 502 { return this->_M_capacity(); } 503 504 /** 505 * @brief Attempt to preallocate enough memory for specified number of 506 * characters. 507 * @param __res_arg Number of characters required. 508 * @throw std::length_error If @a __res_arg exceeds @c max_size(). 509 * 510 * This function attempts to reserve enough memory for the 511 * %string to hold the specified number of characters. If the 512 * number requested is more than max_size(), length_error is 513 * thrown. 514 * 515 * The advantage of this function is that if optimal code is a 516 * necessity and the user can determine the string length that 517 * will be required, the user can reserve the memory in 518 * %advance, and thus prevent a possible reallocation of memory 519 * and copying of %string data. 520 */ 521 void 522 reserve(size_type __res_arg = 0) 523 { this->_M_reserve(__res_arg); } 524 525 /** 526 * Erases the string, making it empty. 527 */ 528 void 529 clear() _GLIBCXX_NOEXCEPT 530 { this->_M_clear(); } 531 532 /** 533 * Returns true if the %string is empty. Equivalent to 534 * <code>*this == ""</code>. 535 */ 536 bool 537 empty() const _GLIBCXX_NOEXCEPT 538 { return this->size() == 0; } 539 540 // Element access: 541 /** 542 * @brief Subscript access to the data contained in the %string. 543 * @param __pos The index of the character to access. 544 * @return Read-only (constant) reference to the character. 545 * 546 * This operator allows for easy, array-style, data access. 547 * Note that data access with this operator is unchecked and 548 * out_of_range lookups are not defined. (For checked lookups 549 * see at().) 550 */ 551 const_reference 552 operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT 553 { 554 #if __google_stl_debug_string && !defined(_GLIBCXX_DEBUG) 555 if (__pos > this->size()) 556 std::__throw_out_of_range_fmt(__N("__versa_string::operator[]: __pos " 557 "(which is %zu) > this->size() " 558 "(which is %zu)"), 559 __pos, this->size()); 560 #else 561 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size()); 562 #endif 563 return this->_M_data()[__pos]; 564 } 565 566 /** 567 * @brief Subscript access to the data contained in the %string. 568 * @param __pos The index of the character to access. 569 * @return Read/write reference to the character. 570 * 571 * This operator allows for easy, array-style, data access. 572 * Note that data access with this operator is unchecked and 573 * out_of_range lookups are not defined. (For checked lookups 574 * see at().) Unshares the string. 575 */ 576 reference 577 operator[](size_type __pos) _GLIBCXX_NOEXCEPT 578 { 579 // Allow pos == size() both in C++98 mode, as v3 extension, 580 // and in C++11 mode. 581 #if __google_stl_debug_string && !defined(_GLIBCXX_DEBUG) 582 if (__pos > this->size()) 583 std::__throw_out_of_range_fmt(__N("__versa_string::operator[]: __pos " 584 "(which is %zu) > this->size() " 585 "(which is %zu)"), 586 __pos, this->size()); 587 #else 588 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size()); 589 #endif 590 // In pedantic mode be strict in C++98 mode. 591 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L 592 || __pos < this->size()); 593 this->_M_leak(); 594 return this->_M_data()[__pos]; 595 } 596 597 /** 598 * @brief Provides access to the data contained in the %string. 599 * @param __n The index of the character to access. 600 * @return Read-only (const) reference to the character. 601 * @throw std::out_of_range If @a __n is an invalid index. 602 * 603 * This function provides for safer data access. The parameter 604 * is first checked that it is in the range of the string. The 605 * function throws out_of_range if the check fails. 606 */ 607 const_reference 608 at(size_type __n) const 609 { 610 if (__n >= this->size()) 611 std::__throw_out_of_range_fmt(__N("__versa_string::at: __n " 612 "(which is %zu) >= this->size() " 613 "(which is %zu)"), 614 __n, this->size()); 615 return this->_M_data()[__n]; 616 } 617 618 /** 619 * @brief Provides access to the data contained in the %string. 620 * @param __n The index of the character to access. 621 * @return Read/write reference to the character. 622 * @throw std::out_of_range If @a __n is an invalid index. 623 * 624 * This function provides for safer data access. The parameter 625 * is first checked that it is in the range of the string. The 626 * function throws out_of_range if the check fails. Success 627 * results in unsharing the string. 628 */ 629 reference 630 at(size_type __n) 631 { 632 if (__n >= this->size()) 633 std::__throw_out_of_range_fmt(__N("__versa_string::at: __n " 634 "(which is %zu) >= this->size() " 635 "(which is %zu)"), 636 __n, this->size()); 637 this->_M_leak(); 638 return this->_M_data()[__n]; 639 } 640 641 #if __cplusplus >= 201103L 642 /** 643 * Returns a read/write reference to the data at the first 644 * element of the %string. 645 */ 646 reference 647 front() _GLIBCXX_NOEXCEPT 648 { return operator[](0); } 649 650 /** 651 * Returns a read-only (constant) reference to the data at the first 652 * element of the %string. 653 */ 654 const_reference 655 front() const _GLIBCXX_NOEXCEPT 656 { return operator[](0); } 657 658 /** 659 * Returns a read/write reference to the data at the last 660 * element of the %string. 661 */ 662 reference 663 back() _GLIBCXX_NOEXCEPT 664 { return operator[](this->size() - 1); } 665 666 /** 667 * Returns a read-only (constant) reference to the data at the 668 * last element of the %string. 669 */ 670 const_reference 671 back() const _GLIBCXX_NOEXCEPT 672 { return operator[](this->size() - 1); } 673 #endif 674 675 // Modifiers: 676 /** 677 * @brief Append a string to this string. 678 * @param __str The string to append. 679 * @return Reference to this string. 680 */ 681 __versa_string& 682 operator+=(const __versa_string& __str) 683 { return this->append(__str); } 684 685 /** 686 * @brief Append a C string. 687 * @param __s The C string to append. 688 * @return Reference to this string. 689 */ 690 __versa_string& 691 operator+=(const _CharT* __s) 692 { return this->append(__s); } 693 694 /** 695 * @brief Append a character. 696 * @param __c The character to append. 697 * @return Reference to this string. 698 */ 699 __versa_string& 700 operator+=(_CharT __c) 701 { 702 this->push_back(__c); 703 return *this; 704 } 705 706 #if __cplusplus >= 201103L 707 /** 708 * @brief Append an initializer_list of characters. 709 * @param __l The initializer_list of characters to be appended. 710 * @return Reference to this string. 711 */ 712 __versa_string& 713 operator+=(std::initializer_list<_CharT> __l) 714 { return this->append(__l.begin(), __l.end()); } 715 #endif // C++11 716 717 /** 718 * @brief Append a string to this string. 719 * @param __str The string to append. 720 * @return Reference to this string. 721 */ 722 __versa_string& 723 append(const __versa_string& __str) 724 { return _M_append(__str._M_data(), __str.size()); } 725 726 /** 727 * @brief Append a substring. 728 * @param __str The string to append. 729 * @param __pos Index of the first character of str to append. 730 * @param __n The number of characters to append. 731 * @return Reference to this string. 732 * @throw std::out_of_range if @a pos is not a valid index. 733 * 734 * This function appends @a __n characters from @a __str 735 * starting at @a __pos to this string. If @a __n is is larger 736 * than the number of available characters in @a __str, the 737 * remainder of @a __str is appended. 738 */ 739 __versa_string& 740 append(const __versa_string& __str, size_type __pos, size_type __n) 741 { return _M_append(__str._M_data() 742 + __str._M_check(__pos, "__versa_string::append"), 743 __str._M_limit(__pos, __n)); } 744 745 /** 746 * @brief Append a C substring. 747 * @param __s The C string to append. 748 * @param __n The number of characters to append. 749 * @return Reference to this string. 750 */ 751 __versa_string& 752 append(const _CharT* __s, size_type __n) 753 { 754 __glibcxx_requires_string_len(__s, __n); 755 _M_check_length(size_type(0), __n, "__versa_string::append"); 756 return _M_append(__s, __n); 757 } 758 759 /** 760 * @brief Append a C string. 761 * @param __s The C string to append. 762 * @return Reference to this string. 763 */ 764 __versa_string& 765 append(const _CharT* __s) 766 { 767 __glibcxx_requires_string(__s); 768 const size_type __n = traits_type::length(__s); 769 _M_check_length(size_type(0), __n, "__versa_string::append"); 770 return _M_append(__s, __n); 771 } 772 773 /** 774 * @brief Append multiple characters. 775 * @param __n The number of characters to append. 776 * @param __c The character to use. 777 * @return Reference to this string. 778 * 779 * Appends n copies of c to this string. 780 */ 781 __versa_string& 782 append(size_type __n, _CharT __c) 783 { return _M_replace_aux(this->size(), size_type(0), __n, __c); } 784 785 #if __cplusplus >= 201103L 786 /** 787 * @brief Append an initializer_list of characters. 788 * @param __l The initializer_list of characters to append. 789 * @return Reference to this string. 790 */ 791 __versa_string& 792 append(std::initializer_list<_CharT> __l) 793 { return this->append(__l.begin(), __l.end()); } 794 #endif // C++11 795 796 /** 797 * @brief Append a range of characters. 798 * @param __first Iterator referencing the first character to append. 799 * @param __last Iterator marking the end of the range. 800 * @return Reference to this string. 801 * 802 * Appends characters in the range [first,last) to this string. 803 */ 804 #if __cplusplus >= 201103L 805 template<class _InputIterator, 806 typename = std::_RequireInputIter<_InputIterator>> 807 #else 808 template<class _InputIterator> 809 #endif 810 __versa_string& 811 append(_InputIterator __first, _InputIterator __last) 812 { return this->replace(_M_iend(), _M_iend(), __first, __last); } 813 814 /** 815 * @brief Append a single character. 816 * @param __c Character to append. 817 */ 818 void 819 push_back(_CharT __c) 820 { 821 const size_type __size = this->size(); 822 if (__size + 1 > this->capacity() || this->_M_is_shared()) 823 this->_M_mutate(__size, size_type(0), 0, size_type(1)); 824 traits_type::assign(this->_M_data()[__size], __c); 825 this->_M_set_length(__size + 1); 826 } 827 828 /** 829 * @brief Set value to contents of another string. 830 * @param __str Source string to use. 831 * @return Reference to this string. 832 */ 833 __versa_string& 834 assign(const __versa_string& __str) 835 { 836 this->_M_assign(__str); 837 return *this; 838 } 839 840 #if __cplusplus >= 201103L 841 /** 842 * @brief Set value to contents of another string. 843 * @param __str Source string to use. 844 * @return Reference to this string. 845 * 846 * This function sets this string to the exact contents of @a __str. 847 * @a __str is a valid, but unspecified string. 848 */ 849 __versa_string& 850 assign(__versa_string&& __str) noexcept 851 { 852 this->swap(__str); 853 return *this; 854 } 855 #endif // C++11 856 857 /** 858 * @brief Set value to a substring of a string. 859 * @param __str The string to use. 860 * @param __pos Index of the first character of str. 861 * @param __n Number of characters to use. 862 * @return Reference to this string. 863 * @throw std::out_of_range if @a __pos is not a valid index. 864 * 865 * This function sets this string to the substring of @a __str 866 * consisting of @a __n characters at @a __pos. If @a __n is 867 * is larger than the number of available characters in @a 868 * __str, the remainder of @a __str is used. 869 */ 870 __versa_string& 871 assign(const __versa_string& __str, size_type __pos, size_type __n) 872 { return _M_replace(size_type(0), this->size(), __str._M_data() 873 + __str._M_check(__pos, "__versa_string::assign"), 874 __str._M_limit(__pos, __n)); } 875 876 /** 877 * @brief Set value to a C substring. 878 * @param __s The C string to use. 879 * @param __n Number of characters to use. 880 * @return Reference to this string. 881 * 882 * This function sets the value of this string to the first @a 883 * __n characters of @a __s. If @a __n is is larger than the 884 * number of available characters in @a __s, the remainder of 885 * @a __s is used. 886 */ 887 __versa_string& 888 assign(const _CharT* __s, size_type __n) 889 { 890 __glibcxx_requires_string_len(__s, __n); 891 return _M_replace(size_type(0), this->size(), __s, __n); 892 } 893 894 /** 895 * @brief Set value to contents of a C string. 896 * @param __s The C string to use. 897 * @return Reference to this string. 898 * 899 * This function sets the value of this string to the value of 900 * @a __s. The data is copied, so there is no dependence on @a 901 * __s once the function returns. 902 */ 903 __versa_string& 904 assign(const _CharT* __s) 905 { 906 __glibcxx_requires_string(__s); 907 return _M_replace(size_type(0), this->size(), __s, 908 traits_type::length(__s)); 909 } 910 911 /** 912 * @brief Set value to multiple characters. 913 * @param __n Length of the resulting string. 914 * @param __c The character to use. 915 * @return Reference to this string. 916 * 917 * This function sets the value of this string to @a __n copies of 918 * character @a __c. 919 */ 920 __versa_string& 921 assign(size_type __n, _CharT __c) 922 { return _M_replace_aux(size_type(0), this->size(), __n, __c); } 923 924 /** 925 * @brief Set value to a range of characters. 926 * @param __first Iterator referencing the first character to append. 927 * @param __last Iterator marking the end of the range. 928 * @return Reference to this string. 929 * 930 * Sets value of string to characters in the range 931 * [first,last). 932 */ 933 #if __cplusplus >= 201103L 934 template<class _InputIterator, 935 typename = std::_RequireInputIter<_InputIterator>> 936 #else 937 template<class _InputIterator> 938 #endif 939 __versa_string& 940 assign(_InputIterator __first, _InputIterator __last) 941 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); } 942 943 #if __cplusplus >= 201103L 944 /** 945 * @brief Set value to an initializer_list of characters. 946 * @param __l The initializer_list of characters to assign. 947 * @return Reference to this string. 948 */ 949 __versa_string& 950 assign(std::initializer_list<_CharT> __l) 951 { return this->assign(__l.begin(), __l.end()); } 952 #endif // C++11 953 954 #if __cplusplus >= 201103L 955 /** 956 * @brief Insert multiple characters. 957 * @param __p Const_iterator referencing location in string to 958 * insert at. 959 * @param __n Number of characters to insert 960 * @param __c The character to insert. 961 * @return Iterator referencing the first inserted char. 962 * @throw std::length_error If new length exceeds @c max_size(). 963 * 964 * Inserts @a __n copies of character @a __c starting at the 965 * position referenced by iterator @a __p. If adding 966 * characters causes the length to exceed max_size(), 967 * length_error is thrown. The value of the string doesn't 968 * change if an error is thrown. 969 */ 970 iterator 971 insert(const_iterator __p, size_type __n, _CharT __c) 972 { 973 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); 974 const size_type __pos = __p - _M_ibegin(); 975 this->replace(__p, __p, __n, __c); 976 return iterator(this->_M_data() + __pos); 977 } 978 #else 979 /** 980 * @brief Insert multiple characters. 981 * @param __p Iterator referencing location in string to insert at. 982 * @param __n Number of characters to insert 983 * @param __c The character to insert. 984 * @throw std::length_error If new length exceeds @c max_size(). 985 * 986 * Inserts @a __n copies of character @a __c starting at the 987 * position referenced by iterator @a __p. If adding 988 * characters causes the length to exceed max_size(), 989 * length_error is thrown. The value of the string doesn't 990 * change if an error is thrown. 991 */ 992 void 993 insert(iterator __p, size_type __n, _CharT __c) 994 { this->replace(__p, __p, __n, __c); } 995 #endif 996 997 #if __cplusplus >= 201103L 998 /** 999 * @brief Insert a range of characters. 1000 * @param __p Const_iterator referencing location in string to 1001 * insert at. 1002 * @param __beg Start of range. 1003 * @param __end End of range. 1004 * @return Iterator referencing the first inserted char. 1005 * @throw std::length_error If new length exceeds @c max_size(). 1006 * 1007 * Inserts characters in range [beg,end). If adding characters 1008 * causes the length to exceed max_size(), length_error is 1009 * thrown. The value of the string doesn't change if an error 1010 * is thrown. 1011 */ 1012 template<class _InputIterator, 1013 typename = std::_RequireInputIter<_InputIterator>> 1014 iterator 1015 insert(const_iterator __p, _InputIterator __beg, _InputIterator __end) 1016 { 1017 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); 1018 const size_type __pos = __p - _M_ibegin(); 1019 this->replace(__p, __p, __beg, __end); 1020 return iterator(this->_M_data() + __pos); 1021 } 1022 #else 1023 /** 1024 * @brief Insert a range of characters. 1025 * @param __p Iterator referencing location in string to insert at. 1026 * @param __beg Start of range. 1027 * @param __end End of range. 1028 * @throw std::length_error If new length exceeds @c max_size(). 1029 * 1030 * Inserts characters in range [beg,end). If adding characters 1031 * causes the length to exceed max_size(), length_error is 1032 * thrown. The value of the string doesn't change if an error 1033 * is thrown. 1034 */ 1035 template<class _InputIterator> 1036 void 1037 insert(iterator __p, _InputIterator __beg, _InputIterator __end) 1038 { this->replace(__p, __p, __beg, __end); } 1039 #endif 1040 1041 #if __cplusplus >= 201103L 1042 /** 1043 * @brief Insert an initializer_list of characters. 1044 * @param __p Const_iterator referencing location in string to 1045 * insert at. 1046 * @param __l The initializer_list of characters to insert. 1047 * @return Iterator referencing the first inserted char. 1048 * @throw std::length_error If new length exceeds @c max_size(). 1049 */ 1050 iterator 1051 insert(const_iterator __p, std::initializer_list<_CharT> __l) 1052 { return this->insert(__p, __l.begin(), __l.end()); } 1053 #endif // C++11 1054 1055 /** 1056 * @brief Insert value of a string. 1057 * @param __pos1 Iterator referencing location in string to insert at. 1058 * @param __str The string to insert. 1059 * @return Reference to this string. 1060 * @throw std::length_error If new length exceeds @c max_size(). 1061 * 1062 * Inserts value of @a __str starting at @a __pos1. If adding 1063 * characters causes the length to exceed max_size(), 1064 * length_error is thrown. The value of the string doesn't 1065 * change if an error is thrown. 1066 */ 1067 __versa_string& 1068 insert(size_type __pos1, const __versa_string& __str) 1069 { return this->replace(__pos1, size_type(0), 1070 __str._M_data(), __str.size()); } 1071 1072 /** 1073 * @brief Insert a substring. 1074 * @param __pos1 Iterator referencing location in string to insert at. 1075 * @param __str The string to insert. 1076 * @param __pos2 Start of characters in str to insert. 1077 * @param __n Number of characters to insert. 1078 * @return Reference to this string. 1079 * @throw std::length_error If new length exceeds @c max_size(). 1080 * @throw std::out_of_range If @a __pos1 > size() or 1081 * @a __pos2 > @a __str.size(). 1082 * 1083 * Starting at @a __pos1, insert @a __n character of @a __str 1084 * beginning with @a __pos2. If adding characters causes the 1085 * length to exceed max_size(), length_error is thrown. If @a 1086 * __pos1 is beyond the end of this string or @a __pos2 is 1087 * beyond the end of @a __str, out_of_range is thrown. The 1088 * value of the string doesn't change if an error is thrown. 1089 */ 1090 __versa_string& 1091 insert(size_type __pos1, const __versa_string& __str, 1092 size_type __pos2, size_type __n) 1093 { return this->replace(__pos1, size_type(0), __str._M_data() 1094 + __str._M_check(__pos2, "__versa_string::insert"), 1095 __str._M_limit(__pos2, __n)); } 1096 1097 /** 1098 * @brief Insert a C substring. 1099 * @param __pos Iterator referencing location in string to insert at. 1100 * @param __s The C string to insert. 1101 * @param __n The number of characters to insert. 1102 * @return Reference to this string. 1103 * @throw std::length_error If new length exceeds @c max_size(). 1104 * @throw std::out_of_range If @a __pos is beyond the end of this 1105 * string. 1106 * 1107 * Inserts the first @a __n characters of @a __s starting at @a 1108 * __pos. If adding characters causes the length to exceed 1109 * max_size(), length_error is thrown. If @a __pos is beyond 1110 * end(), out_of_range is thrown. The value of the string 1111 * doesn't change if an error is thrown. 1112 */ 1113 __versa_string& 1114 insert(size_type __pos, const _CharT* __s, size_type __n) 1115 { return this->replace(__pos, size_type(0), __s, __n); } 1116 1117 /** 1118 * @brief Insert a C string. 1119 * @param __pos Iterator referencing location in string to insert at. 1120 * @param __s The C string to insert. 1121 * @return Reference to this string. 1122 * @throw std::length_error If new length exceeds @c max_size(). 1123 * @throw std::out_of_range If @a __pos is beyond the end of this 1124 * string. 1125 * 1126 * Inserts the first @a __n characters of @a __s starting at @a 1127 * __pos. If adding characters causes the length to exceed 1128 * max_size(), length_error is thrown. If @a __pos is beyond 1129 * end(), out_of_range is thrown. The value of the string 1130 * doesn't change if an error is thrown. 1131 */ 1132 __versa_string& 1133 insert(size_type __pos, const _CharT* __s) 1134 { 1135 __glibcxx_requires_string(__s); 1136 return this->replace(__pos, size_type(0), __s, 1137 traits_type::length(__s)); 1138 } 1139 1140 /** 1141 * @brief Insert multiple characters. 1142 * @param __pos Index in string to insert at. 1143 * @param __n Number of characters to insert 1144 * @param __c The character to insert. 1145 * @return Reference to this string. 1146 * @throw std::length_error If new length exceeds @c max_size(). 1147 * @throw std::out_of_range If @a __pos is beyond the end of this 1148 * string. 1149 * 1150 * Inserts @a __n copies of character @a __c starting at index 1151 * @a __pos. If adding characters causes the length to exceed 1152 * max_size(), length_error is thrown. If @a __pos > length(), 1153 * out_of_range is thrown. The value of the string doesn't 1154 * change if an error is thrown. 1155 */ 1156 __versa_string& 1157 insert(size_type __pos, size_type __n, _CharT __c) 1158 { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"), 1159 size_type(0), __n, __c); } 1160 1161 /** 1162 * @brief Insert one character. 1163 * @param __p Iterator referencing position in string to insert at. 1164 * @param __c The character to insert. 1165 * @return Iterator referencing newly inserted char. 1166 * @throw std::length_error If new length exceeds @c max_size(). 1167 * 1168 * Inserts character @a __c at position referenced by @a __p. 1169 * If adding character causes the length to exceed max_size(), 1170 * length_error is thrown. If @a __p is beyond end of string, 1171 * out_of_range is thrown. The value of the string doesn't 1172 * change if an error is thrown. 1173 */ 1174 iterator 1175 #if __cplusplus >= 201103L 1176 insert(const_iterator __p, _CharT __c) 1177 #else 1178 insert(iterator __p, _CharT __c) 1179 #endif 1180 { 1181 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); 1182 const size_type __pos = __p - _M_ibegin(); 1183 _M_replace_aux(__pos, size_type(0), size_type(1), __c); 1184 this->_M_set_leaked(); 1185 return iterator(this->_M_data() + __pos); 1186 } 1187 1188 /** 1189 * @brief Remove characters. 1190 * @param __pos Index of first character to remove (default 0). 1191 * @param __n Number of characters to remove (default remainder). 1192 * @return Reference to this string. 1193 * @throw std::out_of_range If @a __pos is beyond the end of this 1194 * string. 1195 * 1196 * Removes @a __n characters from this string starting at @a 1197 * __pos. The length of the string is reduced by @a __n. If 1198 * there are < @a __n characters to remove, the remainder of 1199 * the string is truncated. If @a __p is beyond end of string, 1200 * out_of_range is thrown. The value of the string doesn't 1201 * change if an error is thrown. 1202 */ 1203 __versa_string& 1204 erase(size_type __pos = 0, size_type __n = npos) 1205 { 1206 this->_M_erase(_M_check(__pos, "__versa_string::erase"), 1207 _M_limit(__pos, __n)); 1208 return *this; 1209 } 1210 1211 /** 1212 * @brief Remove one character. 1213 * @param __position Iterator referencing the character to remove. 1214 * @return iterator referencing same location after removal. 1215 * 1216 * Removes the character at @a __position from this string. The 1217 * value of the string doesn't change if an error is thrown. 1218 */ 1219 iterator 1220 #if __cplusplus >= 201103L 1221 erase(const_iterator __position) 1222 #else 1223 erase(iterator __position) 1224 #endif 1225 { 1226 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin() 1227 && __position < _M_iend()); 1228 const size_type __pos = __position - _M_ibegin(); 1229 this->_M_erase(__pos, size_type(1)); 1230 this->_M_set_leaked(); 1231 return iterator(this->_M_data() + __pos); 1232 } 1233 1234 /** 1235 * @brief Remove a range of characters. 1236 * @param __first Iterator referencing the first character to remove. 1237 * @param __last Iterator referencing the end of the range. 1238 * @return Iterator referencing location of first after removal. 1239 * 1240 * Removes the characters in the range [first,last) from this 1241 * string. The value of the string doesn't change if an error 1242 * is thrown. 1243 */ 1244 iterator 1245 #if __cplusplus >= 201103L 1246 erase(const_iterator __first, const_iterator __last) 1247 #else 1248 erase(iterator __first, iterator __last) 1249 #endif 1250 { 1251 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last 1252 && __last <= _M_iend()); 1253 const size_type __pos = __first - _M_ibegin(); 1254 this->_M_erase(__pos, __last - __first); 1255 this->_M_set_leaked(); 1256 return iterator(this->_M_data() + __pos); 1257 } 1258 1259 #if __cplusplus >= 201103L 1260 /** 1261 * @brief Remove the last character. 1262 * 1263 * The string must be non-empty. 1264 */ 1265 void 1266 pop_back() 1267 { this->_M_erase(size()-1, 1); } 1268 #endif // C++11 1269 1270 /** 1271 * @brief Replace characters with value from another string. 1272 * @param __pos Index of first character to replace. 1273 * @param __n Number of characters to be replaced. 1274 * @param __str String to insert. 1275 * @return Reference to this string. 1276 * @throw std::out_of_range If @a __pos is beyond the end of this 1277 * string. 1278 * @throw std::length_error If new length exceeds @c max_size(). 1279 * 1280 * Removes the characters in the range [pos,pos+n) from this 1281 * string. In place, the value of @a __str is inserted. If @a 1282 * __pos is beyond end of string, out_of_range is thrown. If 1283 * the length of the result exceeds max_size(), length_error is 1284 * thrown. The value of the string doesn't change if an error 1285 * is thrown. 1286 */ 1287 __versa_string& 1288 replace(size_type __pos, size_type __n, const __versa_string& __str) 1289 { return this->replace(__pos, __n, __str._M_data(), __str.size()); } 1290 1291 /** 1292 * @brief Replace characters with value from another string. 1293 * @param __pos1 Index of first character to replace. 1294 * @param __n1 Number of characters to be replaced. 1295 * @param __str String to insert. 1296 * @param __pos2 Index of first character of str to use. 1297 * @param __n2 Number of characters from str to use. 1298 * @return Reference to this string. 1299 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 > 1300 * str.size(). 1301 * @throw std::length_error If new length exceeds @c max_size(). 1302 * 1303 * Removes the characters in the range [pos1,pos1 + n) from 1304 * this string. In place, the value of @a __str is inserted. 1305 * If @a __pos is beyond end of string, out_of_range is thrown. 1306 * If the length of the result exceeds max_size(), length_error 1307 * is thrown. The value of the string doesn't change if an 1308 * error is thrown. 1309 */ 1310 __versa_string& 1311 replace(size_type __pos1, size_type __n1, const __versa_string& __str, 1312 size_type __pos2, size_type __n2) 1313 { 1314 return this->replace(__pos1, __n1, __str._M_data() 1315 + __str._M_check(__pos2, 1316 "__versa_string::replace"), 1317 __str._M_limit(__pos2, __n2)); 1318 } 1319 1320 /** 1321 * @brief Replace characters with value of a C substring. 1322 * @param __pos Index of first character to replace. 1323 * @param __n1 Number of characters to be replaced. 1324 * @param __s C string to insert. 1325 * @param __n2 Number of characters from @a __s to use. 1326 * @return Reference to this string. 1327 * @throw std::out_of_range If @a __pos1 > size(). 1328 * @throw std::length_error If new length exceeds @c max_size(). 1329 * 1330 * Removes the characters in the range [pos,pos + n1) from this 1331 * string. In place, the first @a __n2 characters of @a __s 1332 * are inserted, or all of @a __s if @a __n2 is too large. If 1333 * @a __pos is beyond end of string, out_of_range is thrown. 1334 * If the length of result exceeds max_size(), length_error is 1335 * thrown. The value of the string doesn't change if an error 1336 * is thrown. 1337 */ 1338 __versa_string& 1339 replace(size_type __pos, size_type __n1, const _CharT* __s, 1340 size_type __n2) 1341 { 1342 __glibcxx_requires_string_len(__s, __n2); 1343 return _M_replace(_M_check(__pos, "__versa_string::replace"), 1344 _M_limit(__pos, __n1), __s, __n2); 1345 } 1346 1347 /** 1348 * @brief Replace characters with value of a C string. 1349 * @param __pos Index of first character to replace. 1350 * @param __n1 Number of characters to be replaced. 1351 * @param __s C string to insert. 1352 * @return Reference to this string. 1353 * @throw std::out_of_range If @a __pos > size(). 1354 * @throw std::length_error If new length exceeds @c max_size(). 1355 * 1356 * Removes the characters in the range [pos,pos + n1) from this 1357 * string. In place, the characters of @a __s are inserted. If 1358 * @a pos is beyond end of string, out_of_range is thrown. If 1359 * the length of result exceeds max_size(), length_error is thrown. 1360 * The value of the string doesn't change if an error is thrown. 1361 */ 1362 __versa_string& 1363 replace(size_type __pos, size_type __n1, const _CharT* __s) 1364 { 1365 __glibcxx_requires_string(__s); 1366 return this->replace(__pos, __n1, __s, traits_type::length(__s)); 1367 } 1368 1369 /** 1370 * @brief Replace characters with multiple characters. 1371 * @param __pos Index of first character to replace. 1372 * @param __n1 Number of characters to be replaced. 1373 * @param __n2 Number of characters to insert. 1374 * @param __c Character to insert. 1375 * @return Reference to this string. 1376 * @throw std::out_of_range If @a __pos > size(). 1377 * @throw std::length_error If new length exceeds @c max_size(). 1378 * 1379 * Removes the characters in the range [pos,pos + n1) from this 1380 * string. In place, @a __n2 copies of @a __c are inserted. 1381 * If @a __pos is beyond end of string, out_of_range is thrown. 1382 * If the length of result exceeds max_size(), length_error is 1383 * thrown. The value of the string doesn't change if an error 1384 * is thrown. 1385 */ 1386 __versa_string& 1387 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) 1388 { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"), 1389 _M_limit(__pos, __n1), __n2, __c); } 1390 1391 /** 1392 * @brief Replace range of characters with string. 1393 * @param __i1 Iterator referencing start of range to replace. 1394 * @param __i2 Iterator referencing end of range to replace. 1395 * @param __str String value to insert. 1396 * @return Reference to this string. 1397 * @throw std::length_error If new length exceeds @c max_size(). 1398 * 1399 * Removes the characters in the range [i1,i2). In place, the 1400 * value of @a __str is inserted. If the length of result 1401 * exceeds max_size(), length_error is thrown. The value of 1402 * the string doesn't change if an error is thrown. 1403 */ 1404 __versa_string& 1405 #if __cplusplus >= 201103L 1406 replace(const_iterator __i1, const_iterator __i2, 1407 const __versa_string& __str) 1408 #else 1409 replace(iterator __i1, iterator __i2, const __versa_string& __str) 1410 #endif 1411 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } 1412 1413 /** 1414 * @brief Replace range of characters with C substring. 1415 * @param __i1 Iterator referencing start of range to replace. 1416 * @param __i2 Iterator referencing end of range to replace. 1417 * @param __s C string value to insert. 1418 * @param __n Number of characters from s to insert. 1419 * @return Reference to this string. 1420 * @throw std::length_error If new length exceeds @c max_size(). 1421 * 1422 * Removes the characters in the range [i1,i2). In place, the 1423 * first @a n characters of @a __s are inserted. If the length 1424 * of result exceeds max_size(), length_error is thrown. The 1425 * value of the string doesn't change if an error is thrown. 1426 */ 1427 __versa_string& 1428 #if __cplusplus >= 201103L 1429 replace(const_iterator __i1, const_iterator __i2, 1430 const _CharT* __s, size_type __n) 1431 #else 1432 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) 1433 #endif 1434 { 1435 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1436 && __i2 <= _M_iend()); 1437 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n); 1438 } 1439 1440 /** 1441 * @brief Replace range of characters with C string. 1442 * @param __i1 Iterator referencing start of range to replace. 1443 * @param __i2 Iterator referencing end of range to replace. 1444 * @param __s C string value to insert. 1445 * @return Reference to this string. 1446 * @throw std::length_error If new length exceeds @c max_size(). 1447 * 1448 * Removes the characters in the range [i1,i2). In place, the 1449 * characters of @a __s are inserted. If the length of result 1450 * exceeds max_size(), length_error is thrown. The value of 1451 * the string doesn't change if an error is thrown. 1452 */ 1453 __versa_string& 1454 #if __cplusplus >= 201103L 1455 replace(const_iterator __i1, const_iterator __i2, const _CharT* __s) 1456 #else 1457 replace(iterator __i1, iterator __i2, const _CharT* __s) 1458 #endif 1459 { 1460 __glibcxx_requires_string(__s); 1461 return this->replace(__i1, __i2, __s, traits_type::length(__s)); 1462 } 1463 1464 /** 1465 * @brief Replace range of characters with multiple characters 1466 * @param __i1 Iterator referencing start of range to replace. 1467 * @param __i2 Iterator referencing end of range to replace. 1468 * @param __n Number of characters to insert. 1469 * @param __c Character to insert. 1470 * @return Reference to this string. 1471 * @throw std::length_error If new length exceeds @c max_size(). 1472 * 1473 * Removes the characters in the range [i1,i2). In place, @a 1474 * __n copies of @a __c are inserted. If the length of result 1475 * exceeds max_size(), length_error is thrown. The value of 1476 * the string doesn't change if an error is thrown. 1477 */ 1478 __versa_string& 1479 #if __cplusplus >= 201103L 1480 replace(const_iterator __i1, const_iterator __i2, size_type __n, 1481 _CharT __c) 1482 #else 1483 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c) 1484 #endif 1485 { 1486 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1487 && __i2 <= _M_iend()); 1488 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c); 1489 } 1490 1491 /** 1492 * @brief Replace range of characters with range. 1493 * @param __i1 Iterator referencing start of range to replace. 1494 * @param __i2 Iterator referencing end of range to replace. 1495 * @param __k1 Iterator referencing start of range to insert. 1496 * @param __k2 Iterator referencing end of range to insert. 1497 * @return Reference to this string. 1498 * @throw std::length_error If new length exceeds @c max_size(). 1499 * 1500 * Removes the characters in the range [i1,i2). In place, 1501 * characters in the range [k1,k2) are inserted. If the length 1502 * of result exceeds max_size(), length_error is thrown. The 1503 * value of the string doesn't change if an error is thrown. 1504 */ 1505 #if __cplusplus >= 201103L 1506 template<class _InputIterator, 1507 typename = std::_RequireInputIter<_InputIterator>> 1508 __versa_string& 1509 replace(const_iterator __i1, const_iterator __i2, 1510 _InputIterator __k1, _InputIterator __k2) 1511 { 1512 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1513 && __i2 <= _M_iend()); 1514 __glibcxx_requires_valid_range(__k1, __k2); 1515 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, 1516 std::__false_type()); 1517 } 1518 #else 1519 template<class _InputIterator> 1520 __versa_string& 1521 replace(iterator __i1, iterator __i2, 1522 _InputIterator __k1, _InputIterator __k2) 1523 { 1524 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1525 && __i2 <= _M_iend()); 1526 __glibcxx_requires_valid_range(__k1, __k2); 1527 typedef typename std::__is_integer<_InputIterator>::__type _Integral; 1528 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); 1529 } 1530 #endif 1531 1532 // Specializations for the common case of pointer and iterator: 1533 // useful to avoid the overhead of temporary buffering in _M_replace. 1534 __versa_string& 1535 #if __cplusplus >= 201103L 1536 replace(const_iterator __i1, const_iterator __i2, 1537 _CharT* __k1, _CharT* __k2) 1538 #else 1539 replace(iterator __i1, iterator __i2, 1540 _CharT* __k1, _CharT* __k2) 1541 #endif 1542 { 1543 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1544 && __i2 <= _M_iend()); 1545 __glibcxx_requires_valid_range(__k1, __k2); 1546 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 1547 __k1, __k2 - __k1); 1548 } 1549 1550 __versa_string& 1551 #if __cplusplus >= 201103L 1552 replace(const_iterator __i1, const_iterator __i2, 1553 const _CharT* __k1, const _CharT* __k2) 1554 #else 1555 replace(iterator __i1, iterator __i2, 1556 const _CharT* __k1, const _CharT* __k2) 1557 #endif 1558 { 1559 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1560 && __i2 <= _M_iend()); 1561 __glibcxx_requires_valid_range(__k1, __k2); 1562 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 1563 __k1, __k2 - __k1); 1564 } 1565 1566 __versa_string& 1567 #if __cplusplus >= 201103L 1568 replace(const_iterator __i1, const_iterator __i2, 1569 iterator __k1, iterator __k2) 1570 #else 1571 replace(iterator __i1, iterator __i2, 1572 iterator __k1, iterator __k2) 1573 #endif 1574 { 1575 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1576 && __i2 <= _M_iend()); 1577 __glibcxx_requires_valid_range(__k1, __k2); 1578 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 1579 __k1.base(), __k2 - __k1); 1580 } 1581 1582 __versa_string& 1583 #if __cplusplus >= 201103L 1584 replace(const_iterator __i1, const_iterator __i2, 1585 const_iterator __k1, const_iterator __k2) 1586 #else 1587 replace(iterator __i1, iterator __i2, 1588 const_iterator __k1, const_iterator __k2) 1589 #endif 1590 { 1591 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1592 && __i2 <= _M_iend()); 1593 __glibcxx_requires_valid_range(__k1, __k2); 1594 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 1595 __k1.base(), __k2 - __k1); 1596 } 1597 1598 #if __cplusplus >= 201103L 1599 /** 1600 * @brief Replace range of characters with initializer_list. 1601 * @param __i1 Iterator referencing start of range to replace. 1602 * @param __i2 Iterator referencing end of range to replace. 1603 * @param __l The initializer_list of characters to insert. 1604 * @return Reference to this string. 1605 * @throw std::length_error If new length exceeds @c max_size(). 1606 * 1607 * Removes the characters in the range [i1,i2). In place, 1608 * characters in the range [k1,k2) are inserted. If the length 1609 * of result exceeds max_size(), length_error is thrown. The 1610 * value of the string doesn't change if an error is thrown. 1611 */ 1612 __versa_string& 1613 replace(const_iterator __i1, const_iterator __i2, 1614 std::initializer_list<_CharT> __l) 1615 { return this->replace(__i1, __i2, __l.begin(), __l.end()); } 1616 #endif // C++11 1617 1618 private: 1619 template<class _Integer> 1620 __versa_string& 1621 _M_replace_dispatch(const_iterator __i1, const_iterator __i2, 1622 _Integer __n, _Integer __val, std::__true_type) 1623 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); } 1624 1625 template<class _InputIterator> 1626 __versa_string& 1627 _M_replace_dispatch(const_iterator __i1, const_iterator __i2, 1628 _InputIterator __k1, _InputIterator __k2, 1629 std::__false_type); 1630 1631 __versa_string& 1632 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, 1633 _CharT __c); 1634 1635 __versa_string& 1636 _M_replace(size_type __pos, size_type __len1, const _CharT* __s, 1637 const size_type __len2); 1638 1639 __versa_string& 1640 _M_append(const _CharT* __s, size_type __n); 1641 1642 public: 1643 1644 /** 1645 * @brief Copy substring into C string. 1646 * @param __s C string to copy value into. 1647 * @param __n Number of characters to copy. 1648 * @param __pos Index of first character to copy. 1649 * @return Number of characters actually copied 1650 * @throw std::out_of_range If pos > size(). 1651 * 1652 * Copies up to @a __n characters starting at @a __pos into the 1653 * C string @a s. If @a __pos is greater than size(), 1654 * out_of_range is thrown. 1655 */ 1656 size_type 1657 copy(_CharT* __s, size_type __n, size_type __pos = 0) const; 1658 1659 /** 1660 * @brief Swap contents with another string. 1661 * @param __s String to swap with. 1662 * 1663 * Exchanges the contents of this string with that of @a __s in 1664 * constant time. 1665 */ 1666 void 1667 swap(__versa_string& __s) _GLIBCXX_NOEXCEPT 1668 { this->_M_swap(__s); } 1669 1670 // String operations: 1671 /** 1672 * @brief Return const pointer to null-terminated contents. 1673 * 1674 * This is a handle to internal data. Do not modify or dire things may 1675 * happen. 1676 */ 1677 const _CharT* 1678 c_str() const _GLIBCXX_NOEXCEPT 1679 { return this->_M_data(); } 1680 1681 /** 1682 * @brief Return const pointer to contents. 1683 * 1684 * This is a handle to internal data. Do not modify or dire things may 1685 * happen. 1686 */ 1687 const _CharT* 1688 data() const _GLIBCXX_NOEXCEPT 1689 { return this->_M_data(); } 1690 1691 /** 1692 * @brief Return copy of allocator used to construct this string. 1693 */ 1694 allocator_type 1695 get_allocator() const _GLIBCXX_NOEXCEPT 1696 { return allocator_type(this->_M_get_allocator()); } 1697 1698 /** 1699 * @brief Find position of a C substring. 1700 * @param __s C string to locate. 1701 * @param __pos Index of character to search from. 1702 * @param __n Number of characters from @a __s to search for. 1703 * @return Index of start of first occurrence. 1704 * 1705 * Starting from @a __pos, searches forward for the first @a 1706 * __n characters in @a __s within this string. If found, 1707 * returns the index where it begins. If not found, returns 1708 * npos. 1709 */ 1710 size_type 1711 find(const _CharT* __s, size_type __pos, size_type __n) const; 1712 1713 /** 1714 * @brief Find position of a string. 1715 * @param __str String to locate. 1716 * @param __pos Index of character to search from (default 0). 1717 * @return Index of start of first occurrence. 1718 * 1719 * Starting from @a __pos, searches forward for value of @a 1720 * __str within this string. If found, returns the index where 1721 * it begins. If not found, returns npos. 1722 */ 1723 size_type 1724 find(const __versa_string& __str, size_type __pos = 0) const 1725 _GLIBCXX_NOEXCEPT 1726 { return this->find(__str.data(), __pos, __str.size()); } 1727 1728 /** 1729 * @brief Find position of a C string. 1730 * @param __s C string to locate. 1731 * @param __pos Index of character to search from (default 0). 1732 * @return Index of start of first occurrence. 1733 * 1734 * Starting from @a __pos, searches forward for the value of @a 1735 * __s within this string. If found, returns the index where 1736 * it begins. If not found, returns npos. 1737 */ 1738 size_type 1739 find(const _CharT* __s, size_type __pos = 0) const 1740 { 1741 __glibcxx_requires_string(__s); 1742 return this->find(__s, __pos, traits_type::length(__s)); 1743 } 1744 1745 /** 1746 * @brief Find position of a character. 1747 * @param __c Character to locate. 1748 * @param __pos Index of character to search from (default 0). 1749 * @return Index of first occurrence. 1750 * 1751 * Starting from @a __pos, searches forward for @a __c within 1752 * this string. If found, returns the index where it was 1753 * found. If not found, returns npos. 1754 */ 1755 size_type 1756 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT; 1757 1758 /** 1759 * @brief Find last position of a string. 1760 * @param __str String to locate. 1761 * @param __pos Index of character to search back from (default end). 1762 * @return Index of start of last occurrence. 1763 * 1764 * Starting from @a __pos, searches backward for value of @a 1765 * __str within this string. If found, returns the index where 1766 * it begins. If not found, returns npos. 1767 */ 1768 size_type 1769 rfind(const __versa_string& __str, size_type __pos = npos) const 1770 _GLIBCXX_NOEXCEPT 1771 { return this->rfind(__str.data(), __pos, __str.size()); } 1772 1773 /** 1774 * @brief Find last position of a C substring. 1775 * @param __s C string to locate. 1776 * @param __pos Index of character to search back from. 1777 * @param __n Number of characters from s to search for. 1778 * @return Index of start of last occurrence. 1779 * 1780 * Starting from @a __pos, searches backward for the first @a 1781 * __n characters in @a __s within this string. If found, 1782 * returns the index where it begins. If not found, returns 1783 * npos. 1784 */ 1785 size_type 1786 rfind(const _CharT* __s, size_type __pos, size_type __n) const; 1787 1788 /** 1789 * @brief Find last position of a C string. 1790 * @param __s C string to locate. 1791 * @param __pos Index of character to start search at (default end). 1792 * @return Index of start of last occurrence. 1793 * 1794 * Starting from @a __pos, searches backward for the value of 1795 * @a __s within this string. If found, returns the index 1796 * where it begins. If not found, returns npos. 1797 */ 1798 size_type 1799 rfind(const _CharT* __s, size_type __pos = npos) const 1800 { 1801 __glibcxx_requires_string(__s); 1802 return this->rfind(__s, __pos, traits_type::length(__s)); 1803 } 1804 1805 /** 1806 * @brief Find last position of a character. 1807 * @param __c Character to locate. 1808 * @param __pos Index of character to search back from (default end). 1809 * @return Index of last occurrence. 1810 * 1811 * Starting from @a __pos, searches backward for @a __c within 1812 * this string. If found, returns the index where it was 1813 * found. If not found, returns npos. 1814 */ 1815 size_type 1816 rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT; 1817 1818 /** 1819 * @brief Find position of a character of string. 1820 * @param __str String containing characters to locate. 1821 * @param __pos Index of character to search from (default 0). 1822 * @return Index of first occurrence. 1823 * 1824 * Starting from @a __pos, searches forward for one of the characters of 1825 * @a __str within this string. If found, returns the index where it was 1826 * found. If not found, returns npos. 1827 */ 1828 size_type 1829 find_first_of(const __versa_string& __str, size_type __pos = 0) const 1830 _GLIBCXX_NOEXCEPT 1831 { return this->find_first_of(__str.data(), __pos, __str.size()); } 1832 1833 /** 1834 * @brief Find position of a character of C substring. 1835 * @param __s String containing characters to locate. 1836 * @param __pos Index of character to search from. 1837 * @param __n Number of characters from s to search for. 1838 * @return Index of first occurrence. 1839 * 1840 * Starting from @a __pos, searches forward for one of the 1841 * first @a __n characters of @a __s within this string. If 1842 * found, returns the index where it was found. If not found, 1843 * returns npos. 1844 */ 1845 size_type 1846 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const; 1847 1848 /** 1849 * @brief Find position of a character of C string. 1850 * @param __s String containing characters to locate. 1851 * @param __pos Index of character to search from (default 0). 1852 * @return Index of first occurrence. 1853 * 1854 * Starting from @a __pos, searches forward for one of the 1855 * characters of @a __s within this string. If found, returns 1856 * the index where it was found. If not found, returns npos. 1857 */ 1858 size_type 1859 find_first_of(const _CharT* __s, size_type __pos = 0) const 1860 { 1861 __glibcxx_requires_string(__s); 1862 return this->find_first_of(__s, __pos, traits_type::length(__s)); 1863 } 1864 1865 /** 1866 * @brief Find position of a character. 1867 * @param __c Character to locate. 1868 * @param __pos Index of character to search from (default 0). 1869 * @return Index of first occurrence. 1870 * 1871 * Starting from @a __pos, searches forward for the character 1872 * @a __c within this string. If found, returns the index 1873 * where it was found. If not found, returns npos. 1874 * 1875 * Note: equivalent to find(c, pos). 1876 */ 1877 size_type 1878 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT 1879 { return this->find(__c, __pos); } 1880 1881 /** 1882 * @brief Find last position of a character of string. 1883 * @param __str String containing characters to locate. 1884 * @param __pos Index of character to search back from (default end). 1885 * @return Index of last occurrence. 1886 * 1887 * Starting from @a __pos, searches backward for one of the 1888 * characters of @a __str within this string. If found, 1889 * returns the index where it was found. If not found, returns 1890 * npos. 1891 */ 1892 size_type 1893 find_last_of(const __versa_string& __str, size_type __pos = npos) const 1894 _GLIBCXX_NOEXCEPT 1895 { return this->find_last_of(__str.data(), __pos, __str.size()); } 1896 1897 /** 1898 * @brief Find last position of a character of C substring. 1899 * @param __s C string containing characters to locate. 1900 * @param __pos Index of character to search back from. 1901 * @param __n Number of characters from s to search for. 1902 * @return Index of last occurrence. 1903 * 1904 * Starting from @a __pos, searches backward for one of the 1905 * first @a __n characters of @a __s within this string. If 1906 * found, returns the index where it was found. If not found, 1907 * returns npos. 1908 */ 1909 size_type 1910 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const; 1911 1912 /** 1913 * @brief Find last position of a character of C string. 1914 * @param __s C string containing characters to locate. 1915 * @param __pos Index of character to search back from (default end). 1916 * @return Index of last occurrence. 1917 * 1918 * Starting from @a __pos, searches backward for one of the 1919 * characters of @a __s within this string. If found, returns 1920 * the index where it was found. If not found, returns npos. 1921 */ 1922 size_type 1923 find_last_of(const _CharT* __s, size_type __pos = npos) const 1924 { 1925 __glibcxx_requires_string(__s); 1926 return this->find_last_of(__s, __pos, traits_type::length(__s)); 1927 } 1928 1929 /** 1930 * @brief Find last position of a character. 1931 * @param __c Character to locate. 1932 * @param __pos Index of character to search back from (default end). 1933 * @return Index of last occurrence. 1934 * 1935 * Starting from @a __pos, searches backward for @a __c within 1936 * this string. If found, returns the index where it was 1937 * found. If not found, returns npos. 1938 * 1939 * Note: equivalent to rfind(c, pos). 1940 */ 1941 size_type 1942 find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT 1943 { return this->rfind(__c, __pos); } 1944 1945 /** 1946 * @brief Find position of a character not in string. 1947 * @param __str String containing characters to avoid. 1948 * @param __pos Index of character to search from (default 0). 1949 * @return Index of first occurrence. 1950 * 1951 * Starting from @a __pos, searches forward for a character not 1952 * contained in @a __str within this string. If found, returns 1953 * the index where it was found. If not found, returns npos. 1954 */ 1955 size_type 1956 find_first_not_of(const __versa_string& __str, size_type __pos = 0) const 1957 _GLIBCXX_NOEXCEPT 1958 { return this->find_first_not_of(__str.data(), __pos, __str.size()); } 1959 1960 /** 1961 * @brief Find position of a character not in C substring. 1962 * @param __s C string containing characters to avoid. 1963 * @param __pos Index of character to search from. 1964 * @param __n Number of characters from s to consider. 1965 * @return Index of first occurrence. 1966 * 1967 * Starting from @a __pos, searches forward for a character not 1968 * contained in the first @a __n characters of @a __s within 1969 * this string. If found, returns the index where it was 1970 * found. If not found, returns npos. 1971 */ 1972 size_type 1973 find_first_not_of(const _CharT* __s, size_type __pos, 1974 size_type __n) const; 1975 1976 /** 1977 * @brief Find position of a character not in C string. 1978 * @param __s C string containing characters to avoid. 1979 * @param __pos Index of character to search from (default 0). 1980 * @return Index of first occurrence. 1981 * 1982 * Starting from @a __pos, searches forward for a character not 1983 * contained in @a __s within this string. If found, returns 1984 * the index where it was found. If not found, returns npos. 1985 */ 1986 size_type 1987 find_first_not_of(const _CharT* __s, size_type __pos = 0) const 1988 { 1989 __glibcxx_requires_string(__s); 1990 return this->find_first_not_of(__s, __pos, traits_type::length(__s)); 1991 } 1992 1993 /** 1994 * @brief Find position of a different character. 1995 * @param __c Character to avoid. 1996 * @param __pos Index of character to search from (default 0). 1997 * @return Index of first occurrence. 1998 * 1999 * Starting from @a __pos, searches forward for a character 2000 * other than @a __c within this string. If found, returns the 2001 * index where it was found. If not found, returns npos. 2002 */ 2003 size_type 2004 find_first_not_of(_CharT __c, size_type __pos = 0) const 2005 _GLIBCXX_NOEXCEPT; 2006 2007 /** 2008 * @brief Find last position of a character not in string. 2009 * @param __str String containing characters to avoid. 2010 * @param __pos Index of character to search back from (default end). 2011 * @return Index of last occurrence. 2012 * 2013 * Starting from @a __pos, searches backward for a character 2014 * not contained in @a __str within this string. If found, 2015 * returns the index where it was found. If not found, returns 2016 * npos. 2017 */ 2018 size_type 2019 find_last_not_of(const __versa_string& __str, 2020 size_type __pos = npos) const _GLIBCXX_NOEXCEPT 2021 { return this->find_last_not_of(__str.data(), __pos, __str.size()); } 2022 2023 /** 2024 * @brief Find last position of a character not in C substring. 2025 * @param __s C string containing characters to avoid. 2026 * @param __pos Index of character to search back from. 2027 * @param __n Number of characters from s to consider. 2028 * @return Index of last occurrence. 2029 * 2030 * Starting from @a __pos, searches backward for a character 2031 * not contained in the first @a __n characters of @a __s 2032 * within this string. If found, returns the index where it 2033 * was found. If not found, returns npos. 2034 */ 2035 size_type 2036 find_last_not_of(const _CharT* __s, size_type __pos, 2037 size_type __n) const; 2038 /** 2039 * @brief Find last position of a character not in C string. 2040 * @param __s C string containing characters to avoid. 2041 * @param __pos Index of character to search back from (default end). 2042 * @return Index of last occurrence. 2043 * 2044 * Starting from @a __pos, searches backward for a character 2045 * not contained in @a __s within this string. If found, 2046 * returns the index where it was found. If not found, returns 2047 * npos. 2048 */ 2049 size_type 2050 find_last_not_of(const _CharT* __s, size_type __pos = npos) const 2051 { 2052 __glibcxx_requires_string(__s); 2053 return this->find_last_not_of(__s, __pos, traits_type::length(__s)); 2054 } 2055 2056 /** 2057 * @brief Find last position of a different character. 2058 * @param __c Character to avoid. 2059 * @param __pos Index of character to search back from (default end). 2060 * @return Index of last occurrence. 2061 * 2062 * Starting from @a __pos, searches backward for a character 2063 * other than @a __c within this string. If found, returns the 2064 * index where it was found. If not found, returns npos. 2065 */ 2066 size_type 2067 find_last_not_of(_CharT __c, size_type __pos = npos) const 2068 _GLIBCXX_NOEXCEPT; 2069 2070 /** 2071 * @brief Get a substring. 2072 * @param __pos Index of first character (default 0). 2073 * @param __n Number of characters in substring (default remainder). 2074 * @return The new string. 2075 * @throw std::out_of_range If pos > size(). 2076 * 2077 * Construct and return a new string using the @a __n 2078 * characters starting at @a __pos. If the string is too 2079 * short, use the remainder of the characters. If @a __pos is 2080 * beyond the end of the string, out_of_range is thrown. 2081 */ 2082 __versa_string 2083 substr(size_type __pos = 0, size_type __n = npos) const 2084 { 2085 return __versa_string(*this, _M_check(__pos, "__versa_string::substr"), 2086 __n); 2087 } 2088 2089 /** 2090 * @brief Compare to a string. 2091 * @param __str String to compare against. 2092 * @return Integer < 0, 0, or > 0. 2093 * 2094 * Returns an integer < 0 if this string is ordered before @a 2095 * __str, 0 if their values are equivalent, or > 0 if this 2096 * string is ordered after @a __str. Determines the effective 2097 * length rlen of the strings to compare as the smallest of 2098 * size() and str.size(). The function then compares the two 2099 * strings by calling traits::compare(data(), str.data(),rlen). 2100 * If the result of the comparison is nonzero returns it, 2101 * otherwise the shorter one is ordered first. 2102 */ 2103 int 2104 compare(const __versa_string& __str) const 2105 { 2106 if (this->_M_compare(__str)) 2107 return 0; 2108 2109 const size_type __size = this->size(); 2110 const size_type __osize = __str.size(); 2111 const size_type __len = std::min(__size, __osize); 2112 2113 int __r = traits_type::compare(this->_M_data(), __str.data(), __len); 2114 if (!__r) 2115 __r = this->_S_compare(__size, __osize); 2116 return __r; 2117 } 2118 2119 /** 2120 * @brief Compare substring to a string. 2121 * @param __pos Index of first character of substring. 2122 * @param __n Number of characters in substring. 2123 * @param __str String to compare against. 2124 * @return Integer < 0, 0, or > 0. 2125 * 2126 * Form the substring of this string from the @a __n characters 2127 * starting at @a __pos. Returns an integer < 0 if the 2128 * substring is ordered before @a __str, 0 if their values are 2129 * equivalent, or > 0 if the substring is ordered after @a 2130 * __str. Determines the effective length rlen of the strings 2131 * to compare as the smallest of the length of the substring 2132 * and @a __str.size(). The function then compares the two 2133 * strings by calling 2134 * traits::compare(substring.data(),str.data(),rlen). If the 2135 * result of the comparison is nonzero returns it, otherwise 2136 * the shorter one is ordered first. 2137 */ 2138 int 2139 compare(size_type __pos, size_type __n, 2140 const __versa_string& __str) const; 2141 2142 /** 2143 * @brief Compare substring to a substring. 2144 * @param __pos1 Index of first character of substring. 2145 * @param __n1 Number of characters in substring. 2146 * @param __str String to compare against. 2147 * @param __pos2 Index of first character of substring of str. 2148 * @param __n2 Number of characters in substring of str. 2149 * @return Integer < 0, 0, or > 0. 2150 * 2151 * Form the substring of this string from the @a __n1 2152 * characters starting at @a __pos1. Form the substring of @a 2153 * __str from the @a __n2 characters starting at @a __pos2. 2154 * Returns an integer < 0 if this substring is ordered before 2155 * the substring of @a __str, 0 if their values are equivalent, 2156 * or > 0 if this substring is ordered after the substring of 2157 * @a __str. Determines the effective length rlen of the 2158 * strings to compare as the smallest of the lengths of the 2159 * substrings. The function then compares the two strings by 2160 * calling 2161 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). 2162 * If the result of the comparison is nonzero returns it, 2163 * otherwise the shorter one is ordered first. 2164 */ 2165 int 2166 compare(size_type __pos1, size_type __n1, const __versa_string& __str, 2167 size_type __pos2, size_type __n2) const; 2168 2169 /** 2170 * @brief Compare to a C string. 2171 * @param __s C string to compare against. 2172 * @return Integer < 0, 0, or > 0. 2173 * 2174 * Returns an integer < 0 if this string is ordered before @a 2175 * __s, 0 if their values are equivalent, or > 0 if this string 2176 * is ordered after @a __s. Determines the effective length 2177 * rlen of the strings to compare as the smallest of size() and 2178 * the length of a string constructed from @a __s. The 2179 * function then compares the two strings by calling 2180 * traits::compare(data(),s,rlen). If the result of the 2181 * comparison is nonzero returns it, otherwise the shorter one 2182 * is ordered first. 2183 */ 2184 int 2185 compare(const _CharT* __s) const; 2186 2187 // _GLIBCXX_RESOLVE_LIB_DEFECTS 2188 // 5 String::compare specification questionable 2189 /** 2190 * @brief Compare substring to a C string. 2191 * @param __pos Index of first character of substring. 2192 * @param __n1 Number of characters in substring. 2193 * @param __s C string to compare against. 2194 * @return Integer < 0, 0, or > 0. 2195 * 2196 * Form the substring of this string from the @a __n1 2197 * characters starting at @a __pos. Returns an integer < 0 if 2198 * the substring is ordered before @a __s, 0 if their values 2199 * are equivalent, or > 0 if the substring is ordered after @a 2200 * __s. Determines the effective length rlen of the strings to 2201 * compare as the smallest of the length of the substring and 2202 * the length of a string constructed from @a __s. The 2203 * function then compares the two string by calling 2204 * traits::compare(substring.data(),s,rlen). If the result of 2205 * the comparison is nonzero returns it, otherwise the shorter 2206 * one is ordered first. 2207 */ 2208 int 2209 compare(size_type __pos, size_type __n1, const _CharT* __s) const; 2210 2211 /** 2212 * @brief Compare substring against a character array. 2213 * @param __pos Index of first character of substring. 2214 * @param __n1 Number of characters in substring. 2215 * @param __s character array to compare against. 2216 * @param __n2 Number of characters of s. 2217 * @return Integer < 0, 0, or > 0. 2218 * 2219 * Form the substring of this string from the @a __n1 2220 * characters starting at @a __pos. Form a string from the 2221 * first @a __n2 characters of @a __s. Returns an integer < 0 2222 * if this substring is ordered before the string from @a __s, 2223 * 0 if their values are equivalent, or > 0 if this substring 2224 * is ordered after the string from @a __s. Determines the 2225 * effective length rlen of the strings to compare as the 2226 * smallest of the length of the substring and @a __n2. The 2227 * function then compares the two strings by calling 2228 * traits::compare(substring.data(),__s,rlen). If the result of 2229 * the comparison is nonzero returns it, otherwise the shorter 2230 * one is ordered first. 2231 * 2232 * NB: __s must have at least n2 characters, <em>\\0</em> has no special 2233 * meaning. 2234 */ 2235 int 2236 compare(size_type __pos, size_type __n1, const _CharT* __s, 2237 size_type __n2) const; 2238 }; 2239 2240 // operator+ 2241 /** 2242 * @brief Concatenate two strings. 2243 * @param __lhs First string. 2244 * @param __rhs Last string. 2245 * @return New string with value of @a __lhs followed by @a __rhs. 2246 */ 2247 template<typename _CharT, typename _Traits, typename _Alloc, 2248 template <typename, typename, typename> class _Base> 2249 __versa_string<_CharT, _Traits, _Alloc, _Base> 2250 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2251 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); 2252 2253 /** 2254 * @brief Concatenate C string and string. 2255 * @param __lhs First string. 2256 * @param __rhs Last string. 2257 * @return New string with value of @a __lhs followed by @a __rhs. 2258 */ 2259 template<typename _CharT, typename _Traits, typename _Alloc, 2260 template <typename, typename, typename> class _Base> 2261 __versa_string<_CharT, _Traits, _Alloc, _Base> 2262 operator+(const _CharT* __lhs, 2263 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); 2264 2265 /** 2266 * @brief Concatenate character and string. 2267 * @param __lhs First string. 2268 * @param __rhs Last string. 2269 * @return New string with @a __lhs followed by @a __rhs. 2270 */ 2271 template<typename _CharT, typename _Traits, typename _Alloc, 2272 template <typename, typename, typename> class _Base> 2273 __versa_string<_CharT, _Traits, _Alloc, _Base> 2274 operator+(_CharT __lhs, 2275 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); 2276 2277 /** 2278 * @brief Concatenate string and C string. 2279 * @param __lhs First string. 2280 * @param __rhs Last string. 2281 * @return New string with @a __lhs followed by @a __rhs. 2282 */ 2283 template<typename _CharT, typename _Traits, typename _Alloc, 2284 template <typename, typename, typename> class _Base> 2285 __versa_string<_CharT, _Traits, _Alloc, _Base> 2286 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2287 const _CharT* __rhs); 2288 2289 /** 2290 * @brief Concatenate string and character. 2291 * @param __lhs First string. 2292 * @param __rhs Last string. 2293 * @return New string with @a __lhs followed by @a __rhs. 2294 */ 2295 template<typename _CharT, typename _Traits, typename _Alloc, 2296 template <typename, typename, typename> class _Base> 2297 __versa_string<_CharT, _Traits, _Alloc, _Base> 2298 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2299 _CharT __rhs); 2300 2301 #if __cplusplus >= 201103L 2302 template<typename _CharT, typename _Traits, typename _Alloc, 2303 template <typename, typename, typename> class _Base> 2304 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 2305 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, 2306 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2307 { return std::move(__lhs.append(__rhs)); } 2308 2309 template<typename _CharT, typename _Traits, typename _Alloc, 2310 template <typename, typename, typename> class _Base> 2311 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 2312 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2313 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) 2314 { return std::move(__rhs.insert(0, __lhs)); } 2315 2316 template<typename _CharT, typename _Traits, typename _Alloc, 2317 template <typename, typename, typename> class _Base> 2318 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 2319 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, 2320 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) 2321 { 2322 const auto __size = __lhs.size() + __rhs.size(); 2323 const bool __cond = (__size > __lhs.capacity() 2324 && __size <= __rhs.capacity()); 2325 return __cond ? std::move(__rhs.insert(0, __lhs)) 2326 : std::move(__lhs.append(__rhs)); 2327 } 2328 2329 template<typename _CharT, typename _Traits, typename _Alloc, 2330 template <typename, typename, typename> class _Base> 2331 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 2332 operator+(const _CharT* __lhs, 2333 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) 2334 { return std::move(__rhs.insert(0, __lhs)); } 2335 2336 template<typename _CharT, typename _Traits, typename _Alloc, 2337 template <typename, typename, typename> class _Base> 2338 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 2339 operator+(_CharT __lhs, 2340 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) 2341 { return std::move(__rhs.insert(0, 1, __lhs)); } 2342 2343 template<typename _CharT, typename _Traits, typename _Alloc, 2344 template <typename, typename, typename> class _Base> 2345 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 2346 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, 2347 const _CharT* __rhs) 2348 { return std::move(__lhs.append(__rhs)); } 2349 2350 template<typename _CharT, typename _Traits, typename _Alloc, 2351 template <typename, typename, typename> class _Base> 2352 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 2353 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, 2354 _CharT __rhs) 2355 { return std::move(__lhs.append(1, __rhs)); } 2356 #endif 2357 2358 // operator == 2359 /** 2360 * @brief Test equivalence of two strings. 2361 * @param __lhs First string. 2362 * @param __rhs Second string. 2363 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. 2364 */ 2365 template<typename _CharT, typename _Traits, typename _Alloc, 2366 template <typename, typename, typename> class _Base> 2367 inline bool 2368 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2369 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2370 { return __lhs.compare(__rhs) == 0; } 2371 2372 template<typename _CharT, 2373 template <typename, typename, typename> class _Base> 2374 inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type 2375 operator==(const __versa_string<_CharT, std::char_traits<_CharT>, 2376 std::allocator<_CharT>, _Base>& __lhs, 2377 const __versa_string<_CharT, std::char_traits<_CharT>, 2378 std::allocator<_CharT>, _Base>& __rhs) 2379 { return (__lhs.size() == __rhs.size() 2380 && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(), 2381 __lhs.size())); } 2382 2383 /** 2384 * @brief Test equivalence of C string and string. 2385 * @param __lhs C string. 2386 * @param __rhs String. 2387 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise. 2388 */ 2389 template<typename _CharT, typename _Traits, typename _Alloc, 2390 template <typename, typename, typename> class _Base> 2391 inline bool 2392 operator==(const _CharT* __lhs, 2393 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2394 { return __rhs.compare(__lhs) == 0; } 2395 2396 /** 2397 * @brief Test equivalence of string and C string. 2398 * @param __lhs String. 2399 * @param __rhs C string. 2400 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. 2401 */ 2402 template<typename _CharT, typename _Traits, typename _Alloc, 2403 template <typename, typename, typename> class _Base> 2404 inline bool 2405 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2406 const _CharT* __rhs) 2407 { return __lhs.compare(__rhs) == 0; } 2408 2409 // operator != 2410 /** 2411 * @brief Test difference of two strings. 2412 * @param __lhs First string. 2413 * @param __rhs Second string. 2414 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. 2415 */ 2416 template<typename _CharT, typename _Traits, typename _Alloc, 2417 template <typename, typename, typename> class _Base> 2418 inline bool 2419 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2420 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2421 { return !(__lhs == __rhs); } 2422 2423 /** 2424 * @brief Test difference of C string and string. 2425 * @param __lhs C string. 2426 * @param __rhs String. 2427 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise. 2428 */ 2429 template<typename _CharT, typename _Traits, typename _Alloc, 2430 template <typename, typename, typename> class _Base> 2431 inline bool 2432 operator!=(const _CharT* __lhs, 2433 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2434 { return !(__lhs == __rhs); } 2435 2436 /** 2437 * @brief Test difference of string and C string. 2438 * @param __lhs String. 2439 * @param __rhs C string. 2440 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. 2441 */ 2442 template<typename _CharT, typename _Traits, typename _Alloc, 2443 template <typename, typename, typename> class _Base> 2444 inline bool 2445 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2446 const _CharT* __rhs) 2447 { return !(__lhs == __rhs); } 2448 2449 // operator < 2450 /** 2451 * @brief Test if string precedes string. 2452 * @param __lhs First string. 2453 * @param __rhs Second string. 2454 * @return True if @a __lhs precedes @a __rhs. False otherwise. 2455 */ 2456 template<typename _CharT, typename _Traits, typename _Alloc, 2457 template <typename, typename, typename> class _Base> 2458 inline bool 2459 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2460 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2461 { return __lhs.compare(__rhs) < 0; } 2462 2463 /** 2464 * @brief Test if string precedes C string. 2465 * @param __lhs String. 2466 * @param __rhs C string. 2467 * @return True if @a __lhs precedes @a __rhs. False otherwise. 2468 */ 2469 template<typename _CharT, typename _Traits, typename _Alloc, 2470 template <typename, typename, typename> class _Base> 2471 inline bool 2472 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2473 const _CharT* __rhs) 2474 { return __lhs.compare(__rhs) < 0; } 2475 2476 /** 2477 * @brief Test if C string precedes string. 2478 * @param __lhs C string. 2479 * @param __rhs String. 2480 * @return True if @a __lhs precedes @a __rhs. False otherwise. 2481 */ 2482 template<typename _CharT, typename _Traits, typename _Alloc, 2483 template <typename, typename, typename> class _Base> 2484 inline bool 2485 operator<(const _CharT* __lhs, 2486 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2487 { return __rhs.compare(__lhs) > 0; } 2488 2489 // operator > 2490 /** 2491 * @brief Test if string follows string. 2492 * @param __lhs First string. 2493 * @param __rhs Second string. 2494 * @return True if @a __lhs follows @a __rhs. False otherwise. 2495 */ 2496 template<typename _CharT, typename _Traits, typename _Alloc, 2497 template <typename, typename, typename> class _Base> 2498 inline bool 2499 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2500 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2501 { return __lhs.compare(__rhs) > 0; } 2502 2503 /** 2504 * @brief Test if string follows C string. 2505 * @param __lhs String. 2506 * @param __rhs C string. 2507 * @return True if @a __lhs follows @a __rhs. False otherwise. 2508 */ 2509 template<typename _CharT, typename _Traits, typename _Alloc, 2510 template <typename, typename, typename> class _Base> 2511 inline bool 2512 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2513 const _CharT* __rhs) 2514 { return __lhs.compare(__rhs) > 0; } 2515 2516 /** 2517 * @brief Test if C string follows string. 2518 * @param __lhs C string. 2519 * @param __rhs String. 2520 * @return True if @a __lhs follows @a __rhs. False otherwise. 2521 */ 2522 template<typename _CharT, typename _Traits, typename _Alloc, 2523 template <typename, typename, typename> class _Base> 2524 inline bool 2525 operator>(const _CharT* __lhs, 2526 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2527 { return __rhs.compare(__lhs) < 0; } 2528 2529 // operator <= 2530 /** 2531 * @brief Test if string doesn't follow string. 2532 * @param __lhs First string. 2533 * @param __rhs Second string. 2534 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. 2535 */ 2536 template<typename _CharT, typename _Traits, typename _Alloc, 2537 template <typename, typename, typename> class _Base> 2538 inline bool 2539 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2540 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2541 { return __lhs.compare(__rhs) <= 0; } 2542 2543 /** 2544 * @brief Test if string doesn't follow C string. 2545 * @param __lhs String. 2546 * @param __rhs C string. 2547 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. 2548 */ 2549 template<typename _CharT, typename _Traits, typename _Alloc, 2550 template <typename, typename, typename> class _Base> 2551 inline bool 2552 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2553 const _CharT* __rhs) 2554 { return __lhs.compare(__rhs) <= 0; } 2555 2556 /** 2557 * @brief Test if C string doesn't follow string. 2558 * @param __lhs C string. 2559 * @param __rhs String. 2560 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. 2561 */ 2562 template<typename _CharT, typename _Traits, typename _Alloc, 2563 template <typename, typename, typename> class _Base> 2564 inline bool 2565 operator<=(const _CharT* __lhs, 2566 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2567 { return __rhs.compare(__lhs) >= 0; } 2568 2569 // operator >= 2570 /** 2571 * @brief Test if string doesn't precede string. 2572 * @param __lhs First string. 2573 * @param __rhs Second string. 2574 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. 2575 */ 2576 template<typename _CharT, typename _Traits, typename _Alloc, 2577 template <typename, typename, typename> class _Base> 2578 inline bool 2579 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2580 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2581 { return __lhs.compare(__rhs) >= 0; } 2582 2583 /** 2584 * @brief Test if string doesn't precede C string. 2585 * @param __lhs String. 2586 * @param __rhs C string. 2587 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. 2588 */ 2589 template<typename _CharT, typename _Traits, typename _Alloc, 2590 template <typename, typename, typename> class _Base> 2591 inline bool 2592 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2593 const _CharT* __rhs) 2594 { return __lhs.compare(__rhs) >= 0; } 2595 2596 /** 2597 * @brief Test if C string doesn't precede string. 2598 * @param __lhs C string. 2599 * @param __rhs String. 2600 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. 2601 */ 2602 template<typename _CharT, typename _Traits, typename _Alloc, 2603 template <typename, typename, typename> class _Base> 2604 inline bool 2605 operator>=(const _CharT* __lhs, 2606 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2607 { return __rhs.compare(__lhs) <= 0; } 2608 2609 /** 2610 * @brief Swap contents of two strings. 2611 * @param __lhs First string. 2612 * @param __rhs Second string. 2613 * 2614 * Exchanges the contents of @a __lhs and @a __rhs in constant time. 2615 */ 2616 template<typename _CharT, typename _Traits, typename _Alloc, 2617 template <typename, typename, typename> class _Base> 2618 inline void 2619 swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2620 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2621 { __lhs.swap(__rhs); } 2622 2623 _GLIBCXX_END_NAMESPACE_VERSION 2624 } // namespace 2625 2626 namespace std _GLIBCXX_VISIBILITY(default) 2627 { 2628 _GLIBCXX_BEGIN_NAMESPACE_VERSION 2629 2630 /** 2631 * @brief Read stream into a string. 2632 * @param __is Input stream. 2633 * @param __str Buffer to store into. 2634 * @return Reference to the input stream. 2635 * 2636 * Stores characters from @a __is into @a __str until whitespace is 2637 * found, the end of the stream is encountered, or str.max_size() 2638 * is reached. If is.width() is non-zero, that is the limit on the 2639 * number of characters stored into @a __str. Any previous 2640 * contents of @a __str are erased. 2641 */ 2642 template<typename _CharT, typename _Traits, typename _Alloc, 2643 template <typename, typename, typename> class _Base> 2644 basic_istream<_CharT, _Traits>& 2645 operator>>(basic_istream<_CharT, _Traits>& __is, 2646 __gnu_cxx::__versa_string<_CharT, _Traits, 2647 _Alloc, _Base>& __str); 2648 2649 /** 2650 * @brief Write string to a stream. 2651 * @param __os Output stream. 2652 * @param __str String to write out. 2653 * @return Reference to the output stream. 2654 * 2655 * Output characters of @a __str into os following the same rules as for 2656 * writing a C string. 2657 */ 2658 template<typename _CharT, typename _Traits, typename _Alloc, 2659 template <typename, typename, typename> class _Base> 2660 inline basic_ostream<_CharT, _Traits>& 2661 operator<<(basic_ostream<_CharT, _Traits>& __os, 2662 const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, 2663 _Base>& __str) 2664 { 2665 // _GLIBCXX_RESOLVE_LIB_DEFECTS 2666 // 586. string inserter not a formatted function 2667 return __ostream_insert(__os, __str.data(), __str.size()); 2668 } 2669 2670 /** 2671 * @brief Read a line from stream into a string. 2672 * @param __is Input stream. 2673 * @param __str Buffer to store into. 2674 * @param __delim Character marking end of line. 2675 * @return Reference to the input stream. 2676 * 2677 * Stores characters from @a __is into @a __str until @a __delim is 2678 * found, the end of the stream is encountered, or str.max_size() 2679 * is reached. If is.width() is non-zero, that is the limit on the 2680 * number of characters stored into @a __str. Any previous 2681 * contents of @a __str are erased. If @a delim was encountered, 2682 * it is extracted but not stored into @a __str. 2683 */ 2684 template<typename _CharT, typename _Traits, typename _Alloc, 2685 template <typename, typename, typename> class _Base> 2686 basic_istream<_CharT, _Traits>& 2687 getline(basic_istream<_CharT, _Traits>& __is, 2688 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str, 2689 _CharT __delim); 2690 2691 /** 2692 * @brief Read a line from stream into a string. 2693 * @param __is Input stream. 2694 * @param __str Buffer to store into. 2695 * @return Reference to the input stream. 2696 * 2697 * Stores characters from is into @a __str until '\n' is 2698 * found, the end of the stream is encountered, or str.max_size() 2699 * is reached. If is.width() is non-zero, that is the limit on the 2700 * number of characters stored into @a __str. Any previous 2701 * contents of @a __str are erased. If end of line was 2702 * encountered, it is extracted but not stored into @a __str. 2703 */ 2704 template<typename _CharT, typename _Traits, typename _Alloc, 2705 template <typename, typename, typename> class _Base> 2706 inline basic_istream<_CharT, _Traits>& 2707 getline(basic_istream<_CharT, _Traits>& __is, 2708 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str) 2709 { return getline(__is, __str, __is.widen('\n')); } 2710 2711 _GLIBCXX_END_NAMESPACE_VERSION 2712 } // namespace 2713 2714 #if ((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99)) 2715 2716 #include <ext/string_conversions.h> 2717 2718 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) 2719 { 2720 _GLIBCXX_BEGIN_NAMESPACE_VERSION 2721 2722 // 21.4 Numeric Conversions [string.conversions]. 2723 inline int 2724 stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) 2725 { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(), 2726 __idx, __base); } 2727 2728 inline long 2729 stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) 2730 { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(), 2731 __idx, __base); } 2732 2733 inline unsigned long 2734 stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) 2735 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(), 2736 __idx, __base); } 2737 2738 inline long long 2739 stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) 2740 { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(), 2741 __idx, __base); } 2742 2743 inline unsigned long long 2744 stoull(const __vstring& __str, std::size_t* __idx, int __base = 10) 2745 { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(), 2746 __idx, __base); } 2747 2748 // NB: strtof vs strtod. 2749 inline float 2750 stof(const __vstring& __str, std::size_t* __idx = 0) 2751 { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } 2752 2753 inline double 2754 stod(const __vstring& __str, std::size_t* __idx = 0) 2755 { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } 2756 2757 inline long double 2758 stold(const __vstring& __str, std::size_t* __idx = 0) 2759 { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } 2760 2761 // NB: (v)snprintf vs sprintf. 2762 2763 // DR 1261. 2764 inline __vstring 2765 to_string(int __val) 2766 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int), 2767 "%d", __val); } 2768 2769 inline __vstring 2770 to_string(unsigned __val) 2771 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 2772 4 * sizeof(unsigned), 2773 "%u", __val); } 2774 2775 inline __vstring 2776 to_string(long __val) 2777 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 2778 4 * sizeof(long), 2779 "%ld", __val); } 2780 2781 inline __vstring 2782 to_string(unsigned long __val) 2783 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 2784 4 * sizeof(unsigned long), 2785 "%lu", __val); } 2786 2787 2788 inline __vstring 2789 to_string(long long __val) 2790 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 2791 4 * sizeof(long long), 2792 "%lld", __val); } 2793 2794 inline __vstring 2795 to_string(unsigned long long __val) 2796 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 2797 4 * sizeof(unsigned long long), 2798 "%llu", __val); } 2799 2800 inline __vstring 2801 to_string(float __val) 2802 { 2803 const int __n = __numeric_traits<float>::__max_exponent10 + 20; 2804 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n, 2805 "%f", __val); 2806 } 2807 2808 inline __vstring 2809 to_string(double __val) 2810 { 2811 const int __n = __numeric_traits<double>::__max_exponent10 + 20; 2812 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n, 2813 "%f", __val); 2814 } 2815 2816 inline __vstring 2817 to_string(long double __val) 2818 { 2819 const int __n = __numeric_traits<long double>::__max_exponent10 + 20; 2820 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n, 2821 "%Lf", __val); 2822 } 2823 2824 #ifdef _GLIBCXX_USE_WCHAR_T 2825 inline int 2826 stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) 2827 { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(), 2828 __idx, __base); } 2829 2830 inline long 2831 stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) 2832 { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(), 2833 __idx, __base); } 2834 2835 inline unsigned long 2836 stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) 2837 { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(), 2838 __idx, __base); } 2839 2840 inline long long 2841 stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) 2842 { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(), 2843 __idx, __base); } 2844 2845 inline unsigned long long 2846 stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) 2847 { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(), 2848 __idx, __base); } 2849 2850 // NB: wcstof vs wcstod. 2851 inline float 2852 stof(const __wvstring& __str, std::size_t* __idx = 0) 2853 { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); } 2854 2855 inline double 2856 stod(const __wvstring& __str, std::size_t* __idx = 0) 2857 { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); } 2858 2859 inline long double 2860 stold(const __wvstring& __str, std::size_t* __idx = 0) 2861 { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); } 2862 2863 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF 2864 // DR 1261. 2865 inline __wvstring 2866 to_wstring(int __val) 2867 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 2868 4 * sizeof(int), 2869 L"%d", __val); } 2870 2871 inline __wvstring 2872 to_wstring(unsigned __val) 2873 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 2874 4 * sizeof(unsigned), 2875 L"%u", __val); } 2876 2877 inline __wvstring 2878 to_wstring(long __val) 2879 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 2880 4 * sizeof(long), 2881 L"%ld", __val); } 2882 2883 inline __wvstring 2884 to_wstring(unsigned long __val) 2885 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 2886 4 * sizeof(unsigned long), 2887 L"%lu", __val); } 2888 2889 inline __wvstring 2890 to_wstring(long long __val) 2891 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 2892 4 * sizeof(long long), 2893 L"%lld", __val); } 2894 2895 inline __wvstring 2896 to_wstring(unsigned long long __val) 2897 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 2898 4 * sizeof(unsigned long long), 2899 L"%llu", __val); } 2900 2901 inline __wvstring 2902 to_wstring(float __val) 2903 { 2904 const int __n = __numeric_traits<float>::__max_exponent10 + 20; 2905 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n, 2906 L"%f", __val); 2907 } 2908 2909 inline __wvstring 2910 to_wstring(double __val) 2911 { 2912 const int __n = __numeric_traits<double>::__max_exponent10 + 20; 2913 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n, 2914 L"%f", __val); 2915 } 2916 2917 inline __wvstring 2918 to_wstring(long double __val) 2919 { 2920 const int __n = __numeric_traits<long double>::__max_exponent10 + 20; 2921 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n, 2922 L"%Lf", __val); 2923 } 2924 #endif 2925 #endif 2926 2927 _GLIBCXX_END_NAMESPACE_VERSION 2928 } // namespace 2929 2930 #endif 2931 2932 #if __cplusplus >= 201103L 2933 2934 #include <bits/functional_hash.h> 2935 2936 namespace std _GLIBCXX_VISIBILITY(default) 2937 { 2938 _GLIBCXX_BEGIN_NAMESPACE_VERSION 2939 2940 /// std::hash specialization for __vstring. 2941 template<> 2942 struct hash<__gnu_cxx::__vstring> 2943 : public __hash_base<size_t, __gnu_cxx::__vstring> 2944 { 2945 size_t 2946 operator()(const __gnu_cxx::__vstring& __s) const noexcept 2947 { return std::_Hash_impl::hash(__s.data(), __s.length()); } 2948 }; 2949 2950 #ifdef _GLIBCXX_USE_WCHAR_T 2951 /// std::hash specialization for __wvstring. 2952 template<> 2953 struct hash<__gnu_cxx::__wvstring> 2954 : public __hash_base<size_t, __gnu_cxx::__wvstring> 2955 { 2956 size_t 2957 operator()(const __gnu_cxx::__wvstring& __s) const noexcept 2958 { return std::_Hash_impl::hash(__s.data(), 2959 __s.length() * sizeof(wchar_t)); } 2960 }; 2961 #endif 2962 2963 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 2964 /// std::hash specialization for __u16vstring. 2965 template<> 2966 struct hash<__gnu_cxx::__u16vstring> 2967 : public __hash_base<size_t, __gnu_cxx::__u16vstring> 2968 { 2969 size_t 2970 operator()(const __gnu_cxx::__u16vstring& __s) const noexcept 2971 { return std::_Hash_impl::hash(__s.data(), 2972 __s.length() * sizeof(char16_t)); } 2973 }; 2974 2975 /// std::hash specialization for __u32vstring. 2976 template<> 2977 struct hash<__gnu_cxx::__u32vstring> 2978 : public __hash_base<size_t, __gnu_cxx::__u32vstring> 2979 { 2980 size_t 2981 operator()(const __gnu_cxx::__u32vstring& __s) const noexcept 2982 { return std::_Hash_impl::hash(__s.data(), 2983 __s.length() * sizeof(char32_t)); } 2984 }; 2985 #endif 2986 2987 _GLIBCXX_END_NAMESPACE_VERSION 2988 } // namespace 2989 2990 #endif // C++11 2991 2992 #include "vstring.tcc" 2993 2994 #if __google_stl_debug_string && !defined(_GLIBCXX_DEBUG) 2995 // Undo our defines, so they don't affect anything else. 2996 # undef _GLIBCXX_DEBUG_ASSERT 2997 # undef _GLIBCXX_DEBUG_PEDASSERT 2998 # define _GLIBCXX_DEBUG_ASSERT(_Condition) 2999 # define _GLIBCXX_DEBUG_PEDASSERT(_Condition) 3000 #endif 3001 3002 #endif /* _VSTRING_H */ 3003