libstdc++
|
00001 // Debugging string implementation -*- C++ -*- 00002 00003 // Copyright (C) 2003-2016 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 debug/string 00026 * This file is a GNU debug extension to the Standard C++ Library. 00027 */ 00028 00029 #ifndef _GLIBCXX_DEBUG_STRING 00030 #define _GLIBCXX_DEBUG_STRING 1 00031 00032 #include <string> 00033 #include <debug/safe_sequence.h> 00034 #include <debug/safe_container.h> 00035 #include <debug/safe_iterator.h> 00036 00037 namespace __gnu_debug 00038 { 00039 /// Class std::basic_string with safety/checking/debug instrumentation. 00040 template<typename _CharT, typename _Traits = std::char_traits<_CharT>, 00041 typename _Allocator = std::allocator<_CharT> > 00042 class basic_string 00043 : public __gnu_debug::_Safe_container< 00044 basic_string<_CharT, _Traits, _Allocator>, 00045 _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>, 00046 public std::basic_string<_CharT, _Traits, _Allocator> 00047 { 00048 typedef std::basic_string<_CharT, _Traits, _Allocator> _Base; 00049 typedef __gnu_debug::_Safe_container< 00050 basic_string, _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)> 00051 _Safe; 00052 00053 public: 00054 // types: 00055 typedef _Traits traits_type; 00056 typedef typename _Traits::char_type value_type; 00057 typedef _Allocator allocator_type; 00058 typedef typename _Base::size_type size_type; 00059 typedef typename _Base::difference_type difference_type; 00060 typedef typename _Base::reference reference; 00061 typedef typename _Base::const_reference const_reference; 00062 typedef typename _Base::pointer pointer; 00063 typedef typename _Base::const_pointer const_pointer; 00064 00065 typedef __gnu_debug::_Safe_iterator< 00066 typename _Base::iterator, basic_string> iterator; 00067 typedef __gnu_debug::_Safe_iterator< 00068 typename _Base::const_iterator, basic_string> const_iterator; 00069 00070 typedef std::reverse_iterator<iterator> reverse_iterator; 00071 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 00072 00073 using _Base::npos; 00074 00075 basic_string() 00076 _GLIBCXX_NOEXCEPT_IF(std::is_nothrow_default_constructible<_Base>::value) 00077 : _Base() { } 00078 00079 // 21.3.1 construct/copy/destroy: 00080 explicit 00081 basic_string(const _Allocator& __a) _GLIBCXX_NOEXCEPT 00082 : _Base(__a) { } 00083 00084 #if __cplusplus < 201103L 00085 basic_string(const basic_string& __str) 00086 : _Base(__str) { } 00087 00088 ~basic_string() { } 00089 #else 00090 basic_string(const basic_string&) = default; 00091 basic_string(basic_string&&) = default; 00092 00093 basic_string(std::initializer_list<_CharT> __l, 00094 const _Allocator& __a = _Allocator()) 00095 : _Base(__l, __a) 00096 { } 00097 00098 #if _GLIBCXX_USE_CXX11_ABI 00099 basic_string(const basic_string& __s, const _Allocator& __a) 00100 : _Base(__s, __a) { } 00101 00102 basic_string(basic_string&& __s, const _Allocator& __a) 00103 : _Base(std::move(__s), __a) { } 00104 #endif 00105 00106 ~basic_string() = default; 00107 00108 // Provides conversion from a normal-mode string to a debug-mode string 00109 basic_string(_Base&& __base) noexcept 00110 : _Base(std::move(__base)) { } 00111 #endif // C++11 00112 00113 // Provides conversion from a normal-mode string to a debug-mode string 00114 basic_string(const _Base& __base) 00115 : _Base(__base) { } 00116 00117 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00118 // 42. string ctors specify wrong default allocator 00119 basic_string(const basic_string& __str, size_type __pos, 00120 size_type __n = _Base::npos, 00121 const _Allocator& __a = _Allocator()) 00122 : _Base(__str, __pos, __n, __a) { } 00123 00124 basic_string(const _CharT* __s, size_type __n, 00125 const _Allocator& __a = _Allocator()) 00126 : _Base(__gnu_debug::__check_string(__s, __n), __n, __a) { } 00127 00128 basic_string(const _CharT* __s, const _Allocator& __a = _Allocator()) 00129 : _Base(__gnu_debug::__check_string(__s), __a) 00130 { this->assign(__s); } 00131 00132 basic_string(size_type __n, _CharT __c, 00133 const _Allocator& __a = _Allocator()) 00134 : _Base(__n, __c, __a) { } 00135 00136 template<typename _InputIterator> 00137 basic_string(_InputIterator __begin, _InputIterator __end, 00138 const _Allocator& __a = _Allocator()) 00139 : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__begin, 00140 __end)), 00141 __gnu_debug::__base(__end), __a) { } 00142 00143 #if __cplusplus < 201103L 00144 basic_string& 00145 operator=(const basic_string& __str) 00146 { 00147 this->_M_safe() = __str; 00148 _M_base() = __str; 00149 return *this; 00150 } 00151 #else 00152 basic_string& 00153 operator=(const basic_string&) = default; 00154 00155 basic_string& 00156 operator=(basic_string&&) = default; 00157 #endif 00158 00159 basic_string& 00160 operator=(const _CharT* __s) 00161 { 00162 __glibcxx_check_string(__s); 00163 _M_base() = __s; 00164 this->_M_invalidate_all(); 00165 return *this; 00166 } 00167 00168 basic_string& 00169 operator=(_CharT __c) 00170 { 00171 _M_base() = __c; 00172 this->_M_invalidate_all(); 00173 return *this; 00174 } 00175 00176 #if __cplusplus >= 201103L 00177 basic_string& 00178 operator=(std::initializer_list<_CharT> __l) 00179 { 00180 _M_base() = __l; 00181 this->_M_invalidate_all(); 00182 return *this; 00183 } 00184 #endif // C++11 00185 00186 // 21.3.2 iterators: 00187 iterator 00188 begin() // _GLIBCXX_NOEXCEPT 00189 { return iterator(_Base::begin(), this); } 00190 00191 const_iterator 00192 begin() const _GLIBCXX_NOEXCEPT 00193 { return const_iterator(_Base::begin(), this); } 00194 00195 iterator 00196 end() // _GLIBCXX_NOEXCEPT 00197 { return iterator(_Base::end(), this); } 00198 00199 const_iterator 00200 end() const _GLIBCXX_NOEXCEPT 00201 { return const_iterator(_Base::end(), this); } 00202 00203 reverse_iterator 00204 rbegin() // _GLIBCXX_NOEXCEPT 00205 { return reverse_iterator(end()); } 00206 00207 const_reverse_iterator 00208 rbegin() const _GLIBCXX_NOEXCEPT 00209 { return const_reverse_iterator(end()); } 00210 00211 reverse_iterator 00212 rend() // _GLIBCXX_NOEXCEPT 00213 { return reverse_iterator(begin()); } 00214 00215 const_reverse_iterator 00216 rend() const _GLIBCXX_NOEXCEPT 00217 { return const_reverse_iterator(begin()); } 00218 00219 #if __cplusplus >= 201103L 00220 const_iterator 00221 cbegin() const noexcept 00222 { return const_iterator(_Base::begin(), this); } 00223 00224 const_iterator 00225 cend() const noexcept 00226 { return const_iterator(_Base::end(), this); } 00227 00228 const_reverse_iterator 00229 crbegin() const noexcept 00230 { return const_reverse_iterator(end()); } 00231 00232 const_reverse_iterator 00233 crend() const noexcept 00234 { return const_reverse_iterator(begin()); } 00235 #endif 00236 00237 // 21.3.3 capacity: 00238 using _Base::size; 00239 using _Base::length; 00240 using _Base::max_size; 00241 00242 void 00243 resize(size_type __n, _CharT __c) 00244 { 00245 _Base::resize(__n, __c); 00246 this->_M_invalidate_all(); 00247 } 00248 00249 void 00250 resize(size_type __n) 00251 { this->resize(__n, _CharT()); } 00252 00253 #if __cplusplus >= 201103L 00254 void 00255 shrink_to_fit() noexcept 00256 { 00257 if (capacity() > size()) 00258 { 00259 __try 00260 { 00261 reserve(0); 00262 this->_M_invalidate_all(); 00263 } 00264 __catch(...) 00265 { } 00266 } 00267 } 00268 #endif 00269 00270 using _Base::capacity; 00271 using _Base::reserve; 00272 00273 void 00274 clear() // _GLIBCXX_NOEXCEPT 00275 { 00276 _Base::clear(); 00277 this->_M_invalidate_all(); 00278 } 00279 00280 using _Base::empty; 00281 00282 // 21.3.4 element access: 00283 const_reference 00284 operator[](size_type __pos) const _GLIBCXX_NOEXCEPT 00285 { 00286 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(), 00287 _M_message(__gnu_debug::__msg_subscript_oob) 00288 ._M_sequence(*this, "this") 00289 ._M_integer(__pos, "__pos") 00290 ._M_integer(this->size(), "size")); 00291 return _M_base()[__pos]; 00292 } 00293 00294 reference 00295 operator[](size_type __pos) // _GLIBCXX_NOEXCEPT 00296 { 00297 #if __cplusplus < 201103L && defined(_GLIBCXX_DEBUG_PEDANTIC) 00298 __glibcxx_check_subscript(__pos); 00299 #else 00300 // as an extension v3 allows s[s.size()] when s is non-const. 00301 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(), 00302 _M_message(__gnu_debug::__msg_subscript_oob) 00303 ._M_sequence(*this, "this") 00304 ._M_integer(__pos, "__pos") 00305 ._M_integer(this->size(), "size")); 00306 #endif 00307 return _M_base()[__pos]; 00308 } 00309 00310 using _Base::at; 00311 00312 #if __cplusplus >= 201103L 00313 using _Base::front; 00314 using _Base::back; 00315 #endif 00316 00317 // 21.3.5 modifiers: 00318 basic_string& 00319 operator+=(const basic_string& __str) 00320 { 00321 _M_base() += __str; 00322 this->_M_invalidate_all(); 00323 return *this; 00324 } 00325 00326 basic_string& 00327 operator+=(const _CharT* __s) 00328 { 00329 __glibcxx_check_string(__s); 00330 _M_base() += __s; 00331 this->_M_invalidate_all(); 00332 return *this; 00333 } 00334 00335 basic_string& 00336 operator+=(_CharT __c) 00337 { 00338 _M_base() += __c; 00339 this->_M_invalidate_all(); 00340 return *this; 00341 } 00342 00343 #if __cplusplus >= 201103L 00344 basic_string& 00345 operator+=(std::initializer_list<_CharT> __l) 00346 { 00347 _M_base() += __l; 00348 this->_M_invalidate_all(); 00349 return *this; 00350 } 00351 #endif // C++11 00352 00353 basic_string& 00354 append(const basic_string& __str) 00355 { 00356 _Base::append(__str); 00357 this->_M_invalidate_all(); 00358 return *this; 00359 } 00360 00361 basic_string& 00362 append(const basic_string& __str, size_type __pos, size_type __n) 00363 { 00364 _Base::append(__str, __pos, __n); 00365 this->_M_invalidate_all(); 00366 return *this; 00367 } 00368 00369 basic_string& 00370 append(const _CharT* __s, size_type __n) 00371 { 00372 __glibcxx_check_string_len(__s, __n); 00373 _Base::append(__s, __n); 00374 this->_M_invalidate_all(); 00375 return *this; 00376 } 00377 00378 basic_string& 00379 append(const _CharT* __s) 00380 { 00381 __glibcxx_check_string(__s); 00382 _Base::append(__s); 00383 this->_M_invalidate_all(); 00384 return *this; 00385 } 00386 00387 basic_string& 00388 append(size_type __n, _CharT __c) 00389 { 00390 _Base::append(__n, __c); 00391 this->_M_invalidate_all(); 00392 return *this; 00393 } 00394 00395 template<typename _InputIterator> 00396 basic_string& 00397 append(_InputIterator __first, _InputIterator __last) 00398 { 00399 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist; 00400 __glibcxx_check_valid_range2(__first, __last, __dist); 00401 00402 if (__dist.second >= __dp_sign) 00403 _Base::append(__gnu_debug::__unsafe(__first), 00404 __gnu_debug::__unsafe(__last)); 00405 else 00406 _Base::append(__first, __last); 00407 00408 this->_M_invalidate_all(); 00409 return *this; 00410 } 00411 00412 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00413 // 7. string clause minor problems 00414 void 00415 push_back(_CharT __c) 00416 { 00417 _Base::push_back(__c); 00418 this->_M_invalidate_all(); 00419 } 00420 00421 basic_string& 00422 assign(const basic_string& __x) 00423 { 00424 _Base::assign(__x); 00425 this->_M_invalidate_all(); 00426 return *this; 00427 } 00428 00429 #if __cplusplus >= 201103L 00430 basic_string& 00431 assign(basic_string&& __x) 00432 noexcept(noexcept(std::declval<_Base&>().assign(std::move(__x)))) 00433 { 00434 _Base::assign(std::move(__x)); 00435 this->_M_invalidate_all(); 00436 return *this; 00437 } 00438 #endif // C++11 00439 00440 basic_string& 00441 assign(const basic_string& __str, size_type __pos, size_type __n) 00442 { 00443 _Base::assign(__str, __pos, __n); 00444 this->_M_invalidate_all(); 00445 return *this; 00446 } 00447 00448 basic_string& 00449 assign(const _CharT* __s, size_type __n) 00450 { 00451 __glibcxx_check_string_len(__s, __n); 00452 _Base::assign(__s, __n); 00453 this->_M_invalidate_all(); 00454 return *this; 00455 } 00456 00457 basic_string& 00458 assign(const _CharT* __s) 00459 { 00460 __glibcxx_check_string(__s); 00461 _Base::assign(__s); 00462 this->_M_invalidate_all(); 00463 return *this; 00464 } 00465 00466 basic_string& 00467 assign(size_type __n, _CharT __c) 00468 { 00469 _Base::assign(__n, __c); 00470 this->_M_invalidate_all(); 00471 return *this; 00472 } 00473 00474 template<typename _InputIterator> 00475 basic_string& 00476 assign(_InputIterator __first, _InputIterator __last) 00477 { 00478 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist; 00479 __glibcxx_check_valid_range2(__first, __last, __dist); 00480 00481 if (__dist.second >= __dp_sign) 00482 _Base::assign(__gnu_debug::__unsafe(__first), 00483 __gnu_debug::__unsafe(__last)); 00484 else 00485 _Base::assign(__first, __last); 00486 00487 this->_M_invalidate_all(); 00488 return *this; 00489 } 00490 00491 #if __cplusplus >= 201103L 00492 basic_string& 00493 assign(std::initializer_list<_CharT> __l) 00494 { 00495 _Base::assign(__l); 00496 this->_M_invalidate_all(); 00497 return *this; 00498 } 00499 #endif // C++11 00500 00501 basic_string& 00502 insert(size_type __pos1, const basic_string& __str) 00503 { 00504 _Base::insert(__pos1, __str); 00505 this->_M_invalidate_all(); 00506 return *this; 00507 } 00508 00509 basic_string& 00510 insert(size_type __pos1, const basic_string& __str, 00511 size_type __pos2, size_type __n) 00512 { 00513 _Base::insert(__pos1, __str, __pos2, __n); 00514 this->_M_invalidate_all(); 00515 return *this; 00516 } 00517 00518 basic_string& 00519 insert(size_type __pos, const _CharT* __s, size_type __n) 00520 { 00521 __glibcxx_check_string(__s); 00522 _Base::insert(__pos, __s, __n); 00523 this->_M_invalidate_all(); 00524 return *this; 00525 } 00526 00527 basic_string& 00528 insert(size_type __pos, const _CharT* __s) 00529 { 00530 __glibcxx_check_string(__s); 00531 _Base::insert(__pos, __s); 00532 this->_M_invalidate_all(); 00533 return *this; 00534 } 00535 00536 basic_string& 00537 insert(size_type __pos, size_type __n, _CharT __c) 00538 { 00539 _Base::insert(__pos, __n, __c); 00540 this->_M_invalidate_all(); 00541 return *this; 00542 } 00543 00544 iterator 00545 insert(iterator __p, _CharT __c) 00546 { 00547 __glibcxx_check_insert(__p); 00548 typename _Base::iterator __res = _Base::insert(__p.base(), __c); 00549 this->_M_invalidate_all(); 00550 return iterator(__res, this); 00551 } 00552 00553 void 00554 insert(iterator __p, size_type __n, _CharT __c) 00555 { 00556 __glibcxx_check_insert(__p); 00557 _Base::insert(__p.base(), __n, __c); 00558 this->_M_invalidate_all(); 00559 } 00560 00561 template<typename _InputIterator> 00562 void 00563 insert(iterator __p, _InputIterator __first, _InputIterator __last) 00564 { 00565 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist; 00566 __glibcxx_check_insert_range2(__p, __first, __last, __dist); 00567 00568 if (__dist.second >= __dp_sign) 00569 _Base::insert(__p.base(), __gnu_debug::__unsafe(__first), 00570 __gnu_debug::__unsafe(__last)); 00571 else 00572 _Base::insert(__p.base(), __first, __last); 00573 00574 this->_M_invalidate_all(); 00575 } 00576 00577 #if __cplusplus >= 201103L 00578 void 00579 insert(iterator __p, std::initializer_list<_CharT> __l) 00580 { 00581 __glibcxx_check_insert(__p); 00582 _Base::insert(__p.base(), __l); 00583 this->_M_invalidate_all(); 00584 } 00585 #endif // C++11 00586 00587 basic_string& 00588 erase(size_type __pos = 0, size_type __n = _Base::npos) 00589 { 00590 _Base::erase(__pos, __n); 00591 this->_M_invalidate_all(); 00592 return *this; 00593 } 00594 00595 iterator 00596 erase(iterator __position) 00597 { 00598 __glibcxx_check_erase(__position); 00599 typename _Base::iterator __res = _Base::erase(__position.base()); 00600 this->_M_invalidate_all(); 00601 return iterator(__res, this); 00602 } 00603 00604 iterator 00605 erase(iterator __first, iterator __last) 00606 { 00607 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00608 // 151. can't currently clear() empty container 00609 __glibcxx_check_erase_range(__first, __last); 00610 typename _Base::iterator __res = _Base::erase(__first.base(), 00611 __last.base()); 00612 this->_M_invalidate_all(); 00613 return iterator(__res, this); 00614 } 00615 00616 #if __cplusplus >= 201103L 00617 void 00618 pop_back() // noexcept 00619 { 00620 __glibcxx_check_nonempty(); 00621 _Base::pop_back(); 00622 this->_M_invalidate_all(); 00623 } 00624 #endif // C++11 00625 00626 basic_string& 00627 replace(size_type __pos1, size_type __n1, const basic_string& __str) 00628 { 00629 _Base::replace(__pos1, __n1, __str); 00630 this->_M_invalidate_all(); 00631 return *this; 00632 } 00633 00634 basic_string& 00635 replace(size_type __pos1, size_type __n1, const basic_string& __str, 00636 size_type __pos2, size_type __n2) 00637 { 00638 _Base::replace(__pos1, __n1, __str, __pos2, __n2); 00639 this->_M_invalidate_all(); 00640 return *this; 00641 } 00642 00643 basic_string& 00644 replace(size_type __pos, size_type __n1, const _CharT* __s, 00645 size_type __n2) 00646 { 00647 __glibcxx_check_string_len(__s, __n2); 00648 _Base::replace(__pos, __n1, __s, __n2); 00649 this->_M_invalidate_all(); 00650 return *this; 00651 } 00652 00653 basic_string& 00654 replace(size_type __pos, size_type __n1, const _CharT* __s) 00655 { 00656 __glibcxx_check_string(__s); 00657 _Base::replace(__pos, __n1, __s); 00658 this->_M_invalidate_all(); 00659 return *this; 00660 } 00661 00662 basic_string& 00663 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) 00664 { 00665 _Base::replace(__pos, __n1, __n2, __c); 00666 this->_M_invalidate_all(); 00667 return *this; 00668 } 00669 00670 basic_string& 00671 replace(iterator __i1, iterator __i2, const basic_string& __str) 00672 { 00673 __glibcxx_check_erase_range(__i1, __i2); 00674 _Base::replace(__i1.base(), __i2.base(), __str); 00675 this->_M_invalidate_all(); 00676 return *this; 00677 } 00678 00679 basic_string& 00680 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) 00681 { 00682 __glibcxx_check_erase_range(__i1, __i2); 00683 __glibcxx_check_string_len(__s, __n); 00684 _Base::replace(__i1.base(), __i2.base(), __s, __n); 00685 this->_M_invalidate_all(); 00686 return *this; 00687 } 00688 00689 basic_string& 00690 replace(iterator __i1, iterator __i2, const _CharT* __s) 00691 { 00692 __glibcxx_check_erase_range(__i1, __i2); 00693 __glibcxx_check_string(__s); 00694 _Base::replace(__i1.base(), __i2.base(), __s); 00695 this->_M_invalidate_all(); 00696 return *this; 00697 } 00698 00699 basic_string& 00700 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c) 00701 { 00702 __glibcxx_check_erase_range(__i1, __i2); 00703 _Base::replace(__i1.base(), __i2.base(), __n, __c); 00704 this->_M_invalidate_all(); 00705 return *this; 00706 } 00707 00708 template<typename _InputIterator> 00709 basic_string& 00710 replace(iterator __i1, iterator __i2, 00711 _InputIterator __j1, _InputIterator __j2) 00712 { 00713 __glibcxx_check_erase_range(__i1, __i2); 00714 00715 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist; 00716 __glibcxx_check_valid_range2(__j1, __j2, __dist); 00717 00718 if (__dist.second >= __dp_sign) 00719 _Base::replace(__i1.base(), __i2.base(), 00720 __gnu_debug::__unsafe(__j1), 00721 __gnu_debug::__unsafe(__j2)); 00722 else 00723 _Base::replace(__i1.base(), __i2.base(), __j1, __j2); 00724 00725 this->_M_invalidate_all(); 00726 return *this; 00727 } 00728 00729 #if __cplusplus >= 201103L 00730 basic_string& replace(iterator __i1, iterator __i2, 00731 std::initializer_list<_CharT> __l) 00732 { 00733 __glibcxx_check_erase_range(__i1, __i2); 00734 _Base::replace(__i1.base(), __i2.base(), __l); 00735 this->_M_invalidate_all(); 00736 return *this; 00737 } 00738 #endif // C++11 00739 00740 size_type 00741 copy(_CharT* __s, size_type __n, size_type __pos = 0) const 00742 { 00743 __glibcxx_check_string_len(__s, __n); 00744 return _Base::copy(__s, __n, __pos); 00745 } 00746 00747 void 00748 swap(basic_string& __x) 00749 _GLIBCXX_NOEXCEPT_IF(std::__is_nothrow_swappable<_Base>::value) 00750 { 00751 _Safe::_M_swap(__x); 00752 _Base::swap(__x); 00753 } 00754 00755 // 21.3.6 string operations: 00756 const _CharT* 00757 c_str() const _GLIBCXX_NOEXCEPT 00758 { 00759 const _CharT* __res = _Base::c_str(); 00760 this->_M_invalidate_all(); 00761 return __res; 00762 } 00763 00764 const _CharT* 00765 data() const _GLIBCXX_NOEXCEPT 00766 { 00767 const _CharT* __res = _Base::data(); 00768 this->_M_invalidate_all(); 00769 return __res; 00770 } 00771 00772 using _Base::get_allocator; 00773 00774 size_type 00775 find(const basic_string& __str, size_type __pos = 0) const 00776 _GLIBCXX_NOEXCEPT 00777 { return _Base::find(__str, __pos); } 00778 00779 size_type 00780 find(const _CharT* __s, size_type __pos, size_type __n) const 00781 { 00782 __glibcxx_check_string(__s); 00783 return _Base::find(__s, __pos, __n); 00784 } 00785 00786 size_type 00787 find(const _CharT* __s, size_type __pos = 0) const 00788 { 00789 __glibcxx_check_string(__s); 00790 return _Base::find(__s, __pos); 00791 } 00792 00793 size_type 00794 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT 00795 { return _Base::find(__c, __pos); } 00796 00797 size_type 00798 rfind(const basic_string& __str, size_type __pos = _Base::npos) const 00799 _GLIBCXX_NOEXCEPT 00800 { return _Base::rfind(__str, __pos); } 00801 00802 size_type 00803 rfind(const _CharT* __s, size_type __pos, size_type __n) const 00804 { 00805 __glibcxx_check_string_len(__s, __n); 00806 return _Base::rfind(__s, __pos, __n); 00807 } 00808 00809 size_type 00810 rfind(const _CharT* __s, size_type __pos = _Base::npos) const 00811 { 00812 __glibcxx_check_string(__s); 00813 return _Base::rfind(__s, __pos); 00814 } 00815 00816 size_type 00817 rfind(_CharT __c, size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT 00818 { return _Base::rfind(__c, __pos); } 00819 00820 size_type 00821 find_first_of(const basic_string& __str, size_type __pos = 0) const 00822 _GLIBCXX_NOEXCEPT 00823 { return _Base::find_first_of(__str, __pos); } 00824 00825 size_type 00826 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const 00827 { 00828 __glibcxx_check_string(__s); 00829 return _Base::find_first_of(__s, __pos, __n); 00830 } 00831 00832 size_type 00833 find_first_of(const _CharT* __s, size_type __pos = 0) const 00834 { 00835 __glibcxx_check_string(__s); 00836 return _Base::find_first_of(__s, __pos); 00837 } 00838 00839 size_type 00840 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT 00841 { return _Base::find_first_of(__c, __pos); } 00842 00843 size_type 00844 find_last_of(const basic_string& __str, 00845 size_type __pos = _Base::npos) const _GLIBCXX_NOEXCEPT 00846 { return _Base::find_last_of(__str, __pos); } 00847 00848 size_type 00849 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const 00850 { 00851 __glibcxx_check_string(__s); 00852 return _Base::find_last_of(__s, __pos, __n); 00853 } 00854 00855 size_type 00856 find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const 00857 { 00858 __glibcxx_check_string(__s); 00859 return _Base::find_last_of(__s, __pos); 00860 } 00861 00862 size_type 00863 find_last_of(_CharT __c, size_type __pos = _Base::npos) const 00864 _GLIBCXX_NOEXCEPT 00865 { return _Base::find_last_of(__c, __pos); } 00866 00867 size_type 00868 find_first_not_of(const basic_string& __str, size_type __pos = 0) const 00869 _GLIBCXX_NOEXCEPT 00870 { return _Base::find_first_not_of(__str, __pos); } 00871 00872 size_type 00873 find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const 00874 { 00875 __glibcxx_check_string_len(__s, __n); 00876 return _Base::find_first_not_of(__s, __pos, __n); 00877 } 00878 00879 size_type 00880 find_first_not_of(const _CharT* __s, size_type __pos = 0) const 00881 { 00882 __glibcxx_check_string(__s); 00883 return _Base::find_first_not_of(__s, __pos); 00884 } 00885 00886 size_type 00887 find_first_not_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT 00888 { return _Base::find_first_not_of(__c, __pos); } 00889 00890 size_type 00891 find_last_not_of(const basic_string& __str, 00892 size_type __pos = _Base::npos) const 00893 _GLIBCXX_NOEXCEPT 00894 { return _Base::find_last_not_of(__str, __pos); } 00895 00896 size_type 00897 find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const 00898 { 00899 __glibcxx_check_string(__s); 00900 return _Base::find_last_not_of(__s, __pos, __n); 00901 } 00902 00903 size_type 00904 find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const 00905 { 00906 __glibcxx_check_string(__s); 00907 return _Base::find_last_not_of(__s, __pos); 00908 } 00909 00910 size_type 00911 find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const 00912 _GLIBCXX_NOEXCEPT 00913 { return _Base::find_last_not_of(__c, __pos); } 00914 00915 basic_string 00916 substr(size_type __pos = 0, size_type __n = _Base::npos) const 00917 { return basic_string(_Base::substr(__pos, __n)); } 00918 00919 int 00920 compare(const basic_string& __str) const 00921 { return _Base::compare(__str); } 00922 00923 int 00924 compare(size_type __pos1, size_type __n1, 00925 const basic_string& __str) const 00926 { return _Base::compare(__pos1, __n1, __str); } 00927 00928 int 00929 compare(size_type __pos1, size_type __n1, const basic_string& __str, 00930 size_type __pos2, size_type __n2) const 00931 { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); } 00932 00933 int 00934 compare(const _CharT* __s) const 00935 { 00936 __glibcxx_check_string(__s); 00937 return _Base::compare(__s); 00938 } 00939 00940 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00941 // 5. string::compare specification questionable 00942 int 00943 compare(size_type __pos1, size_type __n1, const _CharT* __s) const 00944 { 00945 __glibcxx_check_string(__s); 00946 return _Base::compare(__pos1, __n1, __s); 00947 } 00948 00949 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00950 // 5. string::compare specification questionable 00951 int 00952 compare(size_type __pos1, size_type __n1,const _CharT* __s, 00953 size_type __n2) const 00954 { 00955 __glibcxx_check_string_len(__s, __n2); 00956 return _Base::compare(__pos1, __n1, __s, __n2); 00957 } 00958 00959 _Base& 00960 _M_base() _GLIBCXX_NOEXCEPT { return *this; } 00961 00962 const _Base& 00963 _M_base() const _GLIBCXX_NOEXCEPT { return *this; } 00964 00965 using _Safe::_M_invalidate_all; 00966 }; 00967 00968 template<typename _CharT, typename _Traits, typename _Allocator> 00969 inline basic_string<_CharT,_Traits,_Allocator> 00970 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00971 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00972 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; } 00973 00974 template<typename _CharT, typename _Traits, typename _Allocator> 00975 inline basic_string<_CharT,_Traits,_Allocator> 00976 operator+(const _CharT* __lhs, 00977 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00978 { 00979 __glibcxx_check_string(__lhs); 00980 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; 00981 } 00982 00983 template<typename _CharT, typename _Traits, typename _Allocator> 00984 inline basic_string<_CharT,_Traits,_Allocator> 00985 operator+(_CharT __lhs, 00986 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00987 { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; } 00988 00989 template<typename _CharT, typename _Traits, typename _Allocator> 00990 inline basic_string<_CharT,_Traits,_Allocator> 00991 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00992 const _CharT* __rhs) 00993 { 00994 __glibcxx_check_string(__rhs); 00995 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; 00996 } 00997 00998 template<typename _CharT, typename _Traits, typename _Allocator> 00999 inline basic_string<_CharT,_Traits,_Allocator> 01000 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 01001 _CharT __rhs) 01002 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; } 01003 01004 template<typename _CharT, typename _Traits, typename _Allocator> 01005 inline bool 01006 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 01007 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 01008 { return __lhs._M_base() == __rhs._M_base(); } 01009 01010 template<typename _CharT, typename _Traits, typename _Allocator> 01011 inline bool 01012 operator==(const _CharT* __lhs, 01013 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 01014 { 01015 __glibcxx_check_string(__lhs); 01016 return __lhs == __rhs._M_base(); 01017 } 01018 01019 template<typename _CharT, typename _Traits, typename _Allocator> 01020 inline bool 01021 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 01022 const _CharT* __rhs) 01023 { 01024 __glibcxx_check_string(__rhs); 01025 return __lhs._M_base() == __rhs; 01026 } 01027 01028 template<typename _CharT, typename _Traits, typename _Allocator> 01029 inline bool 01030 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 01031 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 01032 { return __lhs._M_base() != __rhs._M_base(); } 01033 01034 template<typename _CharT, typename _Traits, typename _Allocator> 01035 inline bool 01036 operator!=(const _CharT* __lhs, 01037 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 01038 { 01039 __glibcxx_check_string(__lhs); 01040 return __lhs != __rhs._M_base(); 01041 } 01042 01043 template<typename _CharT, typename _Traits, typename _Allocator> 01044 inline bool 01045 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 01046 const _CharT* __rhs) 01047 { 01048 __glibcxx_check_string(__rhs); 01049 return __lhs._M_base() != __rhs; 01050 } 01051 01052 template<typename _CharT, typename _Traits, typename _Allocator> 01053 inline bool 01054 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 01055 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 01056 { return __lhs._M_base() < __rhs._M_base(); } 01057 01058 template<typename _CharT, typename _Traits, typename _Allocator> 01059 inline bool 01060 operator<(const _CharT* __lhs, 01061 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 01062 { 01063 __glibcxx_check_string(__lhs); 01064 return __lhs < __rhs._M_base(); 01065 } 01066 01067 template<typename _CharT, typename _Traits, typename _Allocator> 01068 inline bool 01069 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 01070 const _CharT* __rhs) 01071 { 01072 __glibcxx_check_string(__rhs); 01073 return __lhs._M_base() < __rhs; 01074 } 01075 01076 template<typename _CharT, typename _Traits, typename _Allocator> 01077 inline bool 01078 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 01079 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 01080 { return __lhs._M_base() <= __rhs._M_base(); } 01081 01082 template<typename _CharT, typename _Traits, typename _Allocator> 01083 inline bool 01084 operator<=(const _CharT* __lhs, 01085 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 01086 { 01087 __glibcxx_check_string(__lhs); 01088 return __lhs <= __rhs._M_base(); 01089 } 01090 01091 template<typename _CharT, typename _Traits, typename _Allocator> 01092 inline bool 01093 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 01094 const _CharT* __rhs) 01095 { 01096 __glibcxx_check_string(__rhs); 01097 return __lhs._M_base() <= __rhs; 01098 } 01099 01100 template<typename _CharT, typename _Traits, typename _Allocator> 01101 inline bool 01102 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 01103 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 01104 { return __lhs._M_base() >= __rhs._M_base(); } 01105 01106 template<typename _CharT, typename _Traits, typename _Allocator> 01107 inline bool 01108 operator>=(const _CharT* __lhs, 01109 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 01110 { 01111 __glibcxx_check_string(__lhs); 01112 return __lhs >= __rhs._M_base(); 01113 } 01114 01115 template<typename _CharT, typename _Traits, typename _Allocator> 01116 inline bool 01117 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 01118 const _CharT* __rhs) 01119 { 01120 __glibcxx_check_string(__rhs); 01121 return __lhs._M_base() >= __rhs; 01122 } 01123 01124 template<typename _CharT, typename _Traits, typename _Allocator> 01125 inline bool 01126 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 01127 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 01128 { return __lhs._M_base() > __rhs._M_base(); } 01129 01130 template<typename _CharT, typename _Traits, typename _Allocator> 01131 inline bool 01132 operator>(const _CharT* __lhs, 01133 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 01134 { 01135 __glibcxx_check_string(__lhs); 01136 return __lhs > __rhs._M_base(); 01137 } 01138 01139 template<typename _CharT, typename _Traits, typename _Allocator> 01140 inline bool 01141 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 01142 const _CharT* __rhs) 01143 { 01144 __glibcxx_check_string(__rhs); 01145 return __lhs._M_base() > __rhs; 01146 } 01147 01148 // 21.3.7.8: 01149 template<typename _CharT, typename _Traits, typename _Allocator> 01150 inline void 01151 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs, 01152 basic_string<_CharT,_Traits,_Allocator>& __rhs) 01153 { __lhs.swap(__rhs); } 01154 01155 template<typename _CharT, typename _Traits, typename _Allocator> 01156 std::basic_ostream<_CharT, _Traits>& 01157 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 01158 const basic_string<_CharT, _Traits, _Allocator>& __str) 01159 { return __os << __str._M_base(); } 01160 01161 template<typename _CharT, typename _Traits, typename _Allocator> 01162 std::basic_istream<_CharT,_Traits>& 01163 operator>>(std::basic_istream<_CharT,_Traits>& __is, 01164 basic_string<_CharT,_Traits,_Allocator>& __str) 01165 { 01166 std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base(); 01167 __str._M_invalidate_all(); 01168 return __res; 01169 } 01170 01171 template<typename _CharT, typename _Traits, typename _Allocator> 01172 std::basic_istream<_CharT,_Traits>& 01173 getline(std::basic_istream<_CharT,_Traits>& __is, 01174 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim) 01175 { 01176 std::basic_istream<_CharT,_Traits>& __res = getline(__is, 01177 __str._M_base(), 01178 __delim); 01179 __str._M_invalidate_all(); 01180 return __res; 01181 } 01182 01183 template<typename _CharT, typename _Traits, typename _Allocator> 01184 std::basic_istream<_CharT,_Traits>& 01185 getline(std::basic_istream<_CharT,_Traits>& __is, 01186 basic_string<_CharT,_Traits,_Allocator>& __str) 01187 { 01188 std::basic_istream<_CharT,_Traits>& __res = getline(__is, 01189 __str._M_base()); 01190 __str._M_invalidate_all(); 01191 return __res; 01192 } 01193 01194 typedef basic_string<char> string; 01195 01196 #ifdef _GLIBCXX_USE_WCHAR_T 01197 typedef basic_string<wchar_t> wstring; 01198 #endif 01199 01200 template<typename _CharT, typename _Traits, typename _Allocator> 01201 struct _Insert_range_from_self_is_safe< 01202 __gnu_debug::basic_string<_CharT, _Traits, _Allocator> > 01203 { enum { __value = 1 }; }; 01204 01205 } // namespace __gnu_debug 01206 01207 #endif