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