00001 // Versatile string -*- C++ -*- 00002 00003 // Copyright (C) 2005, 2006, 2007 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 2, 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 // You should have received a copy of the GNU General Public License along 00017 // with this library; see the file COPYING. If not, write to the Free 00018 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 00019 // USA. 00020 00021 // As a special exception, you may use this file as part of a free software 00022 // library without restriction. Specifically, if other files instantiate 00023 // templates or use macros or inline functions from this file, or you compile 00024 // this file and link it with other files to produce an executable, this 00025 // file does not by itself cause the resulting executable to be covered by 00026 // the GNU General Public License. This exception does not however 00027 // invalidate any other reasons why the executable file might be covered by 00028 // the GNU General Public License. 00029 00030 /** @file ext/vstring.h 00031 * This file is a GNU extension to the Standard C++ Library. 00032 */ 00033 00034 #ifndef _VSTRING_H 00035 #define _VSTRING_H 1 00036 00037 #pragma GCC system_header 00038 00039 #include <ext/vstring_util.h> 00040 #include <ext/rc_string_base.h> 00041 #include <ext/sso_string_base.h> 00042 00043 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) 00044 00045 /** 00046 * @class __versa_string vstring.h 00047 * @brief Managing sequences of characters and character-like objects. 00048 */ 00049 00050 // Template class __versa_string 00051 template<typename _CharT, typename _Traits, typename _Alloc, 00052 template <typename, typename, typename> class _Base> 00053 class __versa_string 00054 : private _Base<_CharT, _Traits, _Alloc> 00055 { 00056 typedef _Base<_CharT, _Traits, _Alloc> __vstring_base; 00057 typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type; 00058 00059 // Types: 00060 public: 00061 typedef _Traits traits_type; 00062 typedef typename _Traits::char_type value_type; 00063 typedef _Alloc allocator_type; 00064 typedef typename _CharT_alloc_type::size_type size_type; 00065 typedef typename _CharT_alloc_type::difference_type difference_type; 00066 typedef typename _CharT_alloc_type::reference reference; 00067 typedef typename _CharT_alloc_type::const_reference const_reference; 00068 typedef typename _CharT_alloc_type::pointer pointer; 00069 typedef typename _CharT_alloc_type::const_pointer const_pointer; 00070 typedef __gnu_cxx::__normal_iterator<pointer, __versa_string> iterator; 00071 typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string> 00072 const_iterator; 00073 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 00074 typedef std::reverse_iterator<iterator> reverse_iterator; 00075 00076 // Data Member (public): 00077 /// Value returned by various member functions when they fail. 00078 static const size_type npos = static_cast<size_type>(-1); 00079 00080 private: 00081 size_type 00082 _M_check(size_type __pos, const char* __s) const 00083 { 00084 if (__pos > this->size()) 00085 std::__throw_out_of_range(__N(__s)); 00086 return __pos; 00087 } 00088 00089 void 00090 _M_check_length(size_type __n1, size_type __n2, const char* __s) const 00091 { 00092 if (this->max_size() - (this->size() - __n1) < __n2) 00093 std::__throw_length_error(__N(__s)); 00094 } 00095 00096 // NB: _M_limit doesn't check for a bad __pos value. 00097 size_type 00098 _M_limit(size_type __pos, size_type __off) const 00099 { 00100 const bool __testoff = __off < this->size() - __pos; 00101 return __testoff ? __off : this->size() - __pos; 00102 } 00103 00104 // True if _Rep and source do not overlap. 00105 bool 00106 _M_disjunct(const _CharT* __s) const 00107 { 00108 return (std::less<const _CharT*>()(__s, this->_M_data()) 00109 || std::less<const _CharT*>()(this->_M_data() 00110 + this->size(), __s)); 00111 } 00112 00113 // For the internal use we have functions similar to `begin'/`end' 00114 // but they do not call _M_leak. 00115 iterator 00116 _M_ibegin() const 00117 { return iterator(this->_M_data()); } 00118 00119 iterator 00120 _M_iend() const 00121 { return iterator(this->_M_data() + this->_M_length()); } 00122 00123 public: 00124 // Construct/copy/destroy: 00125 // NB: We overload ctors in some cases instead of using default 00126 // arguments, per 17.4.4.4 para. 2 item 2. 00127 00128 /** 00129 * @brief Default constructor creates an empty string. 00130 */ 00131 __versa_string() 00132 : __vstring_base() { } 00133 00134 /** 00135 * @brief Construct an empty string using allocator @a a. 00136 */ 00137 explicit 00138 __versa_string(const _Alloc& __a) 00139 : __vstring_base(__a) { } 00140 00141 // NB: per LWG issue 42, semantics different from IS: 00142 /** 00143 * @brief Construct string with copy of value of @a str. 00144 * @param str Source string. 00145 */ 00146 __versa_string(const __versa_string& __str) 00147 : __vstring_base(__str) { } 00148 00149 /** 00150 * @brief Construct string as copy of a substring. 00151 * @param str Source string. 00152 * @param pos Index of first character to copy from. 00153 * @param n Number of characters to copy (default remainder). 00154 */ 00155 __versa_string(const __versa_string& __str, size_type __pos, 00156 size_type __n = npos) 00157 : __vstring_base(__str._M_data() 00158 + __str._M_check(__pos, 00159 "__versa_string::__versa_string"), 00160 __str._M_data() + __str._M_limit(__pos, __n) 00161 + __pos, _Alloc()) { } 00162 00163 /** 00164 * @brief Construct string as copy of a substring. 00165 * @param str Source string. 00166 * @param pos Index of first character to copy from. 00167 * @param n Number of characters to copy. 00168 * @param a Allocator to use. 00169 */ 00170 __versa_string(const __versa_string& __str, size_type __pos, 00171 size_type __n, const _Alloc& __a) 00172 : __vstring_base(__str._M_data() 00173 + __str._M_check(__pos, 00174 "__versa_string::__versa_string"), 00175 __str._M_data() + __str._M_limit(__pos, __n) 00176 + __pos, __a) { } 00177 00178 /** 00179 * @brief Construct string initialized by a character array. 00180 * @param s Source character array. 00181 * @param n Number of characters to copy. 00182 * @param a Allocator to use (default is default allocator). 00183 * 00184 * NB: @a s must have at least @a n characters, '\0' has no special 00185 * meaning. 00186 */ 00187 __versa_string(const _CharT* __s, size_type __n, 00188 const _Alloc& __a = _Alloc()) 00189 : __vstring_base(__s, __s + __n, __a) { } 00190 00191 /** 00192 * @brief Construct string as copy of a C string. 00193 * @param s Source C string. 00194 * @param a Allocator to use (default is default allocator). 00195 */ 00196 __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc()) 00197 : __vstring_base(__s, __s ? __s + traits_type::length(__s) : 00198 __s + npos, __a) { } 00199 00200 /** 00201 * @brief Construct string as multiple characters. 00202 * @param n Number of characters. 00203 * @param c Character to use. 00204 * @param a Allocator to use (default is default allocator). 00205 */ 00206 __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()) 00207 : __vstring_base(__n, __c, __a) { } 00208 00209 /** 00210 * @brief Construct string as copy of a range. 00211 * @param beg Start of range. 00212 * @param end End of range. 00213 * @param a Allocator to use (default is default allocator). 00214 */ 00215 template<class _InputIterator> 00216 __versa_string(_InputIterator __beg, _InputIterator __end, 00217 const _Alloc& __a = _Alloc()) 00218 : __vstring_base(__beg, __end, __a) { } 00219 00220 /** 00221 * @brief Destroy the string instance. 00222 */ 00223 ~__versa_string() { } 00224 00225 /** 00226 * @brief Assign the value of @a str to this string. 00227 * @param str Source string. 00228 */ 00229 __versa_string& 00230 operator=(const __versa_string& __str) 00231 { return this->assign(__str); } 00232 00233 /** 00234 * @brief Copy contents of @a s into this string. 00235 * @param s Source null-terminated string. 00236 */ 00237 __versa_string& 00238 operator=(const _CharT* __s) 00239 { return this->assign(__s); } 00240 00241 /** 00242 * @brief Set value to string of length 1. 00243 * @param c Source character. 00244 * 00245 * Assigning to a character makes this string length 1 and 00246 * (*this)[0] == @a c. 00247 */ 00248 __versa_string& 00249 operator=(_CharT __c) 00250 { 00251 this->assign(1, __c); 00252 return *this; 00253 } 00254 00255 // Iterators: 00256 /** 00257 * Returns a read/write iterator that points to the first character in 00258 * the %string. Unshares the string. 00259 */ 00260 iterator 00261 begin() 00262 { 00263 this->_M_leak(); 00264 return iterator(this->_M_data()); 00265 } 00266 00267 /** 00268 * Returns a read-only (constant) iterator that points to the first 00269 * character in the %string. 00270 */ 00271 const_iterator 00272 begin() const 00273 { return const_iterator(this->_M_data()); } 00274 00275 /** 00276 * Returns a read/write iterator that points one past the last 00277 * character in the %string. Unshares the string. 00278 */ 00279 iterator 00280 end() 00281 { 00282 this->_M_leak(); 00283 return iterator(this->_M_data() + this->size()); 00284 } 00285 00286 /** 00287 * Returns a read-only (constant) iterator that points one past the 00288 * last character in the %string. 00289 */ 00290 const_iterator 00291 end() const 00292 { return const_iterator(this->_M_data() + this->size()); } 00293 00294 /** 00295 * Returns a read/write reverse iterator that points to the last 00296 * character in the %string. Iteration is done in reverse element 00297 * order. Unshares the string. 00298 */ 00299 reverse_iterator 00300 rbegin() 00301 { return reverse_iterator(this->end()); } 00302 00303 /** 00304 * Returns a read-only (constant) reverse iterator that points 00305 * to the last character in the %string. Iteration is done in 00306 * reverse element order. 00307 */ 00308 const_reverse_iterator 00309 rbegin() const 00310 { return const_reverse_iterator(this->end()); } 00311 00312 /** 00313 * Returns a read/write reverse iterator that points to one before the 00314 * first character in the %string. Iteration is done in reverse 00315 * element order. Unshares the string. 00316 */ 00317 reverse_iterator 00318 rend() 00319 { return reverse_iterator(this->begin()); } 00320 00321 /** 00322 * Returns a read-only (constant) reverse iterator that points 00323 * to one before the first character in the %string. Iteration 00324 * is done in reverse element order. 00325 */ 00326 const_reverse_iterator 00327 rend() const 00328 { return const_reverse_iterator(this->begin()); } 00329 00330 public: 00331 // Capacity: 00332 /// Returns the number of characters in the string, not including any 00333 /// null-termination. 00334 size_type 00335 size() const 00336 { return this->_M_length(); } 00337 00338 /// Returns the number of characters in the string, not including any 00339 /// null-termination. 00340 size_type 00341 length() const 00342 { return this->_M_length(); } 00343 00344 /// Returns the size() of the largest possible %string. 00345 size_type 00346 max_size() const 00347 { return this->_M_max_size(); } 00348 00349 /** 00350 * @brief Resizes the %string to the specified number of characters. 00351 * @param n Number of characters the %string should contain. 00352 * @param c Character to fill any new elements. 00353 * 00354 * This function will %resize the %string to the specified 00355 * number of characters. If the number is smaller than the 00356 * %string's current size the %string is truncated, otherwise 00357 * the %string is extended and new elements are set to @a c. 00358 */ 00359 void 00360 resize(size_type __n, _CharT __c); 00361 00362 /** 00363 * @brief Resizes the %string to the specified number of characters. 00364 * @param n Number of characters the %string should contain. 00365 * 00366 * This function will resize the %string to the specified length. If 00367 * the new size is smaller than the %string's current size the %string 00368 * is truncated, otherwise the %string is extended and new characters 00369 * are default-constructed. For basic types such as char, this means 00370 * setting them to 0. 00371 */ 00372 void 00373 resize(size_type __n) 00374 { this->resize(__n, _CharT()); } 00375 00376 /** 00377 * Returns the total number of characters that the %string can hold 00378 * before needing to allocate more memory. 00379 */ 00380 size_type 00381 capacity() const 00382 { return this->_M_capacity(); } 00383 00384 /** 00385 * @brief Attempt to preallocate enough memory for specified number of 00386 * characters. 00387 * @param res_arg Number of characters required. 00388 * @throw std::length_error If @a res_arg exceeds @c max_size(). 00389 * 00390 * This function attempts to reserve enough memory for the 00391 * %string to hold the specified number of characters. If the 00392 * number requested is more than max_size(), length_error is 00393 * thrown. 00394 * 00395 * The advantage of this function is that if optimal code is a 00396 * necessity and the user can determine the string length that will be 00397 * required, the user can reserve the memory in %advance, and thus 00398 * prevent a possible reallocation of memory and copying of %string 00399 * data. 00400 */ 00401 void 00402 reserve(size_type __res_arg = 0) 00403 { this->_M_reserve(__res_arg); } 00404 00405 /** 00406 * Erases the string, making it empty. 00407 */ 00408 void 00409 clear() 00410 { this->_M_clear(); } 00411 00412 /** 00413 * Returns true if the %string is empty. Equivalent to *this == "". 00414 */ 00415 bool 00416 empty() const 00417 { return this->size() == 0; } 00418 00419 // Element access: 00420 /** 00421 * @brief Subscript access to the data contained in the %string. 00422 * @param pos The index of the character to access. 00423 * @return Read-only (constant) reference to the character. 00424 * 00425 * This operator allows for easy, array-style, data access. 00426 * Note that data access with this operator is unchecked and 00427 * out_of_range lookups are not defined. (For checked lookups 00428 * see at().) 00429 */ 00430 const_reference 00431 operator[] (size_type __pos) const 00432 { 00433 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size()); 00434 return this->_M_data()[__pos]; 00435 } 00436 00437 /** 00438 * @brief Subscript access to the data contained in the %string. 00439 * @param pos The index of the character to access. 00440 * @return Read/write reference to the character. 00441 * 00442 * This operator allows for easy, array-style, data access. 00443 * Note that data access with this operator is unchecked and 00444 * out_of_range lookups are not defined. (For checked lookups 00445 * see at().) Unshares the string. 00446 */ 00447 reference 00448 operator[](size_type __pos) 00449 { 00450 // allow pos == size() as v3 extension: 00451 _GLIBCXX_DEBUG_ASSERT(__pos <= this->size()); 00452 // but be strict in pedantic mode: 00453 _GLIBCXX_DEBUG_PEDASSERT(__pos < this->size()); 00454 this->_M_leak(); 00455 return this->_M_data()[__pos]; 00456 } 00457 00458 /** 00459 * @brief Provides access to the data contained in the %string. 00460 * @param n The index of the character to access. 00461 * @return Read-only (const) reference to the character. 00462 * @throw std::out_of_range If @a n is an invalid index. 00463 * 00464 * This function provides for safer data access. The parameter is 00465 * first checked that it is in the range of the string. The function 00466 * throws out_of_range if the check fails. 00467 */ 00468 const_reference 00469 at(size_type __n) const 00470 { 00471 if (__n >= this->size()) 00472 std::__throw_out_of_range(__N("__versa_string::at")); 00473 return this->_M_data()[__n]; 00474 } 00475 00476 /** 00477 * @brief Provides access to the data contained in the %string. 00478 * @param n The index of the character to access. 00479 * @return Read/write reference to the character. 00480 * @throw std::out_of_range If @a n is an invalid index. 00481 * 00482 * This function provides for safer data access. The parameter is 00483 * first checked that it is in the range of the string. The function 00484 * throws out_of_range if the check fails. Success results in 00485 * unsharing the string. 00486 */ 00487 reference 00488 at(size_type __n) 00489 { 00490 if (__n >= this->size()) 00491 std::__throw_out_of_range(__N("__versa_string::at")); 00492 this->_M_leak(); 00493 return this->_M_data()[__n]; 00494 } 00495 00496 // Modifiers: 00497 /** 00498 * @brief Append a string to this string. 00499 * @param str The string to append. 00500 * @return Reference to this string. 00501 */ 00502 __versa_string& 00503 operator+=(const __versa_string& __str) 00504 { return this->append(__str); } 00505 00506 /** 00507 * @brief Append a C string. 00508 * @param s The C string to append. 00509 * @return Reference to this string. 00510 */ 00511 __versa_string& 00512 operator+=(const _CharT* __s) 00513 { return this->append(__s); } 00514 00515 /** 00516 * @brief Append a character. 00517 * @param c The character to append. 00518 * @return Reference to this string. 00519 */ 00520 __versa_string& 00521 operator+=(_CharT __c) 00522 { 00523 this->push_back(__c); 00524 return *this; 00525 } 00526 00527 /** 00528 * @brief Append a string to this string. 00529 * @param str The string to append. 00530 * @return Reference to this string. 00531 */ 00532 __versa_string& 00533 append(const __versa_string& __str) 00534 { return _M_append(__str._M_data(), __str.size()); } 00535 00536 /** 00537 * @brief Append a substring. 00538 * @param str The string to append. 00539 * @param pos Index of the first character of str to append. 00540 * @param n The number of characters to append. 00541 * @return Reference to this string. 00542 * @throw std::out_of_range if @a pos is not a valid index. 00543 * 00544 * This function appends @a n characters from @a str starting at @a pos 00545 * to this string. If @a n is is larger than the number of available 00546 * characters in @a str, the remainder of @a str is appended. 00547 */ 00548 __versa_string& 00549 append(const __versa_string& __str, size_type __pos, size_type __n) 00550 { return _M_append(__str._M_data() 00551 + __str._M_check(__pos, "__versa_string::append"), 00552 __str._M_limit(__pos, __n)); } 00553 00554 /** 00555 * @brief Append a C substring. 00556 * @param s The C string to append. 00557 * @param n The number of characters to append. 00558 * @return Reference to this string. 00559 */ 00560 __versa_string& 00561 append(const _CharT* __s, size_type __n) 00562 { 00563 __glibcxx_requires_string_len(__s, __n); 00564 _M_check_length(size_type(0), __n, "__versa_string::append"); 00565 return _M_append(__s, __n); 00566 } 00567 00568 /** 00569 * @brief Append a C string. 00570 * @param s The C string to append. 00571 * @return Reference to this string. 00572 */ 00573 __versa_string& 00574 append(const _CharT* __s) 00575 { 00576 __glibcxx_requires_string(__s); 00577 const size_type __n = traits_type::length(__s); 00578 _M_check_length(size_type(0), __n, "__versa_string::append"); 00579 return _M_append(__s, __n); 00580 } 00581 00582 /** 00583 * @brief Append multiple characters. 00584 * @param n The number of characters to append. 00585 * @param c The character to use. 00586 * @return Reference to this string. 00587 * 00588 * Appends n copies of c to this string. 00589 */ 00590 __versa_string& 00591 append(size_type __n, _CharT __c) 00592 { return _M_replace_aux(this->size(), size_type(0), __n, __c); } 00593 00594 /** 00595 * @brief Append a range of characters. 00596 * @param first Iterator referencing the first character to append. 00597 * @param last Iterator marking the end of the range. 00598 * @return Reference to this string. 00599 * 00600 * Appends characters in the range [first,last) to this string. 00601 */ 00602 template<class _InputIterator> 00603 __versa_string& 00604 append(_InputIterator __first, _InputIterator __last) 00605 { return this->replace(_M_iend(), _M_iend(), __first, __last); } 00606 00607 /** 00608 * @brief Append a single character. 00609 * @param c Character to append. 00610 */ 00611 void 00612 push_back(_CharT __c) 00613 { 00614 const size_type __size = this->size(); 00615 if (__size + 1 > this->capacity() || this->_M_is_shared()) 00616 this->_M_mutate(__size, size_type(0), 0, size_type(1)); 00617 traits_type::assign(this->_M_data()[__size], __c); 00618 this->_M_set_length(__size + 1); 00619 } 00620 00621 /** 00622 * @brief Set value to contents of another string. 00623 * @param str Source string to use. 00624 * @return Reference to this string. 00625 */ 00626 __versa_string& 00627 assign(const __versa_string& __str) 00628 { 00629 this->_M_assign(__str); 00630 return *this; 00631 } 00632 00633 /** 00634 * @brief Set value to a substring of a string. 00635 * @param str The string to use. 00636 * @param pos Index of the first character of str. 00637 * @param n Number of characters to use. 00638 * @return Reference to this string. 00639 * @throw std::out_of_range if @a pos is not a valid index. 00640 * 00641 * This function sets this string to the substring of @a str consisting 00642 * of @a n characters at @a pos. If @a n is is larger than the number 00643 * of available characters in @a str, the remainder of @a str is used. 00644 */ 00645 __versa_string& 00646 assign(const __versa_string& __str, size_type __pos, size_type __n) 00647 { return _M_replace(size_type(0), this->size(), __str._M_data() 00648 + __str._M_check(__pos, "__versa_string::assign"), 00649 __str._M_limit(__pos, __n)); } 00650 00651 /** 00652 * @brief Set value to a C substring. 00653 * @param s The C string to use. 00654 * @param n Number of characters to use. 00655 * @return Reference to this string. 00656 * 00657 * This function sets the value of this string to the first @a n 00658 * characters of @a s. If @a n is is larger than the number of 00659 * available characters in @a s, the remainder of @a s is used. 00660 */ 00661 __versa_string& 00662 assign(const _CharT* __s, size_type __n) 00663 { 00664 __glibcxx_requires_string_len(__s, __n); 00665 return _M_replace(size_type(0), this->size(), __s, __n); 00666 } 00667 00668 /** 00669 * @brief Set value to contents of a C string. 00670 * @param s The C string to use. 00671 * @return Reference to this string. 00672 * 00673 * This function sets the value of this string to the value of @a s. 00674 * The data is copied, so there is no dependence on @a s once the 00675 * function returns. 00676 */ 00677 __versa_string& 00678 assign(const _CharT* __s) 00679 { 00680 __glibcxx_requires_string(__s); 00681 return _M_replace(size_type(0), this->size(), __s, 00682 traits_type::length(__s)); 00683 } 00684 00685 /** 00686 * @brief Set value to multiple characters. 00687 * @param n Length of the resulting string. 00688 * @param c The character to use. 00689 * @return Reference to this string. 00690 * 00691 * This function sets the value of this string to @a n copies of 00692 * character @a c. 00693 */ 00694 __versa_string& 00695 assign(size_type __n, _CharT __c) 00696 { return _M_replace_aux(size_type(0), this->size(), __n, __c); } 00697 00698 /** 00699 * @brief Set value to a range of characters. 00700 * @param first Iterator referencing the first character to append. 00701 * @param last Iterator marking the end of the range. 00702 * @return Reference to this string. 00703 * 00704 * Sets value of string to characters in the range [first,last). 00705 */ 00706 template<class _InputIterator> 00707 __versa_string& 00708 assign(_InputIterator __first, _InputIterator __last) 00709 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); } 00710 00711 /** 00712 * @brief Insert multiple characters. 00713 * @param p Iterator referencing location in string to insert at. 00714 * @param n Number of characters to insert 00715 * @param c The character to insert. 00716 * @throw std::length_error If new length exceeds @c max_size(). 00717 * 00718 * Inserts @a n copies of character @a c starting at the position 00719 * referenced by iterator @a p. If adding characters causes the length 00720 * to exceed max_size(), length_error is thrown. The value of the 00721 * string doesn't change if an error is thrown. 00722 */ 00723 void 00724 insert(iterator __p, size_type __n, _CharT __c) 00725 { this->replace(__p, __p, __n, __c); } 00726 00727 /** 00728 * @brief Insert a range of characters. 00729 * @param p Iterator referencing location in string to insert at. 00730 * @param beg Start of range. 00731 * @param end End of range. 00732 * @throw std::length_error If new length exceeds @c max_size(). 00733 * 00734 * Inserts characters in range [beg,end). If adding characters causes 00735 * the length to exceed max_size(), length_error is thrown. The value 00736 * of the string doesn't change if an error is thrown. 00737 */ 00738 template<class _InputIterator> 00739 void 00740 insert(iterator __p, _InputIterator __beg, _InputIterator __end) 00741 { this->replace(__p, __p, __beg, __end); } 00742 00743 /** 00744 * @brief Insert value of a string. 00745 * @param pos1 Iterator referencing location in string to insert at. 00746 * @param str The string to insert. 00747 * @return Reference to this string. 00748 * @throw std::length_error If new length exceeds @c max_size(). 00749 * 00750 * Inserts value of @a str starting at @a pos1. If adding characters 00751 * causes the length to exceed max_size(), length_error is thrown. The 00752 * value of the string doesn't change if an error is thrown. 00753 */ 00754 __versa_string& 00755 insert(size_type __pos1, const __versa_string& __str) 00756 { return this->replace(__pos1, size_type(0), 00757 __str._M_data(), __str.size()); } 00758 00759 /** 00760 * @brief Insert a substring. 00761 * @param pos1 Iterator referencing location in string to insert at. 00762 * @param str The string to insert. 00763 * @param pos2 Start of characters in str to insert. 00764 * @param n Number of characters to insert. 00765 * @return Reference to this string. 00766 * @throw std::length_error If new length exceeds @c max_size(). 00767 * @throw std::out_of_range If @a pos1 > size() or 00768 * @a pos2 > @a str.size(). 00769 * 00770 * Starting at @a pos1, insert @a n character of @a str beginning with 00771 * @a pos2. If adding characters causes the length to exceed 00772 * max_size(), length_error is thrown. If @a pos1 is beyond the end of 00773 * this string or @a pos2 is beyond the end of @a str, out_of_range is 00774 * thrown. The value of the string doesn't change if an error is 00775 * thrown. 00776 */ 00777 __versa_string& 00778 insert(size_type __pos1, const __versa_string& __str, 00779 size_type __pos2, size_type __n) 00780 { return this->replace(__pos1, size_type(0), __str._M_data() 00781 + __str._M_check(__pos2, "__versa_string::insert"), 00782 __str._M_limit(__pos2, __n)); } 00783 00784 /** 00785 * @brief Insert a C substring. 00786 * @param pos Iterator referencing location in string to insert at. 00787 * @param s The C string to insert. 00788 * @param n The number of characters to insert. 00789 * @return Reference to this string. 00790 * @throw std::length_error If new length exceeds @c max_size(). 00791 * @throw std::out_of_range If @a pos is beyond the end of this 00792 * string. 00793 * 00794 * Inserts the first @a n characters of @a s starting at @a pos. If 00795 * adding characters causes the length to exceed max_size(), 00796 * length_error is thrown. If @a pos is beyond end(), out_of_range is 00797 * thrown. The value of the string doesn't change if an error is 00798 * thrown. 00799 */ 00800 __versa_string& 00801 insert(size_type __pos, const _CharT* __s, size_type __n) 00802 { return this->replace(__pos, size_type(0), __s, __n); } 00803 00804 /** 00805 * @brief Insert a C string. 00806 * @param pos Iterator referencing location in string to insert at. 00807 * @param s The C string to insert. 00808 * @return Reference to this string. 00809 * @throw std::length_error If new length exceeds @c max_size(). 00810 * @throw std::out_of_range If @a pos is beyond the end of this 00811 * string. 00812 * 00813 * Inserts the first @a n characters of @a s starting at @a pos. If 00814 * adding characters causes the length to exceed max_size(), 00815 * length_error is thrown. If @a pos is beyond end(), out_of_range is 00816 * thrown. The value of the string doesn't change if an error is 00817 * thrown. 00818 */ 00819 __versa_string& 00820 insert(size_type __pos, const _CharT* __s) 00821 { 00822 __glibcxx_requires_string(__s); 00823 return this->replace(__pos, size_type(0), __s, 00824 traits_type::length(__s)); 00825 } 00826 00827 /** 00828 * @brief Insert multiple characters. 00829 * @param pos Index in string to insert at. 00830 * @param n Number of characters to insert 00831 * @param c The character to insert. 00832 * @return Reference to this string. 00833 * @throw std::length_error If new length exceeds @c max_size(). 00834 * @throw std::out_of_range If @a pos is beyond the end of this 00835 * string. 00836 * 00837 * Inserts @a n copies of character @a c starting at index @a pos. If 00838 * adding characters causes the length to exceed max_size(), 00839 * length_error is thrown. If @a pos > length(), out_of_range is 00840 * thrown. The value of the string doesn't change if an error is 00841 * thrown. 00842 */ 00843 __versa_string& 00844 insert(size_type __pos, size_type __n, _CharT __c) 00845 { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"), 00846 size_type(0), __n, __c); } 00847 00848 /** 00849 * @brief Insert one character. 00850 * @param p Iterator referencing position in string to insert at. 00851 * @param c The character to insert. 00852 * @return Iterator referencing newly inserted char. 00853 * @throw std::length_error If new length exceeds @c max_size(). 00854 * 00855 * Inserts character @a c at position referenced by @a p. If adding 00856 * character causes the length to exceed max_size(), length_error is 00857 * thrown. If @a p is beyond end of string, out_of_range is thrown. 00858 * The value of the string doesn't change if an error is thrown. 00859 */ 00860 iterator 00861 insert(iterator __p, _CharT __c) 00862 { 00863 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); 00864 const size_type __pos = __p - _M_ibegin(); 00865 _M_replace_aux(__pos, size_type(0), size_type(1), __c); 00866 this->_M_set_leaked(); 00867 return iterator(this->_M_data() + __pos); 00868 } 00869 00870 /** 00871 * @brief Remove characters. 00872 * @param pos Index of first character to remove (default 0). 00873 * @param n Number of characters to remove (default remainder). 00874 * @return Reference to this string. 00875 * @throw std::out_of_range If @a pos is beyond the end of this 00876 * string. 00877 * 00878 * Removes @a n characters from this string starting at @a pos. The 00879 * length of the string is reduced by @a n. If there are < @a n 00880 * characters to remove, the remainder of the string is truncated. If 00881 * @a p is beyond end of string, out_of_range is thrown. The value of 00882 * the string doesn't change if an error is thrown. 00883 */ 00884 __versa_string& 00885 erase(size_type __pos = 0, size_type __n = npos) 00886 { 00887 this->_M_erase(_M_check(__pos, "__versa_string::erase"), 00888 _M_limit(__pos, __n)); 00889 return *this; 00890 } 00891 00892 /** 00893 * @brief Remove one character. 00894 * @param position Iterator referencing the character to remove. 00895 * @return iterator referencing same location after removal. 00896 * 00897 * Removes the character at @a position from this string. The value 00898 * of the string doesn't change if an error is thrown. 00899 */ 00900 iterator 00901 erase(iterator __position) 00902 { 00903 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin() 00904 && __position < _M_iend()); 00905 const size_type __pos = __position - _M_ibegin(); 00906 this->_M_erase(__pos, size_type(1)); 00907 this->_M_set_leaked(); 00908 return iterator(this->_M_data() + __pos); 00909 } 00910 00911 /** 00912 * @brief Remove a range of characters. 00913 * @param first Iterator referencing the first character to remove. 00914 * @param last Iterator referencing the end of the range. 00915 * @return Iterator referencing location of first after removal. 00916 * 00917 * Removes the characters in the range [first,last) from this string. 00918 * The value of the string doesn't change if an error is thrown. 00919 */ 00920 iterator 00921 erase(iterator __first, iterator __last) 00922 { 00923 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last 00924 && __last <= _M_iend()); 00925 const size_type __pos = __first - _M_ibegin(); 00926 this->_M_erase(__pos, __last - __first); 00927 this->_M_set_leaked(); 00928 return iterator(this->_M_data() + __pos); 00929 } 00930 00931 /** 00932 * @brief Replace characters with value from another string. 00933 * @param pos Index of first character to replace. 00934 * @param n Number of characters to be replaced. 00935 * @param str String to insert. 00936 * @return Reference to this string. 00937 * @throw std::out_of_range If @a pos is beyond the end of this 00938 * string. 00939 * @throw std::length_error If new length exceeds @c max_size(). 00940 * 00941 * Removes the characters in the range [pos,pos+n) from this string. 00942 * In place, the value of @a str is inserted. If @a pos is beyond end 00943 * of string, out_of_range is thrown. If the length of the result 00944 * exceeds max_size(), length_error is thrown. The value of the string 00945 * doesn't change if an error is thrown. 00946 */ 00947 __versa_string& 00948 replace(size_type __pos, size_type __n, const __versa_string& __str) 00949 { return this->replace(__pos, __n, __str._M_data(), __str.size()); } 00950 00951 /** 00952 * @brief Replace characters with value from another string. 00953 * @param pos1 Index of first character to replace. 00954 * @param n1 Number of characters to be replaced. 00955 * @param str String to insert. 00956 * @param pos2 Index of first character of str to use. 00957 * @param n2 Number of characters from str to use. 00958 * @return Reference to this string. 00959 * @throw std::out_of_range If @a pos1 > size() or @a pos2 > 00960 * str.size(). 00961 * @throw std::length_error If new length exceeds @c max_size(). 00962 * 00963 * Removes the characters in the range [pos1,pos1 + n) from this 00964 * string. In place, the value of @a str is inserted. If @a pos is 00965 * beyond end of string, out_of_range is thrown. If the length of the 00966 * result exceeds max_size(), length_error is thrown. The value of the 00967 * string doesn't change if an error is thrown. 00968 */ 00969 __versa_string& 00970 replace(size_type __pos1, size_type __n1, const __versa_string& __str, 00971 size_type __pos2, size_type __n2) 00972 { 00973 return this->replace(__pos1, __n1, __str._M_data() 00974 + __str._M_check(__pos2, 00975 "__versa_string::replace"), 00976 __str._M_limit(__pos2, __n2)); 00977 } 00978 00979 /** 00980 * @brief Replace characters with value of a C substring. 00981 * @param pos Index of first character to replace. 00982 * @param n1 Number of characters to be replaced. 00983 * @param s C string to insert. 00984 * @param n2 Number of characters from @a s to use. 00985 * @return Reference to this string. 00986 * @throw std::out_of_range If @a pos1 > size(). 00987 * @throw std::length_error If new length exceeds @c max_size(). 00988 * 00989 * Removes the characters in the range [pos,pos + n1) from this string. 00990 * In place, the first @a n2 characters of @a s are inserted, or all 00991 * of @a s if @a n2 is too large. If @a pos is beyond end of string, 00992 * out_of_range is thrown. If the length of result exceeds max_size(), 00993 * length_error is thrown. The value of the string doesn't change if 00994 * an error is thrown. 00995 */ 00996 __versa_string& 00997 replace(size_type __pos, size_type __n1, const _CharT* __s, 00998 size_type __n2) 00999 { 01000 __glibcxx_requires_string_len(__s, __n2); 01001 return _M_replace(_M_check(__pos, "__versa_string::replace"), 01002 _M_limit(__pos, __n1), __s, __n2); 01003 } 01004 01005 /** 01006 * @brief Replace characters with value of a C string. 01007 * @param pos Index of first character to replace. 01008 * @param n1 Number of characters to be replaced. 01009 * @param s C string to insert. 01010 * @return Reference to this string. 01011 * @throw std::out_of_range If @a pos > size(). 01012 * @throw std::length_error If new length exceeds @c max_size(). 01013 * 01014 * Removes the characters in the range [pos,pos + n1) from this string. 01015 * In place, the first @a n characters of @a s are inserted. If @a 01016 * pos is beyond end of string, out_of_range is thrown. If the length 01017 * of result exceeds max_size(), length_error is thrown. The value of 01018 * the string doesn't change if an error is thrown. 01019 */ 01020 __versa_string& 01021 replace(size_type __pos, size_type __n1, const _CharT* __s) 01022 { 01023 __glibcxx_requires_string(__s); 01024 return this->replace(__pos, __n1, __s, traits_type::length(__s)); 01025 } 01026 01027 /** 01028 * @brief Replace characters with multiple characters. 01029 * @param pos Index of first character to replace. 01030 * @param n1 Number of characters to be replaced. 01031 * @param n2 Number of characters to insert. 01032 * @param c Character to insert. 01033 * @return Reference to this string. 01034 * @throw std::out_of_range If @a pos > size(). 01035 * @throw std::length_error If new length exceeds @c max_size(). 01036 * 01037 * Removes the characters in the range [pos,pos + n1) from this string. 01038 * In place, @a n2 copies of @a c are inserted. If @a pos is beyond 01039 * end of string, out_of_range is thrown. If the length of result 01040 * exceeds max_size(), length_error is thrown. The value of the string 01041 * doesn't change if an error is thrown. 01042 */ 01043 __versa_string& 01044 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) 01045 { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"), 01046 _M_limit(__pos, __n1), __n2, __c); } 01047 01048 /** 01049 * @brief Replace range of characters with string. 01050 * @param i1 Iterator referencing start of range to replace. 01051 * @param i2 Iterator referencing end of range to replace. 01052 * @param str String value to insert. 01053 * @return Reference to this string. 01054 * @throw std::length_error If new length exceeds @c max_size(). 01055 * 01056 * Removes the characters in the range [i1,i2). In place, the value of 01057 * @a str is inserted. If the length of result exceeds max_size(), 01058 * length_error is thrown. The value of the string doesn't change if 01059 * an error is thrown. 01060 */ 01061 __versa_string& 01062 replace(iterator __i1, iterator __i2, const __versa_string& __str) 01063 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } 01064 01065 /** 01066 * @brief Replace range of characters with C substring. 01067 * @param i1 Iterator referencing start of range to replace. 01068 * @param i2 Iterator referencing end of range to replace. 01069 * @param s C string value to insert. 01070 * @param n Number of characters from s to insert. 01071 * @return Reference to this string. 01072 * @throw std::length_error If new length exceeds @c max_size(). 01073 * 01074 * Removes the characters in the range [i1,i2). In place, the first @a 01075 * n characters of @a s are inserted. If the length of result exceeds 01076 * max_size(), length_error is thrown. The value of the string doesn't 01077 * change if an error is thrown. 01078 */ 01079 __versa_string& 01080 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) 01081 { 01082 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 01083 && __i2 <= _M_iend()); 01084 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n); 01085 } 01086 01087 /** 01088 * @brief Replace range of characters with C string. 01089 * @param i1 Iterator referencing start of range to replace. 01090 * @param i2 Iterator referencing end of range to replace. 01091 * @param s C string value to insert. 01092 * @return Reference to this string. 01093 * @throw std::length_error If new length exceeds @c max_size(). 01094 * 01095 * Removes the characters in the range [i1,i2). In place, the 01096 * characters of @a s are inserted. If the length of result exceeds 01097 * max_size(), length_error is thrown. The value of the string doesn't 01098 * change if an error is thrown. 01099 */ 01100 __versa_string& 01101 replace(iterator __i1, iterator __i2, const _CharT* __s) 01102 { 01103 __glibcxx_requires_string(__s); 01104 return this->replace(__i1, __i2, __s, traits_type::length(__s)); 01105 } 01106 01107 /** 01108 * @brief Replace range of characters with multiple characters 01109 * @param i1 Iterator referencing start of range to replace. 01110 * @param i2 Iterator referencing end of range to replace. 01111 * @param n Number of characters to insert. 01112 * @param c Character to insert. 01113 * @return Reference to this string. 01114 * @throw std::length_error If new length exceeds @c max_size(). 01115 * 01116 * Removes the characters in the range [i1,i2). In place, @a n copies 01117 * of @a c are inserted. If the length of result exceeds max_size(), 01118 * length_error is thrown. The value of the string doesn't change if 01119 * an error is thrown. 01120 */ 01121 __versa_string& 01122 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c) 01123 { 01124 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 01125 && __i2 <= _M_iend()); 01126 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c); 01127 } 01128 01129 /** 01130 * @brief Replace range of characters with range. 01131 * @param i1 Iterator referencing start of range to replace. 01132 * @param i2 Iterator referencing end of range to replace. 01133 * @param k1 Iterator referencing start of range to insert. 01134 * @param k2 Iterator referencing end of range to insert. 01135 * @return Reference to this string. 01136 * @throw std::length_error If new length exceeds @c max_size(). 01137 * 01138 * Removes the characters in the range [i1,i2). In place, characters 01139 * in the range [k1,k2) are inserted. If the length of result exceeds 01140 * max_size(), length_error is thrown. The value of the string doesn't 01141 * change if an error is thrown. 01142 */ 01143 template<class _InputIterator> 01144 __versa_string& 01145 replace(iterator __i1, iterator __i2, 01146 _InputIterator __k1, _InputIterator __k2) 01147 { 01148 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 01149 && __i2 <= _M_iend()); 01150 __glibcxx_requires_valid_range(__k1, __k2); 01151 typedef typename std::__is_integer<_InputIterator>::__type _Integral; 01152 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); 01153 } 01154 01155 // Specializations for the common case of pointer and iterator: 01156 // useful to avoid the overhead of temporary buffering in _M_replace. 01157 __versa_string& 01158 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2) 01159 { 01160 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 01161 && __i2 <= _M_iend()); 01162 __glibcxx_requires_valid_range(__k1, __k2); 01163 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 01164 __k1, __k2 - __k1); 01165 } 01166 01167 __versa_string& 01168 replace(iterator __i1, iterator __i2, 01169 const _CharT* __k1, const _CharT* __k2) 01170 { 01171 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 01172 && __i2 <= _M_iend()); 01173 __glibcxx_requires_valid_range(__k1, __k2); 01174 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 01175 __k1, __k2 - __k1); 01176 } 01177 01178 __versa_string& 01179 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2) 01180 { 01181 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 01182 && __i2 <= _M_iend()); 01183 __glibcxx_requires_valid_range(__k1, __k2); 01184 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 01185 __k1.base(), __k2 - __k1); 01186 } 01187 01188 __versa_string& 01189 replace(iterator __i1, iterator __i2, 01190 const_iterator __k1, const_iterator __k2) 01191 { 01192 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 01193 && __i2 <= _M_iend()); 01194 __glibcxx_requires_valid_range(__k1, __k2); 01195 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 01196 __k1.base(), __k2 - __k1); 01197 } 01198 01199 private: 01200 template<class _Integer> 01201 __versa_string& 01202 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n, 01203 _Integer __val, std::__true_type) 01204 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); } 01205 01206 template<class _InputIterator> 01207 __versa_string& 01208 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1, 01209 _InputIterator __k2, std::__false_type); 01210 01211 __versa_string& 01212 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, 01213 _CharT __c); 01214 01215 __versa_string& 01216 _M_replace(size_type __pos, size_type __len1, const _CharT* __s, 01217 const size_type __len2); 01218 01219 __versa_string& 01220 _M_append(const _CharT* __s, size_type __n); 01221 01222 public: 01223 01224 /** 01225 * @brief Copy substring into C string. 01226 * @param s C string to copy value into. 01227 * @param n Number of characters to copy. 01228 * @param pos Index of first character to copy. 01229 * @return Number of characters actually copied 01230 * @throw std::out_of_range If pos > size(). 01231 * 01232 * Copies up to @a n characters starting at @a pos into the C string @a 01233 * s. If @a pos is greater than size(), out_of_range is thrown. 01234 */ 01235 size_type 01236 copy(_CharT* __s, size_type __n, size_type __pos = 0) const; 01237 01238 /** 01239 * @brief Swap contents with another string. 01240 * @param s String to swap with. 01241 * 01242 * Exchanges the contents of this string with that of @a s in constant 01243 * time. 01244 */ 01245 void 01246 swap(__versa_string& __s) 01247 { this->_M_swap(__s); } 01248 01249 // String operations: 01250 /** 01251 * @brief Return const pointer to null-terminated contents. 01252 * 01253 * This is a handle to internal data. Do not modify or dire things may 01254 * happen. 01255 */ 01256 const _CharT* 01257 c_str() const 01258 { return this->_M_data(); } 01259 01260 /** 01261 * @brief Return const pointer to contents. 01262 * 01263 * This is a handle to internal data. Do not modify or dire things may 01264 * happen. 01265 */ 01266 const _CharT* 01267 data() const 01268 { return this->_M_data(); } 01269 01270 /** 01271 * @brief Return copy of allocator used to construct this string. 01272 */ 01273 allocator_type 01274 get_allocator() const 01275 { return allocator_type(this->_M_get_allocator()); } 01276 01277 /** 01278 * @brief Find position of a C substring. 01279 * @param s C string to locate. 01280 * @param pos Index of character to search from. 01281 * @param n Number of characters from @a s to search for. 01282 * @return Index of start of first occurrence. 01283 * 01284 * Starting from @a pos, searches forward for the first @a n characters 01285 * in @a s within this string. If found, returns the index where it 01286 * begins. If not found, returns npos. 01287 */ 01288 size_type 01289 find(const _CharT* __s, size_type __pos, size_type __n) const; 01290 01291 /** 01292 * @brief Find position of a string. 01293 * @param str String to locate. 01294 * @param pos Index of character to search from (default 0). 01295 * @return Index of start of first occurrence. 01296 * 01297 * Starting from @a pos, searches forward for value of @a str within 01298 * this string. If found, returns the index where it begins. If not 01299 * found, returns npos. 01300 */ 01301 size_type 01302 find(const __versa_string& __str, size_type __pos = 0) const 01303 { return this->find(__str.data(), __pos, __str.size()); } 01304 01305 /** 01306 * @brief Find position of a C string. 01307 * @param s C string to locate. 01308 * @param pos Index of character to search from (default 0). 01309 * @return Index of start of first occurrence. 01310 * 01311 * Starting from @a pos, searches forward for the value of @a s within 01312 * this string. If found, returns the index where it begins. If not 01313 * found, returns npos. 01314 */ 01315 size_type 01316 find(const _CharT* __s, size_type __pos = 0) const 01317 { 01318 __glibcxx_requires_string(__s); 01319 return this->find(__s, __pos, traits_type::length(__s)); 01320 } 01321 01322 /** 01323 * @brief Find position of a character. 01324 * @param c Character to locate. 01325 * @param pos Index of character to search from (default 0). 01326 * @return Index of first occurrence. 01327 * 01328 * Starting from @a pos, searches forward for @a c within this string. 01329 * If found, returns the index where it was found. If not found, 01330 * returns npos. 01331 */ 01332 size_type 01333 find(_CharT __c, size_type __pos = 0) const; 01334 01335 /** 01336 * @brief Find last position of a string. 01337 * @param str String to locate. 01338 * @param pos Index of character to search back from (default end). 01339 * @return Index of start of last occurrence. 01340 * 01341 * Starting from @a pos, searches backward for value of @a str within 01342 * this string. If found, returns the index where it begins. If not 01343 * found, returns npos. 01344 */ 01345 size_type 01346 rfind(const __versa_string& __str, size_type __pos = npos) const 01347 { return this->rfind(__str.data(), __pos, __str.size()); } 01348 01349 /** 01350 * @brief Find last position of a C substring. 01351 * @param s C string to locate. 01352 * @param pos Index of character to search back from. 01353 * @param n Number of characters from s to search for. 01354 * @return Index of start of last occurrence. 01355 * 01356 * Starting from @a pos, searches backward for the first @a n 01357 * characters in @a s within this string. If found, returns the index 01358 * where it begins. If not found, returns npos. 01359 */ 01360 size_type 01361 rfind(const _CharT* __s, size_type __pos, size_type __n) const; 01362 01363 /** 01364 * @brief Find last position of a C string. 01365 * @param s C string to locate. 01366 * @param pos Index of character to start search at (default end). 01367 * @return Index of start of last occurrence. 01368 * 01369 * Starting from @a pos, searches backward for the value of @a s within 01370 * this string. If found, returns the index where it begins. If not 01371 * found, returns npos. 01372 */ 01373 size_type 01374 rfind(const _CharT* __s, size_type __pos = npos) const 01375 { 01376 __glibcxx_requires_string(__s); 01377 return this->rfind(__s, __pos, traits_type::length(__s)); 01378 } 01379 01380 /** 01381 * @brief Find last position of a character. 01382 * @param c Character to locate. 01383 * @param pos Index of character to search back from (default end). 01384 * @return Index of last occurrence. 01385 * 01386 * Starting from @a pos, searches backward for @a c within this string. 01387 * If found, returns the index where it was found. If not found, 01388 * returns npos. 01389 */ 01390 size_type 01391 rfind(_CharT __c, size_type __pos = npos) const; 01392 01393 /** 01394 * @brief Find position of a character of string. 01395 * @param str String containing characters to locate. 01396 * @param pos Index of character to search from (default 0). 01397 * @return Index of first occurrence. 01398 * 01399 * Starting from @a pos, searches forward for one of the characters of 01400 * @a str within this string. If found, returns the index where it was 01401 * found. If not found, returns npos. 01402 */ 01403 size_type 01404 find_first_of(const __versa_string& __str, size_type __pos = 0) const 01405 { return this->find_first_of(__str.data(), __pos, __str.size()); } 01406 01407 /** 01408 * @brief Find position of a character of C substring. 01409 * @param s String containing characters to locate. 01410 * @param pos Index of character to search from. 01411 * @param n Number of characters from s to search for. 01412 * @return Index of first occurrence. 01413 * 01414 * Starting from @a pos, searches forward for one of the first @a n 01415 * characters of @a s within this string. If found, returns the index 01416 * where it was found. If not found, returns npos. 01417 */ 01418 size_type 01419 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const; 01420 01421 /** 01422 * @brief Find position of a character of C string. 01423 * @param s String containing characters to locate. 01424 * @param pos Index of character to search from (default 0). 01425 * @return Index of first occurrence. 01426 * 01427 * Starting from @a pos, searches forward for one of the characters of 01428 * @a s within this string. If found, returns the index where it was 01429 * found. If not found, returns npos. 01430 */ 01431 size_type 01432 find_first_of(const _CharT* __s, size_type __pos = 0) const 01433 { 01434 __glibcxx_requires_string(__s); 01435 return this->find_first_of(__s, __pos, traits_type::length(__s)); 01436 } 01437 01438 /** 01439 * @brief Find position of a character. 01440 * @param c Character to locate. 01441 * @param pos Index of character to search from (default 0). 01442 * @return Index of first occurrence. 01443 * 01444 * Starting from @a pos, searches forward for the character @a c within 01445 * this string. If found, returns the index where it was found. If 01446 * not found, returns npos. 01447 * 01448 * Note: equivalent to find(c, pos). 01449 */ 01450 size_type 01451 find_first_of(_CharT __c, size_type __pos = 0) const 01452 { return this->find(__c, __pos); } 01453 01454 /** 01455 * @brief Find last position of a character of string. 01456 * @param str String containing characters to locate. 01457 * @param pos Index of character to search back from (default end). 01458 * @return Index of last occurrence. 01459 * 01460 * Starting from @a pos, searches backward for one of the characters of 01461 * @a str within this string. If found, returns the index where it was 01462 * found. If not found, returns npos. 01463 */ 01464 size_type 01465 find_last_of(const __versa_string& __str, size_type __pos = npos) const 01466 { return this->find_last_of(__str.data(), __pos, __str.size()); } 01467 01468 /** 01469 * @brief Find last position of a character of C substring. 01470 * @param s C string containing characters to locate. 01471 * @param pos Index of character to search back from. 01472 * @param n Number of characters from s to search for. 01473 * @return Index of last occurrence. 01474 * 01475 * Starting from @a pos, searches backward for one of the first @a n 01476 * characters of @a s within this string. If found, returns the index 01477 * where it was found. If not found, returns npos. 01478 */ 01479 size_type 01480 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const; 01481 01482 /** 01483 * @brief Find last position of a character of C string. 01484 * @param s C string containing characters to locate. 01485 * @param pos Index of character to search back from (default end). 01486 * @return Index of last occurrence. 01487 * 01488 * Starting from @a pos, searches backward for one of the characters of 01489 * @a s within this string. If found, returns the index where it was 01490 * found. If not found, returns npos. 01491 */ 01492 size_type 01493 find_last_of(const _CharT* __s, size_type __pos = npos) const 01494 { 01495 __glibcxx_requires_string(__s); 01496 return this->find_last_of(__s, __pos, traits_type::length(__s)); 01497 } 01498 01499 /** 01500 * @brief Find last position of a character. 01501 * @param c Character to locate. 01502 * @param pos Index of character to search back from (default end). 01503 * @return Index of last occurrence. 01504 * 01505 * Starting from @a pos, searches backward for @a c within this string. 01506 * If found, returns the index where it was found. If not found, 01507 * returns npos. 01508 * 01509 * Note: equivalent to rfind(c, pos). 01510 */ 01511 size_type 01512 find_last_of(_CharT __c, size_type __pos = npos) const 01513 { return this->rfind(__c, __pos); } 01514 01515 /** 01516 * @brief Find position of a character not in string. 01517 * @param str String containing characters to avoid. 01518 * @param pos Index of character to search from (default 0). 01519 * @return Index of first occurrence. 01520 * 01521 * Starting from @a pos, searches forward for a character not contained 01522 * in @a str within this string. If found, returns the index where it 01523 * was found. If not found, returns npos. 01524 */ 01525 size_type 01526 find_first_not_of(const __versa_string& __str, size_type __pos = 0) const 01527 { return this->find_first_not_of(__str.data(), __pos, __str.size()); } 01528 01529 /** 01530 * @brief Find position of a character not in C substring. 01531 * @param s C string containing characters to avoid. 01532 * @param pos Index of character to search from. 01533 * @param n Number of characters from s to consider. 01534 * @return Index of first occurrence. 01535 * 01536 * Starting from @a pos, searches forward for a character not contained 01537 * in the first @a n characters of @a s within this string. If found, 01538 * returns the index where it was found. If not found, returns npos. 01539 */ 01540 size_type 01541 find_first_not_of(const _CharT* __s, size_type __pos, 01542 size_type __n) const; 01543 01544 /** 01545 * @brief Find position of a character not in C string. 01546 * @param s C string containing characters to avoid. 01547 * @param pos Index of character to search from (default 0). 01548 * @return Index of first occurrence. 01549 * 01550 * Starting from @a pos, searches forward for a character not contained 01551 * in @a s within this string. If found, returns the index where it 01552 * was found. If not found, returns npos. 01553 */ 01554 size_type 01555 find_first_not_of(const _CharT* __s, size_type __pos = 0) const 01556 { 01557 __glibcxx_requires_string(__s); 01558 return this->find_first_not_of(__s, __pos, traits_type::length(__s)); 01559 } 01560 01561 /** 01562 * @brief Find position of a different character. 01563 * @param c Character to avoid. 01564 * @param pos Index of character to search from (default 0). 01565 * @return Index of first occurrence. 01566 * 01567 * Starting from @a pos, searches forward for a character other than @a c 01568 * within this string. If found, returns the index where it was found. 01569 * If not found, returns npos. 01570 */ 01571 size_type 01572 find_first_not_of(_CharT __c, size_type __pos = 0) const; 01573 01574 /** 01575 * @brief Find last position of a character not in string. 01576 * @param str String containing characters to avoid. 01577 * @param pos Index of character to search back from (default end). 01578 * @return Index of last occurrence. 01579 * 01580 * Starting from @a pos, searches backward for a character not 01581 * contained in @a str within this string. If found, returns the index 01582 * where it was found. If not found, returns npos. 01583 */ 01584 size_type 01585 find_last_not_of(const __versa_string& __str, 01586 size_type __pos = npos) const 01587 { return this->find_last_not_of(__str.data(), __pos, __str.size()); } 01588 01589 /** 01590 * @brief Find last position of a character not in C substring. 01591 * @param s C string containing characters to avoid. 01592 * @param pos Index of character to search back from. 01593 * @param n Number of characters from s to consider. 01594 * @return Index of last occurrence. 01595 * 01596 * Starting from @a pos, searches backward for a character not 01597 * contained in the first @a n characters of @a s within this string. 01598 * If found, returns the index where it was found. If not found, 01599 * returns npos. 01600 */ 01601 size_type 01602 find_last_not_of(const _CharT* __s, size_type __pos, 01603 size_type __n) const; 01604 /** 01605 * @brief Find last position of a character not in C string. 01606 * @param s C string containing characters to avoid. 01607 * @param pos Index of character to search back from (default end). 01608 * @return Index of last occurrence. 01609 * 01610 * Starting from @a pos, searches backward for a character not 01611 * contained in @a s within this string. If found, returns the index 01612 * where it was found. If not found, returns npos. 01613 */ 01614 size_type 01615 find_last_not_of(const _CharT* __s, size_type __pos = npos) const 01616 { 01617 __glibcxx_requires_string(__s); 01618 return this->find_last_not_of(__s, __pos, traits_type::length(__s)); 01619 } 01620 01621 /** 01622 * @brief Find last position of a different character. 01623 * @param c Character to avoid. 01624 * @param pos Index of character to search back from (default end). 01625 * @return Index of last occurrence. 01626 * 01627 * Starting from @a pos, searches backward for a character other than 01628 * @a c within this string. If found, returns the index where it was 01629 * found. If not found, returns npos. 01630 */ 01631 size_type 01632 find_last_not_of(_CharT __c, size_type __pos = npos) const; 01633 01634 /** 01635 * @brief Get a substring. 01636 * @param pos Index of first character (default 0). 01637 * @param n Number of characters in substring (default remainder). 01638 * @return The new string. 01639 * @throw std::out_of_range If pos > size(). 01640 * 01641 * Construct and return a new string using the @a n characters starting 01642 * at @a pos. If the string is too short, use the remainder of the 01643 * characters. If @a pos is beyond the end of the string, out_of_range 01644 * is thrown. 01645 */ 01646 __versa_string 01647 substr(size_type __pos = 0, size_type __n = npos) const 01648 { 01649 return __versa_string(*this, _M_check(__pos, "__versa_string::substr"), 01650 __n); 01651 } 01652 01653 /** 01654 * @brief Compare to a string. 01655 * @param str String to compare against. 01656 * @return Integer < 0, 0, or > 0. 01657 * 01658 * Returns an integer < 0 if this string is ordered before @a str, 0 if 01659 * their values are equivalent, or > 0 if this string is ordered after 01660 * @a str. Determines the effective length rlen of the strings to 01661 * compare as the smallest of size() and str.size(). The function 01662 * then compares the two strings by calling traits::compare(data(), 01663 * str.data(),rlen). If the result of the comparison is nonzero returns 01664 * it, otherwise the shorter one is ordered first. 01665 */ 01666 int 01667 compare(const __versa_string& __str) const 01668 { 01669 if (this->_M_compare(__str)) 01670 return 0; 01671 01672 const size_type __size = this->size(); 01673 const size_type __osize = __str.size(); 01674 const size_type __len = std::min(__size, __osize); 01675 01676 int __r = traits_type::compare(this->_M_data(), __str.data(), __len); 01677 if (!__r) 01678 __r = __size - __osize; 01679 return __r; 01680 } 01681 01682 /** 01683 * @brief Compare substring to a string. 01684 * @param pos Index of first character of substring. 01685 * @param n Number of characters in substring. 01686 * @param str String to compare against. 01687 * @return Integer < 0, 0, or > 0. 01688 * 01689 * Form the substring of this string from the @a n characters starting 01690 * at @a pos. Returns an integer < 0 if the substring is ordered 01691 * before @a str, 0 if their values are equivalent, or > 0 if the 01692 * substring is ordered after @a str. Determines the effective length 01693 * rlen of the strings to compare as the smallest of the length of the 01694 * substring and @a str.size(). The function then compares the two 01695 * strings by calling traits::compare(substring.data(),str.data(),rlen). 01696 * If the result of the comparison is nonzero returns it, otherwise the 01697 * shorter one is ordered first. 01698 */ 01699 int 01700 compare(size_type __pos, size_type __n, 01701 const __versa_string& __str) const; 01702 01703 /** 01704 * @brief Compare substring to a substring. 01705 * @param pos1 Index of first character of substring. 01706 * @param n1 Number of characters in substring. 01707 * @param str String to compare against. 01708 * @param pos2 Index of first character of substring of str. 01709 * @param n2 Number of characters in substring of str. 01710 * @return Integer < 0, 0, or > 0. 01711 * 01712 * Form the substring of this string from the @a n1 characters starting 01713 * at @a pos1. Form the substring of @a str from the @a n2 characters 01714 * starting at @a pos2. Returns an integer < 0 if this substring is 01715 * ordered before the substring of @a str, 0 if their values are 01716 * equivalent, or > 0 if this substring is ordered after the substring 01717 * of @a str. Determines the effective length rlen of the strings 01718 * to compare as the smallest of the lengths of the substrings. The 01719 * function then compares the two strings by calling 01720 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). 01721 * If the result of the comparison is nonzero returns it, otherwise the 01722 * shorter one is ordered first. 01723 */ 01724 int 01725 compare(size_type __pos1, size_type __n1, const __versa_string& __str, 01726 size_type __pos2, size_type __n2) const; 01727 01728 /** 01729 * @brief Compare to a C string. 01730 * @param s C string to compare against. 01731 * @return Integer < 0, 0, or > 0. 01732 * 01733 * Returns an integer < 0 if this string is ordered before @a s, 0 if 01734 * their values are equivalent, or > 0 if this string is ordered after 01735 * @a s. Determines the effective length rlen of the strings to 01736 * compare as the smallest of size() and the length of a string 01737 * constructed from @a s. The function then compares the two strings 01738 * by calling traits::compare(data(),s,rlen). If the result of the 01739 * comparison is nonzero returns it, otherwise the shorter one is 01740 * ordered first. 01741 */ 01742 int 01743 compare(const _CharT* __s) const; 01744 01745 // _GLIBCXX_RESOLVE_LIB_DEFECTS 01746 // 5 String::compare specification questionable 01747 /** 01748 * @brief Compare substring to a C string. 01749 * @param pos Index of first character of substring. 01750 * @param n1 Number of characters in substring. 01751 * @param s C string to compare against. 01752 * @return Integer < 0, 0, or > 0. 01753 * 01754 * Form the substring of this string from the @a n1 characters starting 01755 * at @a pos. Returns an integer < 0 if the substring is ordered 01756 * before @a s, 0 if their values are equivalent, or > 0 if the 01757 * substring is ordered after @a s. Determines the effective length 01758 * rlen of the strings to compare as the smallest of the length of the 01759 * substring and the length of a string constructed from @a s. The 01760 * function then compares the two string by calling 01761 * traits::compare(substring.data(),s,rlen). If the result of the 01762 * comparison is nonzero returns it, otherwise the shorter one is 01763 * ordered first. 01764 */ 01765 int 01766 compare(size_type __pos, size_type __n1, const _CharT* __s) const; 01767 01768 /** 01769 * @brief Compare substring against a character array. 01770 * @param pos1 Index of first character of substring. 01771 * @param n1 Number of characters in substring. 01772 * @param s character array to compare against. 01773 * @param n2 Number of characters of s. 01774 * @return Integer < 0, 0, or > 0. 01775 * 01776 * Form the substring of this string from the @a n1 characters starting 01777 * at @a pos1. Form a string from the first @a n2 characters of @a s. 01778 * Returns an integer < 0 if this substring is ordered before the string 01779 * from @a s, 0 if their values are equivalent, or > 0 if this substring 01780 * is ordered after the string from @a s. Determines the effective 01781 * length rlen of the strings to compare as the smallest of the length 01782 * of the substring and @a n2. The function then compares the two 01783 * strings by calling traits::compare(substring.data(),s,rlen). If the 01784 * result of the comparison is nonzero returns it, otherwise the shorter 01785 * one is ordered first. 01786 * 01787 * NB: s must have at least n2 characters, '\0' has no special 01788 * meaning. 01789 */ 01790 int 01791 compare(size_type __pos, size_type __n1, const _CharT* __s, 01792 size_type __n2) const; 01793 }; 01794 01795 // operator+ 01796 /** 01797 * @brief Concatenate two strings. 01798 * @param lhs First string. 01799 * @param rhs Last string. 01800 * @return New string with value of @a lhs followed by @a rhs. 01801 */ 01802 template<typename _CharT, typename _Traits, typename _Alloc, 01803 template <typename, typename, typename> class _Base> 01804 __versa_string<_CharT, _Traits, _Alloc, _Base> 01805 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 01806 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); 01807 01808 /** 01809 * @brief Concatenate C string and string. 01810 * @param lhs First string. 01811 * @param rhs Last string. 01812 * @return New string with value of @a lhs followed by @a rhs. 01813 */ 01814 template<typename _CharT, typename _Traits, typename _Alloc, 01815 template <typename, typename, typename> class _Base> 01816 __versa_string<_CharT, _Traits, _Alloc, _Base> 01817 operator+(const _CharT* __lhs, 01818 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); 01819 01820 /** 01821 * @brief Concatenate character and string. 01822 * @param lhs First string. 01823 * @param rhs Last string. 01824 * @return New string with @a lhs followed by @a rhs. 01825 */ 01826 template<typename _CharT, typename _Traits, typename _Alloc, 01827 template <typename, typename, typename> class _Base> 01828 __versa_string<_CharT, _Traits, _Alloc, _Base> 01829 operator+(_CharT __lhs, 01830 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); 01831 01832 /** 01833 * @brief Concatenate string and C string. 01834 * @param lhs First string. 01835 * @param rhs Last string. 01836 * @return New string with @a lhs followed by @a rhs. 01837 */ 01838 template<typename _CharT, typename _Traits, typename _Alloc, 01839 template <typename, typename, typename> class _Base> 01840 __versa_string<_CharT, _Traits, _Alloc, _Base> 01841 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 01842 const _CharT* __rhs); 01843 01844 /** 01845 * @brief Concatenate string and character. 01846 * @param lhs First string. 01847 * @param rhs Last string. 01848 * @return New string with @a lhs followed by @a rhs. 01849 */ 01850 template<typename _CharT, typename _Traits, typename _Alloc, 01851 template <typename, typename, typename> class _Base> 01852 __versa_string<_CharT, _Traits, _Alloc, _Base> 01853 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 01854 _CharT __rhs); 01855 01856 // operator == 01857 /** 01858 * @brief Test equivalence of two strings. 01859 * @param lhs First string. 01860 * @param rhs Second string. 01861 * @return True if @a lhs.compare(@a rhs) == 0. False otherwise. 01862 */ 01863 template<typename _CharT, typename _Traits, typename _Alloc, 01864 template <typename, typename, typename> class _Base> 01865 inline bool 01866 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 01867 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 01868 { return __lhs.compare(__rhs) == 0; } 01869 01870 /** 01871 * @brief Test equivalence of C string and string. 01872 * @param lhs C string. 01873 * @param rhs String. 01874 * @return True if @a rhs.compare(@a lhs) == 0. False otherwise. 01875 */ 01876 template<typename _CharT, typename _Traits, typename _Alloc, 01877 template <typename, typename, typename> class _Base> 01878 inline bool 01879 operator==(const _CharT* __lhs, 01880 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 01881 { return __rhs.compare(__lhs) == 0; } 01882 01883 /** 01884 * @brief Test equivalence of string and C string. 01885 * @param lhs String. 01886 * @param rhs C string. 01887 * @return True if @a lhs.compare(@a rhs) == 0. False otherwise. 01888 */ 01889 template<typename _CharT, typename _Traits, typename _Alloc, 01890 template <typename, typename, typename> class _Base> 01891 inline bool 01892 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 01893 const _CharT* __rhs) 01894 { return __lhs.compare(__rhs) == 0; } 01895 01896 // operator != 01897 /** 01898 * @brief Test difference of two strings. 01899 * @param lhs First string. 01900 * @param rhs Second string. 01901 * @return True if @a lhs.compare(@a rhs) != 0. False otherwise. 01902 */ 01903 template<typename _CharT, typename _Traits, typename _Alloc, 01904 template <typename, typename, typename> class _Base> 01905 inline bool 01906 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 01907 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 01908 { return __rhs.compare(__lhs) != 0; } 01909 01910 /** 01911 * @brief Test difference of C string and string. 01912 * @param lhs C string. 01913 * @param rhs String. 01914 * @return True if @a rhs.compare(@a lhs) != 0. False otherwise. 01915 */ 01916 template<typename _CharT, typename _Traits, typename _Alloc, 01917 template <typename, typename, typename> class _Base> 01918 inline bool 01919 operator!=(const _CharT* __lhs, 01920 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 01921 { return __rhs.compare(__lhs) != 0; } 01922 01923 /** 01924 * @brief Test difference of string and C string. 01925 * @param lhs String. 01926 * @param rhs C string. 01927 * @return True if @a lhs.compare(@a rhs) != 0. False otherwise. 01928 */ 01929 template<typename _CharT, typename _Traits, typename _Alloc, 01930 template <typename, typename, typename> class _Base> 01931 inline bool 01932 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 01933 const _CharT* __rhs) 01934 { return __lhs.compare(__rhs) != 0; } 01935 01936 // operator < 01937 /** 01938 * @brief Test if string precedes string. 01939 * @param lhs First string. 01940 * @param rhs Second string. 01941 * @return True if @a lhs precedes @a rhs. False otherwise. 01942 */ 01943 template<typename _CharT, typename _Traits, typename _Alloc, 01944 template <typename, typename, typename> class _Base> 01945 inline bool 01946 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 01947 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 01948 { return __lhs.compare(__rhs) < 0; } 01949 01950 /** 01951 * @brief Test if string precedes C string. 01952 * @param lhs String. 01953 * @param rhs C string. 01954 * @return True if @a lhs precedes @a rhs. False otherwise. 01955 */ 01956 template<typename _CharT, typename _Traits, typename _Alloc, 01957 template <typename, typename, typename> class _Base> 01958 inline bool 01959 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 01960 const _CharT* __rhs) 01961 { return __lhs.compare(__rhs) < 0; } 01962 01963 /** 01964 * @brief Test if C string precedes string. 01965 * @param lhs C string. 01966 * @param rhs String. 01967 * @return True if @a lhs precedes @a rhs. False otherwise. 01968 */ 01969 template<typename _CharT, typename _Traits, typename _Alloc, 01970 template <typename, typename, typename> class _Base> 01971 inline bool 01972 operator<(const _CharT* __lhs, 01973 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 01974 { return __rhs.compare(__lhs) > 0; } 01975 01976 // operator > 01977 /** 01978 * @brief Test if string follows string. 01979 * @param lhs First string. 01980 * @param rhs Second string. 01981 * @return True if @a lhs follows @a rhs. False otherwise. 01982 */ 01983 template<typename _CharT, typename _Traits, typename _Alloc, 01984 template <typename, typename, typename> class _Base> 01985 inline bool 01986 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 01987 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 01988 { return __lhs.compare(__rhs) > 0; } 01989 01990 /** 01991 * @brief Test if string follows C string. 01992 * @param lhs String. 01993 * @param rhs C string. 01994 * @return True if @a lhs follows @a rhs. False otherwise. 01995 */ 01996 template<typename _CharT, typename _Traits, typename _Alloc, 01997 template <typename, typename, typename> class _Base> 01998 inline bool 01999 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02000 const _CharT* __rhs) 02001 { return __lhs.compare(__rhs) > 0; } 02002 02003 /** 02004 * @brief Test if C string follows string. 02005 * @param lhs C string. 02006 * @param rhs String. 02007 * @return True if @a lhs follows @a rhs. False otherwise. 02008 */ 02009 template<typename _CharT, typename _Traits, typename _Alloc, 02010 template <typename, typename, typename> class _Base> 02011 inline bool 02012 operator>(const _CharT* __lhs, 02013 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02014 { return __rhs.compare(__lhs) < 0; } 02015 02016 // operator <= 02017 /** 02018 * @brief Test if string doesn't follow string. 02019 * @param lhs First string. 02020 * @param rhs Second string. 02021 * @return True if @a lhs doesn't follow @a rhs. False otherwise. 02022 */ 02023 template<typename _CharT, typename _Traits, typename _Alloc, 02024 template <typename, typename, typename> class _Base> 02025 inline bool 02026 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02027 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02028 { return __lhs.compare(__rhs) <= 0; } 02029 02030 /** 02031 * @brief Test if string doesn't follow C string. 02032 * @param lhs String. 02033 * @param rhs C string. 02034 * @return True if @a lhs doesn't follow @a rhs. False otherwise. 02035 */ 02036 template<typename _CharT, typename _Traits, typename _Alloc, 02037 template <typename, typename, typename> class _Base> 02038 inline bool 02039 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02040 const _CharT* __rhs) 02041 { return __lhs.compare(__rhs) <= 0; } 02042 02043 /** 02044 * @brief Test if C string doesn't follow string. 02045 * @param lhs C string. 02046 * @param rhs String. 02047 * @return True if @a lhs doesn't follow @a rhs. False otherwise. 02048 */ 02049 template<typename _CharT, typename _Traits, typename _Alloc, 02050 template <typename, typename, typename> class _Base> 02051 inline bool 02052 operator<=(const _CharT* __lhs, 02053 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02054 { return __rhs.compare(__lhs) >= 0; } 02055 02056 // operator >= 02057 /** 02058 * @brief Test if string doesn't precede string. 02059 * @param lhs First string. 02060 * @param rhs Second string. 02061 * @return True if @a lhs doesn't precede @a rhs. False otherwise. 02062 */ 02063 template<typename _CharT, typename _Traits, typename _Alloc, 02064 template <typename, typename, typename> class _Base> 02065 inline bool 02066 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02067 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02068 { return __lhs.compare(__rhs) >= 0; } 02069 02070 /** 02071 * @brief Test if string doesn't precede C string. 02072 * @param lhs String. 02073 * @param rhs C string. 02074 * @return True if @a lhs doesn't precede @a rhs. False otherwise. 02075 */ 02076 template<typename _CharT, typename _Traits, typename _Alloc, 02077 template <typename, typename, typename> class _Base> 02078 inline bool 02079 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02080 const _CharT* __rhs) 02081 { return __lhs.compare(__rhs) >= 0; } 02082 02083 /** 02084 * @brief Test if C string doesn't precede string. 02085 * @param lhs C string. 02086 * @param rhs String. 02087 * @return True if @a lhs doesn't precede @a rhs. False otherwise. 02088 */ 02089 template<typename _CharT, typename _Traits, typename _Alloc, 02090 template <typename, typename, typename> class _Base> 02091 inline bool 02092 operator>=(const _CharT* __lhs, 02093 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02094 { return __rhs.compare(__lhs) <= 0; } 02095 02096 /** 02097 * @brief Swap contents of two strings. 02098 * @param lhs First string. 02099 * @param rhs Second string. 02100 * 02101 * Exchanges the contents of @a lhs and @a rhs in constant time. 02102 */ 02103 template<typename _CharT, typename _Traits, typename _Alloc, 02104 template <typename, typename, typename> class _Base> 02105 inline void 02106 swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 02107 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 02108 { __lhs.swap(__rhs); } 02109 02110 _GLIBCXX_END_NAMESPACE 02111 02112 _GLIBCXX_BEGIN_NAMESPACE(std) 02113 02114 /** 02115 * @brief Read stream into a string. 02116 * @param is Input stream. 02117 * @param str Buffer to store into. 02118 * @return Reference to the input stream. 02119 * 02120 * Stores characters from @a is into @a str until whitespace is found, the 02121 * end of the stream is encountered, or str.max_size() is reached. If 02122 * is.width() is non-zero, that is the limit on the number of characters 02123 * stored into @a str. Any previous contents of @a str are erased. 02124 */ 02125 template<typename _CharT, typename _Traits, typename _Alloc, 02126 template <typename, typename, typename> class _Base> 02127 basic_istream<_CharT, _Traits>& 02128 operator>>(basic_istream<_CharT, _Traits>& __is, 02129 __gnu_cxx::__versa_string<_CharT, _Traits, 02130 _Alloc, _Base>& __str); 02131 02132 /** 02133 * @brief Write string to a stream. 02134 * @param os Output stream. 02135 * @param str String to write out. 02136 * @return Reference to the output stream. 02137 * 02138 * Output characters of @a str into os following the same rules as for 02139 * writing a C string. 02140 */ 02141 template<typename _CharT, typename _Traits, typename _Alloc, 02142 template <typename, typename, typename> class _Base> 02143 inline basic_ostream<_CharT, _Traits>& 02144 operator<<(basic_ostream<_CharT, _Traits>& __os, 02145 const __gnu_cxx::__versa_string<_CharT, _Traits, 02146 _Alloc, _Base>& __str) 02147 { 02148 // _GLIBCXX_RESOLVE_LIB_DEFECTS 02149 // 586. string inserter not a formatted function 02150 return __ostream_insert(__os, __str.data(), __str.size()); 02151 } 02152 02153 /** 02154 * @brief Read a line from stream into a string. 02155 * @param is Input stream. 02156 * @param str Buffer to store into. 02157 * @param delim Character marking end of line. 02158 * @return Reference to the input stream. 02159 * 02160 * Stores characters from @a is into @a str until @a delim is found, the 02161 * end of the stream is encountered, or str.max_size() is reached. If 02162 * is.width() is non-zero, that is the limit on the number of characters 02163 * stored into @a str. Any previous contents of @a str are erased. If @a 02164 * delim was encountered, it is extracted but not stored into @a str. 02165 */ 02166 template<typename _CharT, typename _Traits, typename _Alloc, 02167 template <typename, typename, typename> class _Base> 02168 basic_istream<_CharT, _Traits>& 02169 getline(basic_istream<_CharT, _Traits>& __is, 02170 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str, 02171 _CharT __delim); 02172 02173 /** 02174 * @brief Read a line from stream into a string. 02175 * @param is Input stream. 02176 * @param str Buffer to store into. 02177 * @return Reference to the input stream. 02178 * 02179 * Stores characters from is into @a str until '\n' is found, the end of 02180 * the stream is encountered, or str.max_size() is reached. If is.width() 02181 * is non-zero, that is the limit on the number of characters stored into 02182 * @a str. Any previous contents of @a str are erased. If end of line was 02183 * encountered, it is extracted but not stored into @a str. 02184 */ 02185 template<typename _CharT, typename _Traits, typename _Alloc, 02186 template <typename, typename, typename> class _Base> 02187 inline basic_istream<_CharT, _Traits>& 02188 getline(basic_istream<_CharT, _Traits>& __is, 02189 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str) 02190 { return getline(__is, __str, __is.widen('\n')); } 02191 02192 _GLIBCXX_END_NAMESPACE 02193 02194 #ifndef _GLIBCXX_EXPORT_TEMPLATE 02195 # include "vstring.tcc" 02196 #endif 02197 02198 #endif /* _VSTRING_H */