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