libstdc++
|
00001 // Versatile string -*- C++ -*- 00002 00003 // Copyright (C) 2005-2013 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file ext/vstring.h 00026 * This file is a GNU extension to the Standard C++ Library. 00027 */ 00028 00029 #ifndef _VSTRING_H 00030 #define _VSTRING_H 1 00031 00032 #pragma GCC system_header 00033 00034 #if __cplusplus >= 201103L 00035 #include <initializer_list> 00036 #endif 00037 00038 #include <ext/vstring_util.h> 00039 #include <ext/rc_string_base.h> 00040 #include <ext/sso_string_base.h> 00041 00042 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) 00043 { 00044 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00045 00046 /** 00047 * @class __versa_string vstring.h 00048 * @brief Template class __versa_string. 00049 * @ingroup extensions 00050 * 00051 * Data structure managing sequences of characters and 00052 * character-like objects. 00053 */ 00054 template<typename _CharT, typename _Traits, typename _Alloc, 00055 template <typename, typename, typename> class _Base> 00056 class __versa_string 00057 : private _Base<_CharT, _Traits, _Alloc> 00058 { 00059 typedef _Base<_CharT, _Traits, _Alloc> __vstring_base; 00060 typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type; 00061 00062 // Types: 00063 public: 00064 typedef _Traits traits_type; 00065 typedef typename _Traits::char_type value_type; 00066 typedef _Alloc allocator_type; 00067 typedef typename _CharT_alloc_type::size_type size_type; 00068 typedef typename _CharT_alloc_type::difference_type difference_type; 00069 typedef value_type& reference; 00070 typedef const value_type& const_reference; 00071 typedef typename _CharT_alloc_type::pointer pointer; 00072 typedef typename _CharT_alloc_type::const_pointer const_pointer; 00073 typedef __gnu_cxx::__normal_iterator<pointer, __versa_string> iterator; 00074 typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string> 00075 const_iterator; 00076 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 00077 typedef std::reverse_iterator<iterator> reverse_iterator; 00078 00079 // Data Member (public): 00080 /// Value returned by various member functions when they fail. 00081 static const size_type npos = static_cast<size_type>(-1); 00082 00083 private: 00084 size_type 00085 _M_check(size_type __pos, const char* __s) const 00086 { 00087 if (__pos > this->size()) 00088 std::__throw_out_of_range(__N(__s)); 00089 return __pos; 00090 } 00091 00092 void 00093 _M_check_length(size_type __n1, size_type __n2, const char* __s) const 00094 { 00095 if (this->max_size() - (this->size() - __n1) < __n2) 00096 std::__throw_length_error(__N(__s)); 00097 } 00098 00099 // NB: _M_limit doesn't check for a bad __pos value. 00100 size_type 00101 _M_limit(size_type __pos, size_type __off) const 00102 { 00103 const bool __testoff = __off < this->size() - __pos; 00104 return __testoff ? __off : this->size() - __pos; 00105 } 00106 00107 // True if _Rep and source do not overlap. 00108 bool 00109 _M_disjunct(const _CharT* __s) const 00110 { 00111 return (std::less<const _CharT*>()(__s, this->_M_data()) 00112 || std::less<const _CharT*>()(this->_M_data() 00113 + this->size(), __s)); 00114 } 00115 00116 // For the internal use we have functions similar to `begin'/`end' 00117 // but they do not call _M_leak. 00118 iterator 00119 _M_ibegin() const 00120 { return iterator(this->_M_data()); } 00121 00122 iterator 00123 _M_iend() const 00124 { return iterator(this->_M_data() + this->_M_length()); } 00125 00126 public: 00127 // Construct/copy/destroy: 00128 // NB: We overload ctors in some cases instead of using default 00129 // arguments, per 17.4.4.4 para. 2 item 2. 00130 00131 /** 00132 * @brief Default constructor creates an empty string. 00133 */ 00134 __versa_string() 00135 : __vstring_base() { } 00136 00137 /** 00138 * @brief Construct an empty string using allocator @a a. 00139 */ 00140 explicit 00141 __versa_string(const _Alloc& __a) 00142 : __vstring_base(__a) { } 00143 00144 // NB: per LWG issue 42, semantics different from IS: 00145 /** 00146 * @brief Construct string with copy of value of @a __str. 00147 * @param __str Source string. 00148 */ 00149 __versa_string(const __versa_string& __str) 00150 : __vstring_base(__str) { } 00151 00152 #if __cplusplus >= 201103L 00153 /** 00154 * @brief String move constructor. 00155 * @param __str Source string. 00156 * 00157 * The newly-constructed %string contains the exact contents of 00158 * @a __str. The contents of @a __str are a valid, but unspecified 00159 * string. 00160 */ 00161 __versa_string(__versa_string&& __str) noexcept 00162 : __vstring_base(std::move(__str)) { } 00163 00164 /** 00165 * @brief Construct string from an initializer list. 00166 * @param __l std::initializer_list of characters. 00167 * @param __a Allocator to use (default is default allocator). 00168 */ 00169 __versa_string(std::initializer_list<_CharT> __l, 00170 const _Alloc& __a = _Alloc()) 00171 : __vstring_base(__l.begin(), __l.end(), __a) { } 00172 #endif 00173 00174 /** 00175 * @brief Construct string as copy of a substring. 00176 * @param __str Source string. 00177 * @param __pos Index of first character to copy from. 00178 * @param __n Number of characters to copy (default remainder). 00179 */ 00180 __versa_string(const __versa_string& __str, size_type __pos, 00181 size_type __n = npos) 00182 : __vstring_base(__str._M_data() 00183 + __str._M_check(__pos, 00184 "__versa_string::__versa_string"), 00185 __str._M_data() + __str._M_limit(__pos, __n) 00186 + __pos, _Alloc()) { } 00187 00188 /** 00189 * @brief Construct string as copy of a substring. 00190 * @param __str Source string. 00191 * @param __pos Index of first character to copy from. 00192 * @param __n Number of characters to copy. 00193 * @param __a Allocator to use. 00194 */ 00195 __versa_string(const __versa_string& __str, size_type __pos, 00196 size_type __n, const _Alloc& __a) 00197 : __vstring_base(__str._M_data() 00198 + __str._M_check(__pos, 00199 "__versa_string::__versa_string"), 00200 __str._M_data() + __str._M_limit(__pos, __n) 00201 + __pos, __a) { } 00202 00203 /** 00204 * @brief Construct string initialized by a character array. 00205 * @param __s Source character array. 00206 * @param __n Number of characters to copy. 00207 * @param __a Allocator to use (default is default allocator). 00208 * 00209 * NB: @a __s must have at least @a __n characters, '\\0' has no special 00210 * meaning. 00211 */ 00212 __versa_string(const _CharT* __s, size_type __n, 00213 const _Alloc& __a = _Alloc()) 00214 : __vstring_base(__s, __s + __n, __a) { } 00215 00216 /** 00217 * @brief Construct string as copy of a C string. 00218 * @param __s Source C string. 00219 * @param __a Allocator to use (default is default allocator). 00220 */ 00221 __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc()) 00222 : __vstring_base(__s, __s ? __s + traits_type::length(__s) : 00223 __s + npos, __a) { } 00224 00225 /** 00226 * @brief Construct string as multiple characters. 00227 * @param __n Number of characters. 00228 * @param __c Character to use. 00229 * @param __a Allocator to use (default is default allocator). 00230 */ 00231 __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()) 00232 : __vstring_base(__n, __c, __a) { } 00233 00234 /** 00235 * @brief Construct string as copy of a range. 00236 * @param __beg Start of range. 00237 * @param __end End of range. 00238 * @param __a Allocator to use (default is default allocator). 00239 */ 00240 #if __cplusplus >= 201103L 00241 template<class _InputIterator, 00242 typename = std::_RequireInputIter<_InputIterator>> 00243 #else 00244 template<class _InputIterator> 00245 #endif 00246 __versa_string(_InputIterator __beg, _InputIterator __end, 00247 const _Alloc& __a = _Alloc()) 00248 : __vstring_base(__beg, __end, __a) { } 00249 00250 /** 00251 * @brief Destroy the string instance. 00252 */ 00253 ~__versa_string() _GLIBCXX_NOEXCEPT { } 00254 00255 /** 00256 * @brief Assign the value of @a str to this string. 00257 * @param __str Source string. 00258 */ 00259 __versa_string& 00260 operator=(const __versa_string& __str) 00261 { return this->assign(__str); } 00262 00263 #if __cplusplus >= 201103L 00264 /** 00265 * @brief String move assignment operator. 00266 * @param __str Source string. 00267 * 00268 * The contents of @a __str are moved into this string (without 00269 * copying). @a __str is a valid, but unspecified string. 00270 */ 00271 __versa_string& 00272 operator=(__versa_string&& __str) 00273 { 00274 // NB: DR 1204. 00275 this->swap(__str); 00276 return *this; 00277 } 00278 00279 /** 00280 * @brief Set value to string constructed from initializer list. 00281 * @param __l std::initializer_list. 00282 */ 00283 __versa_string& 00284 operator=(std::initializer_list<_CharT> __l) 00285 { 00286 this->assign(__l.begin(), __l.end()); 00287 return *this; 00288 } 00289 #endif 00290 00291 /** 00292 * @brief Copy contents of @a __s into this string. 00293 * @param __s Source null-terminated string. 00294 */ 00295 __versa_string& 00296 operator=(const _CharT* __s) 00297 { return this->assign(__s); } 00298 00299 /** 00300 * @brief Set value to string of length 1. 00301 * @param __c Source character. 00302 * 00303 * Assigning to a character makes this string length 1 and 00304 * (*this)[0] == @a __c. 00305 */ 00306 __versa_string& 00307 operator=(_CharT __c) 00308 { 00309 this->assign(1, __c); 00310 return *this; 00311 } 00312 00313 // Iterators: 00314 /** 00315 * Returns a read/write iterator that points to the first character in 00316 * the %string. Unshares the string. 00317 */ 00318 iterator 00319 begin() _GLIBCXX_NOEXCEPT 00320 { 00321 this->_M_leak(); 00322 return iterator(this->_M_data()); 00323 } 00324 00325 /** 00326 * Returns a read-only (constant) iterator that points to the first 00327 * character in the %string. 00328 */ 00329 const_iterator 00330 begin() const _GLIBCXX_NOEXCEPT 00331 { return const_iterator(this->_M_data()); } 00332 00333 /** 00334 * Returns a read/write iterator that points one past the last 00335 * character in the %string. Unshares the string. 00336 */ 00337 iterator 00338 end() _GLIBCXX_NOEXCEPT 00339 { 00340 this->_M_leak(); 00341 return iterator(this->_M_data() + this->size()); 00342 } 00343 00344 /** 00345 * Returns a read-only (constant) iterator that points one past the 00346 * last character in the %string. 00347 */ 00348 const_iterator 00349 end() const _GLIBCXX_NOEXCEPT 00350 { return const_iterator(this->_M_data() + this->size()); } 00351 00352 /** 00353 * Returns a read/write reverse iterator that points to the last 00354 * character in the %string. Iteration is done in reverse element 00355 * order. Unshares the string. 00356 */ 00357 reverse_iterator 00358 rbegin() _GLIBCXX_NOEXCEPT 00359 { return reverse_iterator(this->end()); } 00360 00361 /** 00362 * Returns a read-only (constant) reverse iterator that points 00363 * to the last character in the %string. Iteration is done in 00364 * reverse element order. 00365 */ 00366 const_reverse_iterator 00367 rbegin() const _GLIBCXX_NOEXCEPT 00368 { return const_reverse_iterator(this->end()); } 00369 00370 /** 00371 * Returns a read/write reverse iterator that points to one before the 00372 * first character in the %string. Iteration is done in reverse 00373 * element order. Unshares the string. 00374 */ 00375 reverse_iterator 00376 rend() _GLIBCXX_NOEXCEPT 00377 { return reverse_iterator(this->begin()); } 00378 00379 /** 00380 * Returns a read-only (constant) reverse iterator that points 00381 * to one before the first character in the %string. Iteration 00382 * is done in reverse element order. 00383 */ 00384 const_reverse_iterator 00385 rend() const _GLIBCXX_NOEXCEPT 00386 { return const_reverse_iterator(this->begin()); } 00387 00388 #if __cplusplus >= 201103L 00389 /** 00390 * Returns a read-only (constant) iterator that points to the first 00391 * character in the %string. 00392 */ 00393 const_iterator 00394 cbegin() const noexcept 00395 { return const_iterator(this->_M_data()); } 00396 00397 /** 00398 * Returns a read-only (constant) iterator that points one past the 00399 * last character in the %string. 00400 */ 00401 const_iterator 00402 cend() const noexcept 00403 { return const_iterator(this->_M_data() + this->size()); } 00404 00405 /** 00406 * Returns a read-only (constant) reverse iterator that points 00407 * to the last character in the %string. Iteration is done in 00408 * reverse element order. 00409 */ 00410 const_reverse_iterator 00411 crbegin() const noexcept 00412 { return const_reverse_iterator(this->end()); } 00413 00414 /** 00415 * Returns a read-only (constant) reverse iterator that points 00416 * to one before the first character in the %string. Iteration 00417 * is done in reverse element order. 00418 */ 00419 const_reverse_iterator 00420 crend() const noexcept 00421 { return const_reverse_iterator(this->begin()); } 00422 #endif 00423 00424 public: 00425 // Capacity: 00426 /// Returns the number of characters in the string, not including any 00427 /// null-termination. 00428 size_type 00429 size() const _GLIBCXX_NOEXCEPT 00430 { return this->_M_length(); } 00431 00432 /// Returns the number of characters in the string, not including any 00433 /// null-termination. 00434 size_type 00435 length() const _GLIBCXX_NOEXCEPT 00436 { return this->_M_length(); } 00437 00438 /// Returns the size() of the largest possible %string. 00439 size_type 00440 max_size() const _GLIBCXX_NOEXCEPT 00441 { return this->_M_max_size(); } 00442 00443 /** 00444 * @brief Resizes the %string to the specified number of characters. 00445 * @param __n Number of characters the %string should contain. 00446 * @param __c Character to fill any new elements. 00447 * 00448 * This function will %resize the %string to the specified 00449 * number of characters. If the number is smaller than the 00450 * %string's current size the %string is truncated, otherwise 00451 * the %string is extended and new elements are set to @a __c. 00452 */ 00453 void 00454 resize(size_type __n, _CharT __c); 00455 00456 /** 00457 * @brief Resizes the %string to the specified number of characters. 00458 * @param __n Number of characters the %string should contain. 00459 * 00460 * This function will resize the %string to the specified 00461 * length. If the new size is smaller than the %string's 00462 * current size the %string is truncated, otherwise the %string 00463 * is extended and new characters are default-constructed. For 00464 * basic types such as char, this means setting them to 0. 00465 */ 00466 void 00467 resize(size_type __n) 00468 { this->resize(__n, _CharT()); } 00469 00470 #if __cplusplus >= 201103L 00471 /// A non-binding request to reduce capacity() to size(). 00472 void 00473 shrink_to_fit() 00474 { 00475 if (capacity() > size()) 00476 { 00477 __try 00478 { this->reserve(0); } 00479 __catch(...) 00480 { } 00481 } 00482 } 00483 #endif 00484 00485 /** 00486 * Returns the total number of characters that the %string can 00487 * hold before needing to allocate more memory. 00488 */ 00489 size_type 00490 capacity() const _GLIBCXX_NOEXCEPT 00491 { return this->_M_capacity(); } 00492 00493 /** 00494 * @brief Attempt to preallocate enough memory for specified number of 00495 * characters. 00496 * @param __res_arg Number of characters required. 00497 * @throw std::length_error If @a __res_arg exceeds @c max_size(). 00498 * 00499 * This function attempts to reserve enough memory for the 00500 * %string to hold the specified number of characters. If the 00501 * number requested is more than max_size(), length_error is 00502 * thrown. 00503 * 00504 * The advantage of this function is that if optimal code is a 00505 * necessity and the user can determine the string length that 00506 * will be required, the user can reserve the memory in 00507 * %advance, and thus prevent a possible reallocation of memory 00508 * and copying of %string data. 00509 */ 00510 void 00511 reserve(size_type __res_arg = 0) 00512 { this->_M_reserve(__res_arg); } 00513 00514 /** 00515 * Erases the string, making it empty. 00516 */ 00517 void 00518 clear() _GLIBCXX_NOEXCEPT 00519 { this->_M_clear(); } 00520 00521 /** 00522 * Returns true if the %string is empty. Equivalent to 00523 * <code>*this == ""</code>. 00524 */ 00525 bool 00526 empty() const _GLIBCXX_NOEXCEPT 00527 { return this->size() == 0; } 00528 00529 // Element access: 00530 /** 00531 * @brief Subscript access to the data contained in the %string. 00532 * @param __pos The index of the character to access. 00533 * @return Read-only (constant) reference to the character. 00534 * 00535 * This operator allows for easy, array-style, data access. 00536 * Note that data access with this operator is unchecked and 00537 * out_of_range lookups are not defined. (For checked lookups 00538 * see at().) 00539 */ 00540 const_reference 00541 operator[] (size_type __pos) const 00542 { 00543 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size()); 00544 return this->_M_data()[__pos]; 00545 } 00546 00547 /** 00548 * @brief Subscript access to the data contained in the %string. 00549 * @param __pos The index of the character to access. 00550 * @return Read/write reference to the character. 00551 * 00552 * This operator allows for easy, array-style, data access. 00553 * Note that data access with this operator is unchecked and 00554 * out_of_range lookups are not defined. (For checked lookups 00555 * see at().) Unshares the string. 00556 */ 00557 reference 00558 operator[](size_type __pos) 00559 { 00560 // allow pos == size() as v3 extension: 00561 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size()); 00562 // but be strict in pedantic mode: 00563 _GLIBCXX_DEBUG_PEDASSERT(__pos < this->size()); 00564 this->_M_leak(); 00565 return this->_M_data()[__pos]; 00566 } 00567 00568 /** 00569 * @brief Provides access to the data contained in the %string. 00570 * @param __n The index of the character to access. 00571 * @return Read-only (const) reference to the character. 00572 * @throw std::out_of_range If @a __n is an invalid index. 00573 * 00574 * This function provides for safer data access. The parameter 00575 * is first checked that it is in the range of the string. The 00576 * function throws out_of_range if the check fails. 00577 */ 00578 const_reference 00579 at(size_type __n) const 00580 { 00581 if (__n >= this->size()) 00582 std::__throw_out_of_range(__N("__versa_string::at")); 00583 return this->_M_data()[__n]; 00584 } 00585 00586 /** 00587 * @brief Provides access to the data contained in the %string. 00588 * @param __n The index of the character to access. 00589 * @return Read/write reference to the character. 00590 * @throw std::out_of_range If @a __n is an invalid index. 00591 * 00592 * This function provides for safer data access. The parameter 00593 * is first checked that it is in the range of the string. The 00594 * function throws out_of_range if the check fails. Success 00595 * results in unsharing the string. 00596 */ 00597 reference 00598 at(size_type __n) 00599 { 00600 if (__n >= this->size()) 00601 std::__throw_out_of_range(__N("__versa_string::at")); 00602 this->_M_leak(); 00603 return this->_M_data()[__n]; 00604 } 00605 00606 #if __cplusplus >= 201103L 00607 /** 00608 * Returns a read/write reference to the data at the first 00609 * element of the %string. 00610 */ 00611 reference 00612 front() 00613 { return operator[](0); } 00614 00615 /** 00616 * Returns a read-only (constant) reference to the data at the first 00617 * element of the %string. 00618 */ 00619 const_reference 00620 front() const 00621 { return operator[](0); } 00622 00623 /** 00624 * Returns a read/write reference to the data at the last 00625 * element of the %string. 00626 */ 00627 reference 00628 back() 00629 { return operator[](this->size() - 1); } 00630 00631 /** 00632 * Returns a read-only (constant) reference to the data at the 00633 * last element of the %string. 00634 */ 00635 const_reference 00636 back() const 00637 { return operator[](this->size() - 1); } 00638 #endif 00639 00640 // Modifiers: 00641 /** 00642 * @brief Append a string to this string. 00643 * @param __str The string to append. 00644 * @return Reference to this string. 00645 */ 00646 __versa_string& 00647 operator+=(const __versa_string& __str) 00648 { return this->append(__str); } 00649 00650 /** 00651 * @brief Append a C string. 00652 * @param __s The C string to append. 00653 * @return Reference to this string. 00654 */ 00655 __versa_string& 00656 operator+=(const _CharT* __s) 00657 { return this->append(__s); } 00658 00659 /** 00660 * @brief Append a character. 00661 * @param __c The character to append. 00662 * @return Reference to this string. 00663 */ 00664 __versa_string& 00665 operator+=(_CharT __c) 00666 { 00667 this->push_back(__c); 00668 return *this; 00669 } 00670 00671 #if __cplusplus >= 201103L 00672 /** 00673 * @brief Append an initializer_list of characters. 00674 * @param __l The initializer_list of characters to be appended. 00675 * @return Reference to this string. 00676 */ 00677 __versa_string& 00678 operator+=(std::initializer_list<_CharT> __l) 00679 { return this->append(__l.begin(), __l.end()); } 00680 #endif // C++11 00681 00682 /** 00683 * @brief Append a string to this string. 00684 * @param __str The string to append. 00685 * @return Reference to this string. 00686 */ 00687 __versa_string& 00688 append(const __versa_string& __str) 00689 { return _M_append(__str._M_data(), __str.size()); } 00690 00691 /** 00692 * @brief Append a substring. 00693 * @param __str The string to append. 00694 * @param __pos Index of the first character of str to append. 00695 * @param __n The number of characters to append. 00696 * @return Reference to this string. 00697 * @throw std::out_of_range if @a pos is not a valid index. 00698 * 00699 * This function appends @a __n characters from @a __str 00700 * starting at @a __pos to this string. If @a __n is is larger 00701 * than the number of available characters in @a __str, the 00702 * remainder of @a __str is appended. 00703 */ 00704 __versa_string& 00705 append(const __versa_string& __str, size_type __pos, size_type __n) 00706 { return _M_append(__str._M_data() 00707 + __str._M_check(__pos, "__versa_string::append"), 00708 __str._M_limit(__pos, __n)); } 00709 00710 /** 00711 * @brief Append a C substring. 00712 * @param __s The C string to append. 00713 * @param __n The number of characters to append. 00714 * @return Reference to this string. 00715 */ 00716 __versa_string& 00717 append(const _CharT* __s, size_type __n) 00718 { 00719 __glibcxx_requires_string_len(__s, __n); 00720 _M_check_length(size_type(0), __n, "__versa_string::append"); 00721 return _M_append(__s, __n); 00722 } 00723 00724 /** 00725 * @brief Append a C string. 00726 * @param __s The C string to append. 00727 * @return Reference to this string. 00728 */ 00729 __versa_string& 00730 append(const _CharT* __s) 00731 { 00732 __glibcxx_requires_string(__s); 00733 const size_type __n = traits_type::length(__s); 00734 _M_check_length(size_type(0), __n, "__versa_string::append"); 00735 return _M_append(__s, __n); 00736 } 00737 00738 /** 00739 * @brief Append multiple characters. 00740 * @param __n The number of characters to append. 00741 * @param __c The character to use. 00742 * @return Reference to this string. 00743 * 00744 * Appends n copies of c to this string. 00745 */ 00746 __versa_string& 00747 append(size_type __n, _CharT __c) 00748 { return _M_replace_aux(this->size(), size_type(0), __n, __c); } 00749 00750 #if __cplusplus >= 201103L 00751 /** 00752 * @brief Append an initializer_list of characters. 00753 * @param __l The initializer_list of characters to append. 00754 * @return Reference to this string. 00755 */ 00756 __versa_string& 00757 append(std::initializer_list<_CharT> __l) 00758 { return this->append(__l.begin(), __l.end()); } 00759 #endif // C++11 00760 00761 /** 00762 * @brief Append a range of characters. 00763 * @param __first Iterator referencing the first character to append. 00764 * @param __last Iterator marking the end of the range. 00765 * @return Reference to this string. 00766 * 00767 * Appends characters in the range [first,last) to this string. 00768 */ 00769 #if __cplusplus >= 201103L 00770 template<class _InputIterator, 00771 typename = std::_RequireInputIter<_InputIterator>> 00772 #else 00773 template<class _InputIterator> 00774 #endif 00775 __versa_string& 00776 append(_InputIterator __first, _InputIterator __last) 00777 { return this->replace(_M_iend(), _M_iend(), __first, __last); } 00778 00779 /** 00780 * @brief Append a single character. 00781 * @param __c Character to append. 00782 */ 00783 void 00784 push_back(_CharT __c) 00785 { 00786 const size_type __size = this->size(); 00787 if (__size + 1 > this->capacity() || this->_M_is_shared()) 00788 this->_M_mutate(__size, size_type(0), 0, size_type(1)); 00789 traits_type::assign(this->_M_data()[__size], __c); 00790 this->_M_set_length(__size + 1); 00791 } 00792 00793 /** 00794 * @brief Set value to contents of another string. 00795 * @param __str Source string to use. 00796 * @return Reference to this string. 00797 */ 00798 __versa_string& 00799 assign(const __versa_string& __str) 00800 { 00801 this->_M_assign(__str); 00802 return *this; 00803 } 00804 00805 #if __cplusplus >= 201103L 00806 /** 00807 * @brief Set value to contents of another string. 00808 * @param __str Source string to use. 00809 * @return Reference to this string. 00810 * 00811 * This function sets this string to the exact contents of @a __str. 00812 * @a __str is a valid, but unspecified string. 00813 */ 00814 __versa_string& 00815 assign(__versa_string&& __str) 00816 { 00817 this->swap(__str); 00818 return *this; 00819 } 00820 #endif // C++11 00821 00822 /** 00823 * @brief Set value to a substring of a string. 00824 * @param __str The string to use. 00825 * @param __pos Index of the first character of str. 00826 * @param __n Number of characters to use. 00827 * @return Reference to this string. 00828 * @throw std::out_of_range if @a __pos is not a valid index. 00829 * 00830 * This function sets this string to the substring of @a __str 00831 * consisting of @a __n characters at @a __pos. If @a __n is 00832 * is larger than the number of available characters in @a 00833 * __str, the remainder of @a __str is used. 00834 */ 00835 __versa_string& 00836 assign(const __versa_string& __str, size_type __pos, size_type __n) 00837 { return _M_replace(size_type(0), this->size(), __str._M_data() 00838 + __str._M_check(__pos, "__versa_string::assign"), 00839 __str._M_limit(__pos, __n)); } 00840 00841 /** 00842 * @brief Set value to a C substring. 00843 * @param __s The C string to use. 00844 * @param __n Number of characters to use. 00845 * @return Reference to this string. 00846 * 00847 * This function sets the value of this string to the first @a 00848 * __n characters of @a __s. If @a __n is is larger than the 00849 * number of available characters in @a __s, the remainder of 00850 * @a __s is used. 00851 */ 00852 __versa_string& 00853 assign(const _CharT* __s, size_type __n) 00854 { 00855 __glibcxx_requires_string_len(__s, __n); 00856 return _M_replace(size_type(0), this->size(), __s, __n); 00857 } 00858 00859 /** 00860 * @brief Set value to contents of a C string. 00861 * @param __s The C string to use. 00862 * @return Reference to this string. 00863 * 00864 * This function sets the value of this string to the value of 00865 * @a __s. The data is copied, so there is no dependence on @a 00866 * __s once the function returns. 00867 */ 00868 __versa_string& 00869 assign(const _CharT* __s) 00870 { 00871 __glibcxx_requires_string(__s); 00872 return _M_replace(size_type(0), this->size(), __s, 00873 traits_type::length(__s)); 00874 } 00875 00876 /** 00877 * @brief Set value to multiple characters. 00878 * @param __n Length of the resulting string. 00879 * @param __c The character to use. 00880 * @return Reference to this string. 00881 * 00882 * This function sets the value of this string to @a __n copies of 00883 * character @a __c. 00884 */ 00885 __versa_string& 00886 assign(size_type __n, _CharT __c) 00887 { return _M_replace_aux(size_type(0), this->size(), __n, __c); } 00888 00889 /** 00890 * @brief Set value to a range of characters. 00891 * @param __first Iterator referencing the first character to append. 00892 * @param __last Iterator marking the end of the range. 00893 * @return Reference to this string. 00894 * 00895 * Sets value of string to characters in the range 00896 * [first,last). 00897 */ 00898 #if __cplusplus >= 201103L 00899 template<class _InputIterator, 00900 typename = std::_RequireInputIter<_InputIterator>> 00901 #else 00902 template<class _InputIterator> 00903 #endif 00904 __versa_string& 00905 assign(_InputIterator __first, _InputIterator __last) 00906 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); } 00907 00908 #if __cplusplus >= 201103L 00909 /** 00910 * @brief Set value to an initializer_list of characters. 00911 * @param __l The initializer_list of characters to assign. 00912 * @return Reference to this string. 00913 */ 00914 __versa_string& 00915 assign(std::initializer_list<_CharT> __l) 00916 { return this->assign(__l.begin(), __l.end()); } 00917 #endif // C++11 00918 00919 /** 00920 * @brief Insert multiple characters. 00921 * @param __p Iterator referencing location in string to insert at. 00922 * @param __n Number of characters to insert 00923 * @param __c The character to insert. 00924 * @throw std::length_error If new length exceeds @c max_size(). 00925 * 00926 * Inserts @a __n copies of character @a __c starting at the 00927 * position referenced by iterator @a __p. If adding 00928 * characters causes the length to exceed max_size(), 00929 * length_error is thrown. The value of the string doesn't 00930 * change if an error is thrown. 00931 */ 00932 void 00933 insert(iterator __p, size_type __n, _CharT __c) 00934 { this->replace(__p, __p, __n, __c); } 00935 00936 /** 00937 * @brief Insert a range of characters. 00938 * @param __p Iterator referencing location in string to insert at. 00939 * @param __beg Start of range. 00940 * @param __end End of range. 00941 * @throw std::length_error If new length exceeds @c max_size(). 00942 * 00943 * Inserts characters in range [beg,end). If adding characters 00944 * causes the length to exceed max_size(), length_error is 00945 * thrown. The value of the string doesn't change if an error 00946 * is thrown. 00947 */ 00948 #if __cplusplus >= 201103L 00949 template<class _InputIterator, 00950 typename = std::_RequireInputIter<_InputIterator>> 00951 #else 00952 template<class _InputIterator> 00953 #endif 00954 void 00955 insert(iterator __p, _InputIterator __beg, _InputIterator __end) 00956 { this->replace(__p, __p, __beg, __end); } 00957 00958 #if __cplusplus >= 201103L 00959 /** 00960 * @brief Insert an initializer_list of characters. 00961 * @param __p Iterator referencing location in string to insert at. 00962 * @param __l The initializer_list of characters to insert. 00963 * @throw std::length_error If new length exceeds @c max_size(). 00964 */ 00965 void 00966 insert(iterator __p, std::initializer_list<_CharT> __l) 00967 { this->insert(__p, __l.begin(), __l.end()); } 00968 #endif // C++11 00969 00970 /** 00971 * @brief Insert value of a string. 00972 * @param __pos1 Iterator referencing location in string to insert at. 00973 * @param __str The string to insert. 00974 * @return Reference to this string. 00975 * @throw std::length_error If new length exceeds @c max_size(). 00976 * 00977 * Inserts value of @a __str starting at @a __pos1. If adding 00978 * characters causes the length to exceed max_size(), 00979 * length_error is thrown. The value of the string doesn't 00980 * change if an error is thrown. 00981 */ 00982 __versa_string& 00983 insert(size_type __pos1, const __versa_string& __str) 00984 { return this->replace(__pos1, size_type(0), 00985 __str._M_data(), __str.size()); } 00986 00987 /** 00988 * @brief Insert a substring. 00989 * @param __pos1 Iterator referencing location in string to insert at. 00990 * @param __str The string to insert. 00991 * @param __pos2 Start of characters in str to insert. 00992 * @param __n Number of characters to insert. 00993 * @return Reference to this string. 00994 * @throw std::length_error If new length exceeds @c max_size(). 00995 * @throw std::out_of_range If @a __pos1 > size() or 00996 * @a __pos2 > @a __str.size(). 00997 * 00998 * Starting at @a __pos1, insert @a __n character of @a __str 00999 * beginning with @a __pos2. If adding characters causes the 01000 * length to exceed max_size(), length_error is thrown. If @a 01001 * __pos1 is beyond the end of this string or @a __pos2 is 01002 * beyond the end of @a __str, out_of_range is thrown. The 01003 * value of the string doesn't change if an error is thrown. 01004 */ 01005 __versa_string& 01006 insert(size_type __pos1, const __versa_string& __str, 01007 size_type __pos2, size_type __n) 01008 { return this->replace(__pos1, size_type(0), __str._M_data() 01009 + __str._M_check(__pos2, "__versa_string::insert"), 01010 __str._M_limit(__pos2, __n)); } 01011 01012 /** 01013 * @brief Insert a C substring. 01014 * @param __pos Iterator referencing location in string to insert at. 01015 * @param __s The C string to insert. 01016 * @param __n The number of characters to insert. 01017 * @return Reference to this string. 01018 * @throw std::length_error If new length exceeds @c max_size(). 01019 * @throw std::out_of_range If @a __pos is beyond the end of this 01020 * string. 01021 * 01022 * Inserts the first @a __n characters of @a __s starting at @a 01023 * __pos. If adding characters causes the length to exceed 01024 * max_size(), length_error is thrown. If @a __pos is beyond 01025 * end(), out_of_range is thrown. The value of the string 01026 * doesn't change if an error is thrown. 01027 */ 01028 __versa_string& 01029 insert(size_type __pos, const _CharT* __s, size_type __n) 01030 { return this->replace(__pos, size_type(0), __s, __n); } 01031 01032 /** 01033 * @brief Insert a C string. 01034 * @param __pos Iterator referencing location in string to insert at. 01035 * @param __s The C string to insert. 01036 * @return Reference to this string. 01037 * @throw std::length_error If new length exceeds @c max_size(). 01038 * @throw std::out_of_range If @a __pos is beyond the end of this 01039 * string. 01040 * 01041 * Inserts the first @a __n characters of @a __s starting at @a 01042 * __pos. If adding characters causes the length to exceed 01043 * max_size(), length_error is thrown. If @a __pos is beyond 01044 * end(), out_of_range is thrown. The value of the string 01045 * doesn't change if an error is thrown. 01046 */ 01047 __versa_string& 01048 insert(size_type __pos, const _CharT* __s) 01049 { 01050 __glibcxx_requires_string(__s); 01051 return this->replace(__pos, size_type(0), __s, 01052 traits_type::length(__s)); 01053 } 01054 01055 /** 01056 * @brief Insert multiple characters. 01057 * @param __pos Index in string to insert at. 01058 * @param __n Number of characters to insert 01059 * @param __c The character to insert. 01060 * @return Reference to this string. 01061 * @throw std::length_error If new length exceeds @c max_size(). 01062 * @throw std::out_of_range If @a __pos is beyond the end of this 01063 * string. 01064 * 01065 * Inserts @a __n copies of character @a __c starting at index 01066 * @a __pos. If adding characters causes the length to exceed 01067 * max_size(), length_error is thrown. If @a __pos > length(), 01068 * out_of_range is thrown. The value of the string doesn't 01069 * change if an error is thrown. 01070 */ 01071 __versa_string& 01072 insert(size_type __pos, size_type __n, _CharT __c) 01073 { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"), 01074 size_type(0), __n, __c); } 01075 01076 /** 01077 * @brief Insert one character. 01078 * @param __p Iterator referencing position in string to insert at. 01079 * @param __c The character to insert. 01080 * @return Iterator referencing newly inserted char. 01081 * @throw std::length_error If new length exceeds @c max_size(). 01082 * 01083 * Inserts character @a __c at position referenced by @a __p. 01084 * If adding character causes the length to exceed max_size(), 01085 * length_error is thrown. If @a __p is beyond end of string, 01086 * out_of_range is thrown. The value of the string doesn't 01087 * change if an error is thrown. 01088 */ 01089 iterator 01090 insert(iterator __p, _CharT __c) 01091 { 01092 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); 01093 const size_type __pos = __p - _M_ibegin(); 01094 _M_replace_aux(__pos, size_type(0), size_type(1), __c); 01095 this->_M_set_leaked(); 01096 return iterator(this->_M_data() + __pos); 01097 } 01098 01099 /** 01100 * @brief Remove characters. 01101 * @param __pos Index of first character to remove (default 0). 01102 * @param __n Number of characters to remove (default remainder). 01103 * @return Reference to this string. 01104 * @throw std::out_of_range If @a __pos is beyond the end of this 01105 * string. 01106 * 01107 * Removes @a __n characters from this string starting at @a 01108 * __pos. The length of the string is reduced by @a __n. If 01109 * there are < @a __n characters to remove, the remainder of 01110 * the string is truncated. If @a __p is beyond end of string, 01111 * out_of_range is thrown. The value of the string doesn't 01112 * change if an error is thrown. 01113 */ 01114 __versa_string& 01115 erase(size_type __pos = 0, size_type __n = npos) 01116 { 01117 this->_M_erase(_M_check(__pos, "__versa_string::erase"), 01118 _M_limit(__pos, __n)); 01119 return *this; 01120 } 01121 01122 /** 01123 * @brief Remove one character. 01124 * @param __position Iterator referencing the character to remove. 01125 * @return iterator referencing same location after removal. 01126 * 01127 * Removes the character at @a __position from this string. The 01128 * value of the string doesn't change if an error is thrown. 01129 */ 01130 iterator 01131 erase(iterator __position) 01132 { 01133 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin() 01134 && __position < _M_iend()); 01135 const size_type __pos = __position - _M_ibegin(); 01136 this->_M_erase(__pos, size_type(1)); 01137 this->_M_set_leaked(); 01138 return iterator(this->_M_data() + __pos); 01139 } 01140 01141 /** 01142 * @brief Remove a range of characters. 01143 * @param __first Iterator referencing the first character to remove. 01144 * @param __last Iterator referencing the end of the range. 01145 * @return Iterator referencing location of first after removal. 01146 * 01147 * Removes the characters in the range [first,last) from this 01148 * string. The value of the string doesn't change if an error 01149 * is thrown. 01150 */ 01151 iterator 01152 erase(iterator __first, iterator __last) 01153 { 01154 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last 01155 && __last <= _M_iend()); 01156 const size_type __pos = __first - _M_ibegin(); 01157 this->_M_erase(__pos, __last - __first); 01158 this->_M_set_leaked(); 01159 return iterator(this->_M_data() + __pos); 01160 } 01161 01162 #if __cplusplus >= 201103L 01163 /** 01164 * @brief Remove the last character. 01165 * 01166 * The string must be non-empty. 01167 */ 01168 void 01169 pop_back() 01170 { this->_M_erase(size()-1, 1); } 01171 #endif // C++11 01172 01173 /** 01174 * @brief Replace characters with value from another string. 01175 * @param __pos Index of first character to replace. 01176 * @param __n Number of characters to be replaced. 01177 * @param __str String to insert. 01178 * @return Reference to this string. 01179 * @throw std::out_of_range If @a __pos is beyond the end of this 01180 * string. 01181 * @throw std::length_error If new length exceeds @c max_size(). 01182 * 01183 * Removes the characters in the range [pos,pos+n) from this 01184 * string. In place, the value of @a __str is inserted. If @a 01185 * __pos is beyond end of string, out_of_range is thrown. If 01186 * the length of the result exceeds max_size(), length_error is 01187 * thrown. The value of the string doesn't change if an error 01188 * is thrown. 01189 */ 01190 __versa_string& 01191 replace(size_type __pos, size_type __n, const __versa_string& __str) 01192 { return this->replace(__pos, __n, __str._M_data(), __str.size()); } 01193 01194 /** 01195 * @brief Replace characters with value from another string. 01196 * @param __pos1 Index of first character to replace. 01197 * @param __n1 Number of characters to be replaced. 01198 * @param __str String to insert. 01199 * @param __pos2 Index of first character of str to use. 01200 * @param __n2 Number of characters from str to use. 01201 * @return Reference to this string. 01202 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 > 01203 * str.size(). 01204 * @throw std::length_error If new length exceeds @c max_size(). 01205 * 01206 * Removes the characters in the range [pos1,pos1 + n) from 01207 * this string. In place, the value of @a __str is inserted. 01208 * If @a __pos is beyond end of string, out_of_range is thrown. 01209 * If the length of the result exceeds max_size(), length_error 01210 * is thrown. The value of the string doesn't change if an 01211 * error is thrown. 01212 */ 01213 __versa_string& 01214 replace(size_type __pos1, size_type __n1, const __versa_string& __str, 01215 size_type __pos2, size_type __n2) 01216 { 01217 return this->replace(__pos1, __n1, __str._M_data() 01218 + __str._M_check(__pos2, 01219 "__versa_string::replace"), 01220 __str._M_limit(__pos2, __n2)); 01221 } 01222 01223 /** 01224 * @brief Replace characters with value of a C substring. 01225 * @param __pos Index of first character to replace. 01226 * @param __n1 Number of characters to be replaced. 01227 * @param __s C string to insert. 01228 * @param __n2 Number of characters from @a __s to use. 01229 * @return Reference to this string. 01230 * @throw std::out_of_range If @a __pos1 > size(). 01231 * @throw std::length_error If new length exceeds @c max_size(). 01232 * 01233 * Removes the characters in the range [pos,pos + n1) from this 01234 * string. In place, the first @a __n2 characters of @a __s 01235 * are inserted, or all of @a __s if @a __n2 is too large. If 01236 * @a __pos is beyond end of string, out_of_range is thrown. 01237 * If the length of result exceeds max_size(), length_error is 01238 * thrown. The value of the string doesn't change if an error 01239 * is thrown. 01240 */ 01241 __versa_string& 01242 replace(size_type __pos, size_type __n1, const _CharT* __s, 01243 size_type __n2) 01244 { 01245 __glibcxx_requires_string_len(__s, __n2); 01246 return _M_replace(_M_check(__pos, "__versa_string::replace"), 01247 _M_limit(__pos, __n1), __s, __n2); 01248 } 01249 01250 /** 01251 * @brief Replace characters with value of a C string. 01252 * @param __pos Index of first character to replace. 01253 * @param __n1 Number of characters to be replaced. 01254 * @param __s C string to insert. 01255 * @return Reference to this string. 01256 * @throw std::out_of_range If @a __pos > size(). 01257 * @throw std::length_error If new length exceeds @c max_size(). 01258 * 01259 * Removes the characters in the range [pos,pos + n1) from this 01260 * string. In place, the characters of @a __s are inserted. If 01261 * @a pos is beyond end of string, out_of_range is thrown. If 01262 * the length of result exceeds max_size(), length_error is thrown. 01263 * The value of the string doesn't change if an error is thrown. 01264 */ 01265 __versa_string& 01266 replace(size_type __pos, size_type __n1, const _CharT* __s) 01267 { 01268 __glibcxx_requires_string(__s); 01269 return this->replace(__pos, __n1, __s, traits_type::length(__s)); 01270 } 01271 01272 /** 01273 * @brief Replace characters with multiple characters. 01274 * @param __pos Index of first character to replace. 01275 * @param __n1 Number of characters to be replaced. 01276 * @param __n2 Number of characters to insert. 01277 * @param __c Character to insert. 01278 * @return Reference to this string. 01279 * @throw std::out_of_range If @a __pos > size(). 01280 * @throw std::length_error If new length exceeds @c max_size(). 01281 * 01282 * Removes the characters in the range [pos,pos + n1) from this 01283 * string. In place, @a __n2 copies of @a __c are inserted. 01284 * If @a __pos is beyond end of string, out_of_range is thrown. 01285 * If the length of result exceeds max_size(), length_error is 01286 * thrown. The value of the string doesn't change if an error 01287 * is thrown. 01288 */ 01289 __versa_string& 01290 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) 01291 { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"), 01292 _M_limit(__pos, __n1), __n2, __c); } 01293 01294 /** 01295 * @brief Replace range of characters with string. 01296 * @param __i1 Iterator referencing start of range to replace. 01297 * @param __i2 Iterator referencing end of range to replace. 01298 * @param __str String value to insert. 01299 * @return Reference to this string. 01300 * @throw std::length_error If new length exceeds @c max_size(). 01301 * 01302 * Removes the characters in the range [i1,i2). In place, the 01303 * value of @a __str is inserted. If the length of result 01304 * exceeds max_size(), length_error is thrown. The value of 01305 * the string doesn't change if an error is thrown. 01306 */ 01307 __versa_string& 01308 replace(iterator __i1, iterator __i2, const __versa_string& __str) 01309 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } 01310 01311 /** 01312 * @brief Replace range of characters with C substring. 01313 * @param __i1 Iterator referencing start of range to replace. 01314 * @param __i2 Iterator referencing end of range to replace. 01315 * @param __s C string value to insert. 01316 * @param __n Number of characters from s to insert. 01317 * @return Reference to this string. 01318 * @throw std::length_error If new length exceeds @c max_size(). 01319 * 01320 * Removes the characters in the range [i1,i2). In place, the 01321 * first @a n characters of @a __s are inserted. If the length 01322 * of result exceeds max_size(), length_error is thrown. The 01323 * value of the string doesn't change if an error is thrown. 01324 */ 01325 __versa_string& 01326 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) 01327 { 01328 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 01329 && __i2 <= _M_iend()); 01330 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n); 01331 } 01332 01333 /** 01334 * @brief Replace range of characters with C string. 01335 * @param __i1 Iterator referencing start of range to replace. 01336 * @param __i2 Iterator referencing end of range to replace. 01337 * @param __s C string value to insert. 01338 * @return Reference to this string. 01339 * @throw std::length_error If new length exceeds @c max_size(). 01340 * 01341 * Removes the characters in the range [i1,i2). In place, the 01342 * characters of @a __s are inserted. If the length of result 01343 * exceeds max_size(), length_error is thrown. The value of 01344 * the string doesn't change if an error is thrown. 01345 */ 01346 __versa_string& 01347 replace(iterator __i1, iterator __i2, const _CharT* __s) 01348 { 01349 __glibcxx_requires_string(__s); 01350 return this->replace(__i1, __i2, __s, traits_type::length(__s)); 01351 } 01352 01353 /** 01354 * @brief Replace range of characters with multiple characters 01355 * @param __i1 Iterator referencing start of range to replace. 01356 * @param __i2 Iterator referencing end of range to replace. 01357 * @param __n Number of characters to insert. 01358 * @param __c Character to insert. 01359 * @return Reference to this string. 01360 * @throw std::length_error If new length exceeds @c max_size(). 01361 * 01362 * Removes the characters in the range [i1,i2). In place, @a 01363 * __n copies of @a __c are inserted. If the length of result 01364 * exceeds max_size(), length_error is thrown. The value of 01365 * the string doesn't change if an error is thrown. 01366 */ 01367 __versa_string& 01368 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c) 01369 { 01370 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 01371 && __i2 <= _M_iend()); 01372 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c); 01373 } 01374 01375 /** 01376 * @brief Replace range of characters with range. 01377 * @param __i1 Iterator referencing start of range to replace. 01378 * @param __i2 Iterator referencing end of range to replace. 01379 * @param __k1 Iterator referencing start of range to insert. 01380 * @param __k2 Iterator referencing end of range to insert. 01381 * @return Reference to this string. 01382 * @throw std::length_error If new length exceeds @c max_size(). 01383 * 01384 * Removes the characters in the range [i1,i2). In place, 01385 * characters in the range [k1,k2) are inserted. If the length 01386 * of result exceeds max_size(), length_error is thrown. The 01387 * value of the string doesn't change if an error is thrown. 01388 */ 01389 #if __cplusplus >= 201103L 01390 template<class _InputIterator, 01391 typename = std::_RequireInputIter<_InputIterator>> 01392 __versa_string& 01393 replace(iterator __i1, iterator __i2, 01394 _InputIterator __k1, _InputIterator __k2) 01395 { 01396 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 01397 && __i2 <= _M_iend()); 01398 __glibcxx_requires_valid_range(__k1, __k2); 01399 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, 01400 std::__false_type()); 01401 } 01402 #else 01403 template<class _InputIterator> 01404 __versa_string& 01405 replace(iterator __i1, iterator __i2, 01406 _InputIterator __k1, _InputIterator __k2) 01407 { 01408 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 01409 && __i2 <= _M_iend()); 01410 __glibcxx_requires_valid_range(__k1, __k2); 01411 typedef typename std::__is_integer<_InputIterator>::__type _Integral; 01412 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); 01413 } 01414 #endif 01415 01416 // Specializations for the common case of pointer and iterator: 01417 // useful to avoid the overhead of temporary buffering in _M_replace. 01418 __versa_string& 01419 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2) 01420 { 01421 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 01422 && __i2 <= _M_iend()); 01423 __glibcxx_requires_valid_range(__k1, __k2); 01424 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 01425 __k1, __k2 - __k1); 01426 } 01427 01428 __versa_string& 01429 replace(iterator __i1, iterator __i2, 01430 const _CharT* __k1, const _CharT* __k2) 01431 { 01432 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 01433 && __i2 <= _M_iend()); 01434 __glibcxx_requires_valid_range(__k1, __k2); 01435 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 01436 __k1, __k2 - __k1); 01437 } 01438 01439 __versa_string& 01440 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2) 01441 { 01442 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 01443 && __i2 <= _M_iend()); 01444 __glibcxx_requires_valid_range(__k1, __k2); 01445 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 01446 __k1.base(), __k2 - __k1); 01447 } 01448 01449 __versa_string& 01450 replace(iterator __i1, iterator __i2, 01451 const_iterator __k1, const_iterator __k2) 01452 { 01453 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 01454 && __i2 <= _M_iend()); 01455 __glibcxx_requires_valid_range(__k1, __k2); 01456 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 01457 __k1.base(), __k2 - __k1); 01458 } 01459 01460 #if __cplusplus >= 201103L 01461 /** 01462 * @brief Replace range of characters with initializer_list. 01463 * @param __i1 Iterator referencing start of range to replace. 01464 * @param __i2 Iterator referencing end of range to replace. 01465 * @param __l The initializer_list of characters to insert. 01466 * @return Reference to this string. 01467 * @throw std::length_error If new length exceeds @c max_size(). 01468 * 01469 * Removes the characters in the range [i1,i2). In place, 01470 * characters in the range [k1,k2) are inserted. If the length 01471 * of result exceeds max_size(), length_error is thrown. The 01472 * value of the string doesn't change if an error is thrown. 01473 */ 01474 __versa_string& replace(iterator __i1, iterator __i2, 01475 std::initializer_list<_CharT> __l) 01476 { return this->replace(__i1, __i2, __l.begin(), __l.end()); } 01477 #endif // C++11 01478 01479 private: 01480 template<class _Integer> 01481 __versa_string& 01482 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n, 01483 _Integer __val, std::__true_type) 01484 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); } 01485 01486 template<class _InputIterator> 01487 __versa_string& 01488 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1, 01489 _InputIterator __k2, std::__false_type); 01490 01491 __versa_string& 01492 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, 01493 _CharT __c); 01494 01495 __versa_string& 01496 _M_replace(size_type __pos, size_type __len1, const _CharT* __s, 01497 const size_type __len2); 01498 01499 __versa_string& 01500 _M_append(const _CharT* __s, size_type __n); 01501 01502 public: 01503 01504 /** 01505 * @brief Copy substring into C string. 01506 * @param __s C string to copy value into. 01507 * @param __n Number of characters to copy. 01508 * @param __pos Index of first character to copy. 01509 * @return Number of characters actually copied 01510 * @throw std::out_of_range If pos > size(). 01511 * 01512 * Copies up to @a __n characters starting at @a __pos into the 01513 * C string @a s. If @a __pos is greater than size(), 01514 * out_of_range is thrown. 01515 */ 01516 size_type 01517 copy(_CharT* __s, size_type __n, size_type __pos = 0) const; 01518 01519 /** 01520 * @brief Swap contents with another string. 01521 * @param __s String to swap with. 01522 * 01523 * Exchanges the contents of this string with that of @a __s in 01524 * constant time. 01525 */ 01526 void 01527 swap(__versa_string& __s) 01528 { this->_M_swap(__s); } 01529 01530 // String operations: 01531 /** 01532 * @brief Return const pointer to null-terminated contents. 01533 * 01534 * This is a handle to internal data. Do not modify or dire things may 01535 * happen. 01536 */ 01537 const _CharT* 01538 c_str() const _GLIBCXX_NOEXCEPT 01539 { return this->_M_data(); } 01540 01541 /** 01542 * @brief Return const pointer to contents. 01543 * 01544 * This is a handle to internal data. Do not modify or dire things may 01545 * happen. 01546 */ 01547 const _CharT* 01548 data() const _GLIBCXX_NOEXCEPT 01549 { return this->_M_data(); } 01550 01551 /** 01552 * @brief Return copy of allocator used to construct this string. 01553 */ 01554 allocator_type 01555 get_allocator() const _GLIBCXX_NOEXCEPT 01556 { return allocator_type(this->_M_get_allocator()); } 01557 01558 /** 01559 * @brief Find position of a C substring. 01560 * @param __s C string to locate. 01561 * @param __pos Index of character to search from. 01562 * @param __n Number of characters from @a __s to search for. 01563 * @return Index of start of first occurrence. 01564 * 01565 * Starting from @a __pos, searches forward for the first @a 01566 * __n characters in @a __s within this string. If found, 01567 * returns the index where it begins. If not found, returns 01568 * npos. 01569 */ 01570 size_type 01571 find(const _CharT* __s, size_type __pos, size_type __n) const; 01572 01573 /** 01574 * @brief Find position of a string. 01575 * @param __str String to locate. 01576 * @param __pos Index of character to search from (default 0). 01577 * @return Index of start of first occurrence. 01578 * 01579 * Starting from @a __pos, searches forward for value of @a 01580 * __str within this string. If found, returns the index where 01581 * it begins. If not found, returns npos. 01582 */ 01583 size_type 01584 find(const __versa_string& __str, size_type __pos = 0) const 01585 _GLIBCXX_NOEXCEPT 01586 { return this->find(__str.data(), __pos, __str.size()); } 01587 01588 /** 01589 * @brief Find position of a C string. 01590 * @param __s C string to locate. 01591 * @param __pos Index of character to search from (default 0). 01592 * @return Index of start of first occurrence. 01593 * 01594 * Starting from @a __pos, searches forward for the value of @a 01595 * __s within this string. If found, returns the index where 01596 * it begins. If not found, returns npos. 01597 */ 01598 size_type 01599 find(const _CharT* __s, size_type __pos = 0) const 01600 { 01601 __glibcxx_requires_string(__s); 01602 return this->find(__s, __pos, traits_type::length(__s)); 01603 } 01604 01605 /** 01606 * @brief Find position of a character. 01607 * @param __c Character to locate. 01608 * @param __pos Index of character to search from (default 0). 01609 * @return Index of first occurrence. 01610 * 01611 * Starting from @a __pos, searches forward for @a __c within 01612 * this string. If found, returns the index where it was 01613 * found. If not found, returns npos. 01614 */ 01615 size_type 01616 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT; 01617 01618 /** 01619 * @brief Find last position of a string. 01620 * @param __str String to locate. 01621 * @param __pos Index of character to search back from (default end). 01622 * @return Index of start of last occurrence. 01623 * 01624 * Starting from @a __pos, searches backward for value of @a 01625 * __str within this string. If found, returns the index where 01626 * it begins. If not found, returns npos. 01627 */ 01628 size_type 01629 rfind(const __versa_string& __str, size_type __pos = npos) const 01630 _GLIBCXX_NOEXCEPT 01631 { return this->rfind(__str.data(), __pos, __str.size()); } 01632 01633 /** 01634 * @brief Find last position of a C substring. 01635 * @param __s C string to locate. 01636 * @param __pos Index of character to search back from. 01637 * @param __n Number of characters from s to search for. 01638 * @return Index of start of last occurrence. 01639 * 01640 * Starting from @a __pos, searches backward for the first @a 01641 * __n characters in @a __s within this string. If found, 01642 * returns the index where it begins. If not found, returns 01643 * npos. 01644 */ 01645 size_type 01646 rfind(const _CharT* __s, size_type __pos, size_type __n) const; 01647 01648 /** 01649 * @brief Find last position of a C string. 01650 * @param __s C string to locate. 01651 * @param __pos Index of character to start search at (default end). 01652 * @return Index of start of last occurrence. 01653 * 01654 * Starting from @a __pos, searches backward for the value of 01655 * @a __s within this string. If found, returns the index 01656 * where it begins. If not found, returns npos. 01657 */ 01658 size_type 01659 rfind(const _CharT* __s, size_type __pos = npos) const 01660 { 01661 __glibcxx_requires_string(__s); 01662 return this->rfind(__s, __pos, traits_type::length(__s)); 01663 } 01664 01665 /** 01666 * @brief Find last position of a character. 01667 * @param __c Character to locate. 01668 * @param __pos Index of character to search back from (default end). 01669 * @return Index of last occurrence. 01670 * 01671 * Starting from @a __pos, searches backward for @a __c within 01672 * this string. If found, returns the index where it was 01673 * found. If not found, returns npos. 01674 */ 01675 size_type 01676 rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT; 01677 01678 /** 01679 * @brief Find position of a character of string. 01680 * @param __str String containing characters to locate. 01681 * @param __pos Index of character to search from (default 0). 01682 * @return Index of first occurrence. 01683 * 01684 * Starting from @a __pos, searches forward for one of the characters of 01685 * @a __str within this string. If found, returns the index where it was 01686 * found. If not found, returns npos. 01687 */ 01688 size_type 01689 find_first_of(const __versa_string& __str, size_type __pos = 0) const 01690 _GLIBCXX_NOEXCEPT 01691 { return this->find_first_of(__str.data(), __pos, __str.size()); } 01692 01693 /** 01694 * @brief Find position of a character of C substring. 01695 * @param __s String containing characters to locate. 01696 * @param __pos Index of character to search from. 01697 * @param __n Number of characters from s to search for. 01698 * @return Index of first occurrence. 01699 * 01700 * Starting from @a __pos, searches forward for one of the 01701 * first @a __n characters of @a __s within this string. If 01702 * found, returns the index where it was found. If not found, 01703 * returns npos. 01704 */ 01705 size_type 01706 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const; 01707 01708 /** 01709 * @brief Find position of a character of C string. 01710 * @param __s String containing characters to locate. 01711 * @param __pos Index of character to search from (default 0). 01712 * @return Index of first occurrence. 01713 * 01714 * Starting from @a __pos, searches forward for one of the 01715 * characters of @a __s within this string. If found, returns 01716 * the index where it was found. If not found, returns npos. 01717 */ 01718 size_type 01719 find_first_of(const _CharT* __s, size_type __pos = 0) const 01720 { 01721 __glibcxx_requires_string(__s); 01722 return this->find_first_of(__s, __pos, traits_type::length(__s)); 01723 } 01724 01725 /** 01726 * @brief Find position of a character. 01727 * @param __c Character to locate. 01728 * @param __pos Index of character to search from (default 0). 01729 * @return Index of first occurrence. 01730 * 01731 * Starting from @a __pos, searches forward for the character 01732 * @a __c within this string. If found, returns the index 01733 * where it was found. If not found, returns npos. 01734 * 01735 * Note: equivalent to find(c, pos). 01736 */ 01737 size_type 01738 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT 01739 { return this->find(__c, __pos); } 01740 01741 /** 01742 * @brief Find last position of a character of string. 01743 * @param __str String containing characters to locate. 01744 * @param __pos Index of character to search back from (default end). 01745 * @return Index of last occurrence. 01746 * 01747 * Starting from @a __pos, searches backward for one of the 01748 * characters of @a __str within this string. If found, 01749 * returns the index where it was found. If not found, returns 01750 * npos. 01751 */ 01752 size_type 01753 find_last_of(const __versa_string& __str, size_type __pos = npos) const 01754 _GLIBCXX_NOEXCEPT 01755 { return this->find_last_of(__str.data(), __pos, __str.size()); } 01756 01757 /** 01758 * @brief Find last position of a character of C substring. 01759 * @param __s C string containing characters to locate. 01760 * @param __pos Index of character to search back from. 01761 * @param __n Number of characters from s to search for. 01762 * @return Index of last occurrence. 01763 * 01764 * Starting from @a __pos, searches backward for one of the 01765 * first @a __n characters of @a __s within this string. If 01766 * found, returns the index where it was found. If not found, 01767 * returns npos. 01768 */ 01769 size_type 01770 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const; 01771 01772 /** 01773 * @brief Find last position of a character of C string. 01774 * @param __s C string containing characters to locate. 01775 * @param __pos Index of character to search back from (default end). 01776 * @return Index of last occurrence. 01777 * 01778 * Starting from @a __pos, searches backward for one of the 01779 * characters of @a __s within this string. If found, returns 01780 * the index where it was found. If not found, returns npos. 01781 */ 01782 size_type 01783 find_last_of(const _CharT* __s, size_type __pos = npos) const 01784 { 01785 __glibcxx_requires_string(__s); 01786 return this->find_last_of(__s, __pos, traits_type::length(__s)); 01787 } 01788 01789 /** 01790 * @brief Find last position of a character. 01791 * @param __c Character to locate. 01792 * @param __pos Index of character to search back from (default end). 01793 * @return Index of last occurrence. 01794 * 01795 * Starting from @a __pos, searches backward for @a __c within 01796 * this string. If found, returns the index where it was 01797 * found. If not found, returns npos. 01798 * 01799 * Note: equivalent to rfind(c, pos). 01800 */ 01801 size_type 01802 find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT 01803 { return this->rfind(__c, __pos); } 01804 01805 /** 01806 * @brief Find position of a character not in string. 01807 * @param __str String containing characters to avoid. 01808 * @param __pos Index of character to search from (default 0). 01809 * @return Index of first occurrence. 01810 * 01811 * Starting from @a __pos, searches forward for a character not 01812 * contained in @a __str within this string. If found, returns 01813 * the index where it was found. If not found, returns npos. 01814 */ 01815 size_type 01816 find_first_not_of(const __versa_string& __str, size_type __pos = 0) const 01817 _GLIBCXX_NOEXCEPT 01818 { return this->find_first_not_of(__str.data(), __pos, __str.size()); } 01819 01820 /** 01821 * @brief Find position of a character not in C substring. 01822 * @param __s C string containing characters to avoid. 01823 * @param __pos Index of character to search from. 01824 * @param __n Number of characters from s to consider. 01825 * @return Index of first occurrence. 01826 * 01827 * Starting from @a __pos, searches forward for a character not 01828 * contained in the first @a __n characters of @a __s within 01829 * this string. If found, returns the index where it was 01830 * found. If not found, returns npos. 01831 */ 01832 size_type 01833 find_first_not_of(const _CharT* __s, size_type __pos, 01834 size_type __n) const; 01835 01836 /** 01837 * @brief Find position of a character not in C string. 01838 * @param __s C string containing characters to avoid. 01839 * @param __pos Index of character to search from (default 0). 01840 * @return Index of first occurrence. 01841 * 01842 * Starting from @a __pos, searches forward for a character not 01843 * contained in @a __s within this string. If found, returns 01844 * the index where it was found. If not found, returns npos. 01845 */ 01846 size_type 01847 find_first_not_of(const _CharT* __s, size_type __pos = 0) const 01848 { 01849 __glibcxx_requires_string(__s); 01850 return this->find_first_not_of(__s, __pos, traits_type::length(__s)); 01851 } 01852 01853 /** 01854 * @brief Find position of a different character. 01855 * @param __c Character to avoid. 01856 * @param __pos Index of character to search from (default 0). 01857 * @return Index of first occurrence. 01858 * 01859 * Starting from @a __pos, searches forward for a character 01860 * other than @a __c within this string. If found, returns the 01861 * index where it was found. If not found, returns npos. 01862 */ 01863 size_type 01864 find_first_not_of(_CharT __c, size_type __pos = 0) const 01865 _GLIBCXX_NOEXCEPT; 01866 01867 /** 01868 * @brief Find last position of a character not in string. 01869 * @param __str String containing characters to avoid. 01870 * @param __pos Index of character to search back from (default end). 01871 * @return Index of last occurrence. 01872 * 01873 * Starting from @a __pos, searches backward for a character 01874 * not contained in @a __str within this string. If found, 01875 * returns the index where it was found. If not found, returns 01876 * npos. 01877 */ 01878 size_type 01879 find_last_not_of(const __versa_string& __str, 01880 size_type __pos = npos) const _GLIBCXX_NOEXCEPT 01881 { return this->find_last_not_of(__str.data(), __pos, __str.size()); } 01882 01883 /** 01884 * @brief Find last position of a character not in C substring. 01885 * @param __s C string containing characters to avoid. 01886 * @param __pos Index of character to search back from. 01887 * @param __n Number of characters from s to consider. 01888 * @return Index of last occurrence. 01889 * 01890 * Starting from @a __pos, searches backward for a character 01891 * not contained in the first @a __n characters of @a __s 01892 * within this string. If found, returns the index where it 01893 * was found. If not found, returns npos. 01894 */ 01895 size_type 01896 find_last_not_of(const _CharT* __s, size_type __pos, 01897 size_type __n) const; 01898 /** 01899 * @brief Find last position of a character not in C string. 01900 * @param __s C string containing characters to avoid. 01901 * @param __pos Index of character to search back from (default end). 01902 * @return Index of last occurrence. 01903 * 01904 * Starting from @a __pos, searches backward for a character 01905 * not contained in @a __s within this string. If found, 01906 * returns the index where it was found. If not found, returns 01907 * npos. 01908 */ 01909 size_type 01910 find_last_not_of(const _CharT* __s, size_type __pos = npos) const 01911 { 01912 __glibcxx_requires_string(__s); 01913 return this->find_last_not_of(__s, __pos, traits_type::length(__s)); 01914 } 01915 01916 /** 01917 * @brief Find last position of a different character. 01918 * @param __c Character to avoid. 01919 * @param __pos Index of character to search back from (default end). 01920 * @return Index of last occurrence. 01921 * 01922 * Starting from @a __pos, searches backward for a character 01923 * other than @a __c within this string. If found, returns the 01924 * index where it was found. If not found, returns npos. 01925 */ 01926 size_type 01927 find_last_not_of(_CharT __c, size_type __pos = npos) const 01928 _GLIBCXX_NOEXCEPT; 01929 01930 /** 01931 * @brief Get a substring. 01932 * @param __pos Index of first character (default 0). 01933 * @param __n Number of characters in substring (default remainder). 01934 * @return The new string. 01935 * @throw std::out_of_range If pos > size(). 01936 * 01937 * Construct and return a new string using the @a __n 01938 * characters starting at @a __pos. If the string is too 01939 * short, use the remainder of the characters. If @a __pos is 01940 * beyond the end of the string, out_of_range is thrown. 01941 */ 01942 __versa_string 01943 substr(size_type __pos = 0, size_type __n = npos) const 01944 { 01945 return __versa_string(*this, _M_check(__pos, "__versa_string::substr"), 01946 __n); 01947 } 01948 01949 /** 01950 * @brief Compare to a string. 01951 * @param __str String to compare against. 01952 * @return Integer < 0, 0, or > 0. 01953 * 01954 * Returns an integer < 0 if this string is ordered before @a 01955 * __str, 0 if their values are equivalent, or > 0 if this 01956 * string is ordered after @a __str. Determines the effective 01957 * length rlen of the strings to compare as the smallest of 01958 * size() and str.size(). The function then compares the two 01959 * strings by calling traits::compare(data(), str.data(),rlen). 01960 * If the result of the comparison is nonzero returns it, 01961 * otherwise the shorter one is ordered first. 01962 */ 01963 int 01964 compare(const __versa_string& __str) const 01965 { 01966 if (this->_M_compare(__str)) 01967 return 0; 01968 01969 const size_type __size = this->size(); 01970 const size_type __osize = __str.size(); 01971 const size_type __len = std::min(__size, __osize); 01972 01973 int __r = traits_type::compare(this->_M_data(), __str.data(), __len); 01974 if (!__r) 01975 __r = this->_S_compare(__size, __osize); 01976 return __r; 01977 } 01978 01979 /** 01980 * @brief Compare substring to a string. 01981 * @param __pos Index of first character of substring. 01982 * @param __n Number of characters in substring. 01983 * @param __str String to compare against. 01984 * @return Integer < 0, 0, or > 0. 01985 * 01986 * Form the substring of this string from the @a __n characters 01987 * starting at @a __pos. Returns an integer < 0 if the 01988 * substring is ordered before @a __str, 0 if their values are 01989 * equivalent, or > 0 if the substring is ordered after @a 01990 * __str. Determines the effective length rlen of the strings 01991 * to compare as the smallest of the length of the substring 01992 * and @a __str.size(). The function then compares the two 01993 * strings by calling 01994 * traits::compare(substring.data(),str.data(),rlen). If the 01995 * result of the comparison is nonzero returns it, otherwise 01996 * the shorter one is ordered first. 01997 */ 01998 int 01999 compare(size_type __pos, size_type __n, 02000 const __versa_string& __str) const; 02001 02002 /** 02003 * @brief Compare substring to a substring. 02004 * @param __pos1 Index of first character of substring. 02005 * @param __n1 Number of characters in substring. 02006 * @param __str String to compare against. 02007 * @param __pos2 Index of first character of substring of str. 02008 * @param __n2 Number of characters in substring of str. 02009 * @return Integer < 0, 0, or > 0. 02010 * 02011 * Form the substring of this string from the @a __n1 02012 * characters starting at @a __pos1. Form the substring of @a 02013 * __str from the @a __n2 characters starting at @a __pos2. 02014 * Returns an integer < 0 if this substring is ordered before 02015 * the substring of @a __str, 0 if their values are equivalent, 02016 * or > 0 if this substring is ordered after the substring of 02017 * @a __str. Determines the effective length rlen of the 02018 * strings to compare as the smallest of the lengths of the 02019 * substrings. The function then compares the two strings by 02020 * calling 02021 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). 02022 * If the result of the comparison is nonzero returns it, 02023 * otherwise the shorter one is ordered first. 02024 */ 02025 int 02026 compare(size_type __pos1, size_type __n1, const __versa_string& __str, 02027 size_type __pos2, size_type __n2) const; 02028 02029 /** 02030 * @brief Compare to a C string. 02031 * @param __s C string to compare against. 02032 * @return Integer < 0, 0, or > 0. 02033 * 02034 * Returns an integer < 0 if this string is ordered before @a 02035 * __s, 0 if their values are equivalent, or > 0 if this string 02036 * is ordered after @a __s. Determines the effective length 02037 * rlen of the strings to compare as the smallest of size() and 02038 * the length of a string constructed from @a __s. The 02039 * function then compares the two strings by calling 02040 * traits::compare(data(),s,rlen). If the result of the 02041 * comparison is nonzero returns it, otherwise the shorter one 02042 * is ordered first. 02043 */ 02044 int 02045 compare(const _CharT* __s) const; 02046 02047 // _GLIBCXX_RESOLVE_LIB_DEFECTS 02048 // 5 String::compare specification questionable 02049 /** 02050 * @brief Compare substring to a C string. 02051 * @param __pos Index of first character of substring. 02052 * @param __n1 Number of characters in substring. 02053 * @param __s C string to compare against. 02054 * @return Integer < 0, 0, or > 0. 02055 * 02056 * Form the substring of this string from the @a __n1 02057 * characters starting at @a __pos. Returns an integer < 0 if 02058 * the substring is ordered before @a __s, 0 if their values 02059 * are equivalent, or > 0 if the substring is ordered after @a 02060 * __s. Determines the effective length rlen of the strings to 02061 * compare as the smallest of the length of the substring and 02062 * the length of a string constructed from @a __s. The 02063 * function then compares the two string by calling 02064 * traits::compare(substring.data(),s,rlen). If the result of 02065 * the comparison is nonzero returns it, otherwise the shorter 02066 * one is ordered first. 02067 */ 02068 int 02069 compare(size_type __pos, size_type __n1, const _CharT* __s) const; 02070 02071 /** 02072 * @brief Compare substring against a character array. 02073 * @param __pos Index of first character of substring. 02074 * @param __n1 Number of characters in substring. 02075 * @param __s character array to compare against. 02076 * @param __n2 Number of characters of s. 02077 * @return Integer < 0, 0, or > 0. 02078 * 02079 * Form the substring of this string from the @a __n1 02080 * characters starting at @a __pos. Form a string from the 02081 * first @a __n2 characters of @a __s. Returns an integer < 0 02082 * if this substring is ordered before the string from @a __s, 02083 * 0 if their values are equivalent, or > 0 if this substring 02084 * is ordered after the string from @a __s. Determines the 02085 * effective length rlen of the strings to compare as the 02086 * smallest of the length of the substring and @a __n2. The 02087 * function then compares the two strings by calling 02088 * traits::compare(substring.data(),__s,rlen). If the result of 02089 * the comparison is nonzero returns it, otherwise the shorter 02090 * one is ordered first. 02091 * 02092 * NB: __s must have at least n2 characters, <em>\\0</em> has no special 02093 * meaning. 02094 */ 02095 int 02096 compare(size_type __pos, size_type __n1, const _CharT* __s, 02097 size_type __n2) const; 02098 }; 02099 02100 // operator+ 02101 /** 02102 * @brief Concatenate two strings. 02103 * @param __lhs First string. 02104 * @param __rhs Last string. 02105 * @return New string with value of @a __lhs followed by @a __rhs. 02106 */ 02107 template<typename _CharT, typename _Traits, typename _Alloc, 02108 template <typename, typename, typename> class _Base> 02109 __versa_string<_CharT, _Traits, _Alloc, _Base> 02110 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02111 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); 02112 02113 /** 02114 * @brief Concatenate C string and string. 02115 * @param __lhs First string. 02116 * @param __rhs Last string. 02117 * @return New string with value of @a __lhs followed by @a __rhs. 02118 */ 02119 template<typename _CharT, typename _Traits, typename _Alloc, 02120 template <typename, typename, typename> class _Base> 02121 __versa_string<_CharT, _Traits, _Alloc, _Base> 02122 operator+(const _CharT* __lhs, 02123 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); 02124 02125 /** 02126 * @brief Concatenate character and string. 02127 * @param __lhs First string. 02128 * @param __rhs Last string. 02129 * @return New string with @a __lhs followed by @a __rhs. 02130 */ 02131 template<typename _CharT, typename _Traits, typename _Alloc, 02132 template <typename, typename, typename> class _Base> 02133 __versa_string<_CharT, _Traits, _Alloc, _Base> 02134 operator+(_CharT __lhs, 02135 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); 02136 02137 /** 02138 * @brief Concatenate string and C string. 02139 * @param __lhs First string. 02140 * @param __rhs Last string. 02141 * @return New string with @a __lhs followed by @a __rhs. 02142 */ 02143 template<typename _CharT, typename _Traits, typename _Alloc, 02144 template <typename, typename, typename> class _Base> 02145 __versa_string<_CharT, _Traits, _Alloc, _Base> 02146 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02147 const _CharT* __rhs); 02148 02149 /** 02150 * @brief Concatenate string and character. 02151 * @param __lhs First string. 02152 * @param __rhs Last string. 02153 * @return New string with @a __lhs followed by @a __rhs. 02154 */ 02155 template<typename _CharT, typename _Traits, typename _Alloc, 02156 template <typename, typename, typename> class _Base> 02157 __versa_string<_CharT, _Traits, _Alloc, _Base> 02158 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02159 _CharT __rhs); 02160 02161 #if __cplusplus >= 201103L 02162 template<typename _CharT, typename _Traits, typename _Alloc, 02163 template <typename, typename, typename> class _Base> 02164 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 02165 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, 02166 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02167 { return std::move(__lhs.append(__rhs)); } 02168 02169 template<typename _CharT, typename _Traits, typename _Alloc, 02170 template <typename, typename, typename> class _Base> 02171 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 02172 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02173 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) 02174 { return std::move(__rhs.insert(0, __lhs)); } 02175 02176 template<typename _CharT, typename _Traits, typename _Alloc, 02177 template <typename, typename, typename> class _Base> 02178 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 02179 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, 02180 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) 02181 { 02182 const auto __size = __lhs.size() + __rhs.size(); 02183 const bool __cond = (__size > __lhs.capacity() 02184 && __size <= __rhs.capacity()); 02185 return __cond ? std::move(__rhs.insert(0, __lhs)) 02186 : std::move(__lhs.append(__rhs)); 02187 } 02188 02189 template<typename _CharT, typename _Traits, typename _Alloc, 02190 template <typename, typename, typename> class _Base> 02191 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 02192 operator+(const _CharT* __lhs, 02193 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) 02194 { return std::move(__rhs.insert(0, __lhs)); } 02195 02196 template<typename _CharT, typename _Traits, typename _Alloc, 02197 template <typename, typename, typename> class _Base> 02198 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 02199 operator+(_CharT __lhs, 02200 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) 02201 { return std::move(__rhs.insert(0, 1, __lhs)); } 02202 02203 template<typename _CharT, typename _Traits, typename _Alloc, 02204 template <typename, typename, typename> class _Base> 02205 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 02206 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, 02207 const _CharT* __rhs) 02208 { return std::move(__lhs.append(__rhs)); } 02209 02210 template<typename _CharT, typename _Traits, typename _Alloc, 02211 template <typename, typename, typename> class _Base> 02212 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 02213 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, 02214 _CharT __rhs) 02215 { return std::move(__lhs.append(1, __rhs)); } 02216 #endif 02217 02218 // operator == 02219 /** 02220 * @brief Test equivalence of two strings. 02221 * @param __lhs First string. 02222 * @param __rhs Second string. 02223 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. 02224 */ 02225 template<typename _CharT, typename _Traits, typename _Alloc, 02226 template <typename, typename, typename> class _Base> 02227 inline bool 02228 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02229 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02230 { return __lhs.compare(__rhs) == 0; } 02231 02232 template<typename _CharT, 02233 template <typename, typename, typename> class _Base> 02234 inline typename __enable_if<std::__is_char<_CharT>::__value, bool>::__type 02235 operator==(const __versa_string<_CharT, std::char_traits<_CharT>, 02236 std::allocator<_CharT>, _Base>& __lhs, 02237 const __versa_string<_CharT, std::char_traits<_CharT>, 02238 std::allocator<_CharT>, _Base>& __rhs) 02239 { return (__lhs.size() == __rhs.size() 02240 && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(), 02241 __lhs.size())); } 02242 02243 /** 02244 * @brief Test equivalence of C string and string. 02245 * @param __lhs C string. 02246 * @param __rhs String. 02247 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise. 02248 */ 02249 template<typename _CharT, typename _Traits, typename _Alloc, 02250 template <typename, typename, typename> class _Base> 02251 inline bool 02252 operator==(const _CharT* __lhs, 02253 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02254 { return __rhs.compare(__lhs) == 0; } 02255 02256 /** 02257 * @brief Test equivalence of string and C string. 02258 * @param __lhs String. 02259 * @param __rhs C string. 02260 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. 02261 */ 02262 template<typename _CharT, typename _Traits, typename _Alloc, 02263 template <typename, typename, typename> class _Base> 02264 inline bool 02265 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02266 const _CharT* __rhs) 02267 { return __lhs.compare(__rhs) == 0; } 02268 02269 // operator != 02270 /** 02271 * @brief Test difference of two strings. 02272 * @param __lhs First string. 02273 * @param __rhs Second string. 02274 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. 02275 */ 02276 template<typename _CharT, typename _Traits, typename _Alloc, 02277 template <typename, typename, typename> class _Base> 02278 inline bool 02279 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02280 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02281 { return !(__lhs == __rhs); } 02282 02283 /** 02284 * @brief Test difference of C string and string. 02285 * @param __lhs C string. 02286 * @param __rhs String. 02287 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise. 02288 */ 02289 template<typename _CharT, typename _Traits, typename _Alloc, 02290 template <typename, typename, typename> class _Base> 02291 inline bool 02292 operator!=(const _CharT* __lhs, 02293 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02294 { return !(__lhs == __rhs); } 02295 02296 /** 02297 * @brief Test difference of string and C string. 02298 * @param __lhs String. 02299 * @param __rhs C string. 02300 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. 02301 */ 02302 template<typename _CharT, typename _Traits, typename _Alloc, 02303 template <typename, typename, typename> class _Base> 02304 inline bool 02305 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02306 const _CharT* __rhs) 02307 { return !(__lhs == __rhs); } 02308 02309 // operator < 02310 /** 02311 * @brief Test if string precedes string. 02312 * @param __lhs First string. 02313 * @param __rhs Second string. 02314 * @return True if @a __lhs precedes @a __rhs. False otherwise. 02315 */ 02316 template<typename _CharT, typename _Traits, typename _Alloc, 02317 template <typename, typename, typename> class _Base> 02318 inline bool 02319 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02320 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02321 { return __lhs.compare(__rhs) < 0; } 02322 02323 /** 02324 * @brief Test if string precedes C string. 02325 * @param __lhs String. 02326 * @param __rhs C string. 02327 * @return True if @a __lhs precedes @a __rhs. False otherwise. 02328 */ 02329 template<typename _CharT, typename _Traits, typename _Alloc, 02330 template <typename, typename, typename> class _Base> 02331 inline bool 02332 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02333 const _CharT* __rhs) 02334 { return __lhs.compare(__rhs) < 0; } 02335 02336 /** 02337 * @brief Test if C string precedes string. 02338 * @param __lhs C string. 02339 * @param __rhs String. 02340 * @return True if @a __lhs precedes @a __rhs. False otherwise. 02341 */ 02342 template<typename _CharT, typename _Traits, typename _Alloc, 02343 template <typename, typename, typename> class _Base> 02344 inline bool 02345 operator<(const _CharT* __lhs, 02346 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02347 { return __rhs.compare(__lhs) > 0; } 02348 02349 // operator > 02350 /** 02351 * @brief Test if string follows string. 02352 * @param __lhs First string. 02353 * @param __rhs Second string. 02354 * @return True if @a __lhs follows @a __rhs. False otherwise. 02355 */ 02356 template<typename _CharT, typename _Traits, typename _Alloc, 02357 template <typename, typename, typename> class _Base> 02358 inline bool 02359 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02360 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02361 { return __lhs.compare(__rhs) > 0; } 02362 02363 /** 02364 * @brief Test if string follows C string. 02365 * @param __lhs String. 02366 * @param __rhs C string. 02367 * @return True if @a __lhs follows @a __rhs. False otherwise. 02368 */ 02369 template<typename _CharT, typename _Traits, typename _Alloc, 02370 template <typename, typename, typename> class _Base> 02371 inline bool 02372 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02373 const _CharT* __rhs) 02374 { return __lhs.compare(__rhs) > 0; } 02375 02376 /** 02377 * @brief Test if C string follows string. 02378 * @param __lhs C string. 02379 * @param __rhs String. 02380 * @return True if @a __lhs follows @a __rhs. False otherwise. 02381 */ 02382 template<typename _CharT, typename _Traits, typename _Alloc, 02383 template <typename, typename, typename> class _Base> 02384 inline bool 02385 operator>(const _CharT* __lhs, 02386 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02387 { return __rhs.compare(__lhs) < 0; } 02388 02389 // operator <= 02390 /** 02391 * @brief Test if string doesn't follow string. 02392 * @param __lhs First string. 02393 * @param __rhs Second string. 02394 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. 02395 */ 02396 template<typename _CharT, typename _Traits, typename _Alloc, 02397 template <typename, typename, typename> class _Base> 02398 inline bool 02399 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02400 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02401 { return __lhs.compare(__rhs) <= 0; } 02402 02403 /** 02404 * @brief Test if string doesn't follow C string. 02405 * @param __lhs String. 02406 * @param __rhs C string. 02407 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. 02408 */ 02409 template<typename _CharT, typename _Traits, typename _Alloc, 02410 template <typename, typename, typename> class _Base> 02411 inline bool 02412 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02413 const _CharT* __rhs) 02414 { return __lhs.compare(__rhs) <= 0; } 02415 02416 /** 02417 * @brief Test if C string doesn't follow string. 02418 * @param __lhs C string. 02419 * @param __rhs String. 02420 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. 02421 */ 02422 template<typename _CharT, typename _Traits, typename _Alloc, 02423 template <typename, typename, typename> class _Base> 02424 inline bool 02425 operator<=(const _CharT* __lhs, 02426 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02427 { return __rhs.compare(__lhs) >= 0; } 02428 02429 // operator >= 02430 /** 02431 * @brief Test if string doesn't precede string. 02432 * @param __lhs First string. 02433 * @param __rhs Second string. 02434 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. 02435 */ 02436 template<typename _CharT, typename _Traits, typename _Alloc, 02437 template <typename, typename, typename> class _Base> 02438 inline bool 02439 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02440 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02441 { return __lhs.compare(__rhs) >= 0; } 02442 02443 /** 02444 * @brief Test if string doesn't precede C string. 02445 * @param __lhs String. 02446 * @param __rhs C string. 02447 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. 02448 */ 02449 template<typename _CharT, typename _Traits, typename _Alloc, 02450 template <typename, typename, typename> class _Base> 02451 inline bool 02452 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02453 const _CharT* __rhs) 02454 { return __lhs.compare(__rhs) >= 0; } 02455 02456 /** 02457 * @brief Test if C string doesn't precede string. 02458 * @param __lhs C string. 02459 * @param __rhs String. 02460 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. 02461 */ 02462 template<typename _CharT, typename _Traits, typename _Alloc, 02463 template <typename, typename, typename> class _Base> 02464 inline bool 02465 operator>=(const _CharT* __lhs, 02466 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02467 { return __rhs.compare(__lhs) <= 0; } 02468 02469 /** 02470 * @brief Swap contents of two strings. 02471 * @param __lhs First string. 02472 * @param __rhs Second string. 02473 * 02474 * Exchanges the contents of @a __lhs and @a __rhs in constant time. 02475 */ 02476 template<typename _CharT, typename _Traits, typename _Alloc, 02477 template <typename, typename, typename> class _Base> 02478 inline void 02479 swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02480 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02481 { __lhs.swap(__rhs); } 02482 02483 _GLIBCXX_END_NAMESPACE_VERSION 02484 } // namespace 02485 02486 namespace std _GLIBCXX_VISIBILITY(default) 02487 { 02488 _GLIBCXX_BEGIN_NAMESPACE_VERSION 02489 02490 /** 02491 * @brief Read stream into a string. 02492 * @param __is Input stream. 02493 * @param __str Buffer to store into. 02494 * @return Reference to the input stream. 02495 * 02496 * Stores characters from @a __is into @a __str until whitespace is 02497 * found, the end of the stream is encountered, or str.max_size() 02498 * is reached. If is.width() is non-zero, that is the limit on the 02499 * number of characters stored into @a __str. Any previous 02500 * contents of @a __str are erased. 02501 */ 02502 template<typename _CharT, typename _Traits, typename _Alloc, 02503 template <typename, typename, typename> class _Base> 02504 basic_istream<_CharT, _Traits>& 02505 operator>>(basic_istream<_CharT, _Traits>& __is, 02506 __gnu_cxx::__versa_string<_CharT, _Traits, 02507 _Alloc, _Base>& __str); 02508 02509 /** 02510 * @brief Write string to a stream. 02511 * @param __os Output stream. 02512 * @param __str String to write out. 02513 * @return Reference to the output stream. 02514 * 02515 * Output characters of @a __str into os following the same rules as for 02516 * writing a C string. 02517 */ 02518 template<typename _CharT, typename _Traits, typename _Alloc, 02519 template <typename, typename, typename> class _Base> 02520 inline basic_ostream<_CharT, _Traits>& 02521 operator<<(basic_ostream<_CharT, _Traits>& __os, 02522 const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, 02523 _Base>& __str) 02524 { 02525 // _GLIBCXX_RESOLVE_LIB_DEFECTS 02526 // 586. string inserter not a formatted function 02527 return __ostream_insert(__os, __str.data(), __str.size()); 02528 } 02529 02530 /** 02531 * @brief Read a line from stream into a string. 02532 * @param __is Input stream. 02533 * @param __str Buffer to store into. 02534 * @param __delim Character marking end of line. 02535 * @return Reference to the input stream. 02536 * 02537 * Stores characters from @a __is into @a __str until @a __delim is 02538 * found, the end of the stream is encountered, or str.max_size() 02539 * is reached. If is.width() is non-zero, that is the limit on the 02540 * number of characters stored into @a __str. Any previous 02541 * contents of @a __str are erased. If @a delim was encountered, 02542 * it is extracted but not stored into @a __str. 02543 */ 02544 template<typename _CharT, typename _Traits, typename _Alloc, 02545 template <typename, typename, typename> class _Base> 02546 basic_istream<_CharT, _Traits>& 02547 getline(basic_istream<_CharT, _Traits>& __is, 02548 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str, 02549 _CharT __delim); 02550 02551 /** 02552 * @brief Read a line from stream into a string. 02553 * @param __is Input stream. 02554 * @param __str Buffer to store into. 02555 * @return Reference to the input stream. 02556 * 02557 * Stores characters from is into @a __str until '\n' is 02558 * found, the end of the stream is encountered, or str.max_size() 02559 * is reached. If is.width() is non-zero, that is the limit on the 02560 * number of characters stored into @a __str. Any previous 02561 * contents of @a __str are erased. If end of line was 02562 * encountered, it is extracted but not stored into @a __str. 02563 */ 02564 template<typename _CharT, typename _Traits, typename _Alloc, 02565 template <typename, typename, typename> class _Base> 02566 inline basic_istream<_CharT, _Traits>& 02567 getline(basic_istream<_CharT, _Traits>& __is, 02568 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str) 02569 { return getline(__is, __str, __is.widen('\n')); } 02570 02571 _GLIBCXX_END_NAMESPACE_VERSION 02572 } // namespace 02573 02574 #if ((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99)) 02575 02576 #include <ext/string_conversions.h> 02577 02578 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) 02579 { 02580 _GLIBCXX_BEGIN_NAMESPACE_VERSION 02581 02582 // 21.4 Numeric Conversions [string.conversions]. 02583 inline int 02584 stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) 02585 { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(), 02586 __idx, __base); } 02587 02588 inline long 02589 stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) 02590 { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(), 02591 __idx, __base); } 02592 02593 inline unsigned long 02594 stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) 02595 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(), 02596 __idx, __base); } 02597 02598 inline long long 02599 stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) 02600 { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(), 02601 __idx, __base); } 02602 02603 inline unsigned long long 02604 stoull(const __vstring& __str, std::size_t* __idx, int __base = 10) 02605 { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(), 02606 __idx, __base); } 02607 02608 // NB: strtof vs strtod. 02609 inline float 02610 stof(const __vstring& __str, std::size_t* __idx = 0) 02611 { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } 02612 02613 inline double 02614 stod(const __vstring& __str, std::size_t* __idx = 0) 02615 { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } 02616 02617 inline long double 02618 stold(const __vstring& __str, std::size_t* __idx = 0) 02619 { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } 02620 02621 // NB: (v)snprintf vs sprintf. 02622 02623 // DR 1261. 02624 inline __vstring 02625 to_string(int __val) 02626 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int), 02627 "%d", __val); } 02628 02629 inline __vstring 02630 to_string(unsigned __val) 02631 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 02632 4 * sizeof(unsigned), 02633 "%u", __val); } 02634 02635 inline __vstring 02636 to_string(long __val) 02637 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 02638 4 * sizeof(long), 02639 "%ld", __val); } 02640 02641 inline __vstring 02642 to_string(unsigned long __val) 02643 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 02644 4 * sizeof(unsigned long), 02645 "%lu", __val); } 02646 02647 02648 inline __vstring 02649 to_string(long long __val) 02650 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 02651 4 * sizeof(long long), 02652 "%lld", __val); } 02653 02654 inline __vstring 02655 to_string(unsigned long long __val) 02656 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 02657 4 * sizeof(unsigned long long), 02658 "%llu", __val); } 02659 02660 inline __vstring 02661 to_string(float __val) 02662 { 02663 const int __n = __numeric_traits<float>::__max_exponent10 + 20; 02664 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n, 02665 "%f", __val); 02666 } 02667 02668 inline __vstring 02669 to_string(double __val) 02670 { 02671 const int __n = __numeric_traits<double>::__max_exponent10 + 20; 02672 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n, 02673 "%f", __val); 02674 } 02675 02676 inline __vstring 02677 to_string(long double __val) 02678 { 02679 const int __n = __numeric_traits<long double>::__max_exponent10 + 20; 02680 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n, 02681 "%Lf", __val); 02682 } 02683 02684 #ifdef _GLIBCXX_USE_WCHAR_T 02685 inline int 02686 stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) 02687 { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(), 02688 __idx, __base); } 02689 02690 inline long 02691 stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) 02692 { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(), 02693 __idx, __base); } 02694 02695 inline unsigned long 02696 stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) 02697 { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(), 02698 __idx, __base); } 02699 02700 inline long long 02701 stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) 02702 { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(), 02703 __idx, __base); } 02704 02705 inline unsigned long long 02706 stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) 02707 { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(), 02708 __idx, __base); } 02709 02710 // NB: wcstof vs wcstod. 02711 inline float 02712 stof(const __wvstring& __str, std::size_t* __idx = 0) 02713 { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); } 02714 02715 inline double 02716 stod(const __wvstring& __str, std::size_t* __idx = 0) 02717 { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); } 02718 02719 inline long double 02720 stold(const __wvstring& __str, std::size_t* __idx = 0) 02721 { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); } 02722 02723 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF 02724 // DR 1261. 02725 inline __wvstring 02726 to_wstring(int __val) 02727 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 02728 4 * sizeof(int), 02729 L"%d", __val); } 02730 02731 inline __wvstring 02732 to_wstring(unsigned __val) 02733 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 02734 4 * sizeof(unsigned), 02735 L"%u", __val); } 02736 02737 inline __wvstring 02738 to_wstring(long __val) 02739 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 02740 4 * sizeof(long), 02741 L"%ld", __val); } 02742 02743 inline __wvstring 02744 to_wstring(unsigned long __val) 02745 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 02746 4 * sizeof(unsigned long), 02747 L"%lu", __val); } 02748 02749 inline __wvstring 02750 to_wstring(long long __val) 02751 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 02752 4 * sizeof(long long), 02753 L"%lld", __val); } 02754 02755 inline __wvstring 02756 to_wstring(unsigned long long __val) 02757 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 02758 4 * sizeof(unsigned long long), 02759 L"%llu", __val); } 02760 02761 inline __wvstring 02762 to_wstring(float __val) 02763 { 02764 const int __n = __numeric_traits<float>::__max_exponent10 + 20; 02765 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n, 02766 L"%f", __val); 02767 } 02768 02769 inline __wvstring 02770 to_wstring(double __val) 02771 { 02772 const int __n = __numeric_traits<double>::__max_exponent10 + 20; 02773 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n, 02774 L"%f", __val); 02775 } 02776 02777 inline __wvstring 02778 to_wstring(long double __val) 02779 { 02780 const int __n = __numeric_traits<long double>::__max_exponent10 + 20; 02781 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n, 02782 L"%Lf", __val); 02783 } 02784 #endif 02785 #endif 02786 02787 _GLIBCXX_END_NAMESPACE_VERSION 02788 } // namespace 02789 02790 #endif 02791 02792 #if __cplusplus >= 201103L 02793 02794 #include <bits/functional_hash.h> 02795 02796 namespace std _GLIBCXX_VISIBILITY(default) 02797 { 02798 _GLIBCXX_BEGIN_NAMESPACE_VERSION 02799 02800 /// std::hash specialization for __vstring. 02801 template<> 02802 struct hash<__gnu_cxx::__vstring> 02803 : public __hash_base<size_t, __gnu_cxx::__vstring> 02804 { 02805 size_t 02806 operator()(const __gnu_cxx::__vstring& __s) const noexcept 02807 { return std::_Hash_impl::hash(__s.data(), __s.length()); } 02808 }; 02809 02810 #ifdef _GLIBCXX_USE_WCHAR_T 02811 /// std::hash specialization for __wvstring. 02812 template<> 02813 struct hash<__gnu_cxx::__wvstring> 02814 : public __hash_base<size_t, __gnu_cxx::__wvstring> 02815 { 02816 size_t 02817 operator()(const __gnu_cxx::__wvstring& __s) const noexcept 02818 { return std::_Hash_impl::hash(__s.data(), 02819 __s.length() * sizeof(wchar_t)); } 02820 }; 02821 #endif 02822 02823 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 02824 /// std::hash specialization for __u16vstring. 02825 template<> 02826 struct hash<__gnu_cxx::__u16vstring> 02827 : public __hash_base<size_t, __gnu_cxx::__u16vstring> 02828 { 02829 size_t 02830 operator()(const __gnu_cxx::__u16vstring& __s) const noexcept 02831 { return std::_Hash_impl::hash(__s.data(), 02832 __s.length() * sizeof(char16_t)); } 02833 }; 02834 02835 /// std::hash specialization for __u32vstring. 02836 template<> 02837 struct hash<__gnu_cxx::__u32vstring> 02838 : public __hash_base<size_t, __gnu_cxx::__u32vstring> 02839 { 02840 size_t 02841 operator()(const __gnu_cxx::__u32vstring& __s) const noexcept 02842 { return std::_Hash_impl::hash(__s.data(), 02843 __s.length() * sizeof(char32_t)); } 02844 }; 02845 #endif 02846 02847 _GLIBCXX_END_NAMESPACE_VERSION 02848 } // namespace 02849 02850 #endif // C++11 02851 02852 #include "vstring.tcc" 02853 02854 #endif /* _VSTRING_H */