string

00001 // Debugging string implementation -*- C++ -*- 00002 00003 // Copyright (C) 2003 00004 // Free Software Foundation, Inc. 00005 // 00006 // This file is part of the GNU ISO C++ Library. This library is free 00007 // software; you can redistribute it and/or modify it under the 00008 // terms of the GNU General Public License as published by the 00009 // Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 00017 // You should have received a copy of the GNU General Public License along 00018 // with this library; see the file COPYING. If not, write to the Free 00019 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00020 // USA. 00021 00022 // As a special exception, you may use this file as part of a free software 00023 // library without restriction. Specifically, if other files instantiate 00024 // templates or use macros or inline functions from this file, or you compile 00025 // this file and link it with other files to produce an executable, this 00026 // file does not by itself cause the resulting executable to be covered by 00027 // the GNU General Public License. This exception does not however 00028 // invalidate any other reasons why the executable file might be covered by 00029 // the GNU General Public License. 00030 00031 #ifndef _GLIBCXX_DEBUG_STRING 00032 #define _GLIBCXX_DEBUG_STRING 1 00033 00034 #include <string> 00035 #include <debug/safe_sequence.h> 00036 #include <debug/safe_iterator.h> 00037 00038 namespace __gnu_debug 00039 { 00040 template<typename _CharT, typename _Traits, typename _Allocator> 00041 class basic_string 00042 : public std::basic_string<_CharT, _Traits, _Allocator>, 00043 public __gnu_debug::_Safe_sequence<basic_string<_CharT, _Traits, 00044 _Allocator> > 00045 { 00046 typedef std::basic_string<_CharT, _Traits, _Allocator> _Base; 00047 typedef __gnu_debug::_Safe_sequence<basic_string> _Safe_base; 00048 00049 public: 00050 // types: 00051 typedef _Traits traits_type; 00052 typedef typename _Traits::char_type value_type; 00053 typedef _Allocator allocator_type; 00054 typedef typename _Allocator::size_type size_type; 00055 typedef typename _Allocator::difference_type difference_type; 00056 typedef typename _Allocator::reference reference; 00057 typedef typename _Allocator::const_reference const_reference; 00058 typedef typename _Allocator::pointer pointer; 00059 typedef typename _Allocator::const_pointer const_pointer; 00060 00061 typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, basic_string> 00062 iterator; 00063 typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator, 00064 basic_string> const_iterator; 00065 00066 typedef std::reverse_iterator<iterator> reverse_iterator; 00067 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 00068 00069 using _Base::npos; 00070 00071 // 21.3.1 construct/copy/destroy: 00072 explicit basic_string(const _Allocator& __a = _Allocator()) 00073 : _Base(__a) 00074 { } 00075 00076 // Provides conversion from a release-mode string to a debug-mode string 00077 basic_string(const _Base& __base) : _Base(__base), _Safe_base() { } 00078 00079 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00080 // 42. string ctors specify wrong default allocator 00081 basic_string(const basic_string& __str) 00082 : _Base(__str, 0, _Base::npos, __str.get_allocator()), _Safe_base() 00083 { } 00084 00085 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00086 // 42. string ctors specify wrong default allocator 00087 basic_string(const basic_string& __str, size_type __pos, 00088 size_type __n = _Base::npos, 00089 const _Allocator& __a = _Allocator()) 00090 : _Base(__str, __pos, __n, __a) 00091 { } 00092 00093 basic_string(const _CharT* __s, size_type __n, 00094 const _Allocator& __a = _Allocator()) 00095 : _Base(__gnu_debug::__check_string(__s, __n), __n, __a) 00096 { } 00097 00098 basic_string(const _CharT* __s, const _Allocator& __a = _Allocator()) 00099 : _Base(__gnu_debug::__check_string(__s), __a) 00100 { this->assign(__s); } 00101 00102 basic_string(size_type __n, _CharT __c, 00103 const _Allocator& __a = _Allocator()) 00104 : _Base(__n, __c, __a) 00105 { } 00106 00107 template<typename _InputIterator> 00108 basic_string(_InputIterator __begin, _InputIterator __end, 00109 const _Allocator& __a = _Allocator()) 00110 : _Base(__gnu_debug::__check_valid_range(__begin, __end), __end, __a) 00111 { } 00112 00113 ~basic_string() { } 00114 00115 basic_string& 00116 operator=(const basic_string& __str) 00117 { 00118 *static_cast<_Base*>(this) = __str; 00119 this->_M_invalidate_all(); 00120 return *this; 00121 } 00122 00123 basic_string& 00124 operator=(const _CharT* __s) 00125 { 00126 __glibcxx_check_string(__s); 00127 *static_cast<_Base*>(this) = __s; 00128 this->_M_invalidate_all(); 00129 return *this; 00130 } 00131 00132 basic_string& 00133 operator=(_CharT __c) 00134 { 00135 *static_cast<_Base*>(this) = __c; 00136 this->_M_invalidate_all(); 00137 return *this; 00138 } 00139 00140 // 21.3.2 iterators: 00141 iterator 00142 begin() 00143 { return iterator(_Base::begin(), this); } 00144 00145 const_iterator 00146 begin() const 00147 { return const_iterator(_Base::begin(), this); } 00148 00149 iterator 00150 end() 00151 { return iterator(_Base::end(), this); } 00152 00153 const_iterator 00154 end() const 00155 { return const_iterator(_Base::end(), this); } 00156 00157 reverse_iterator 00158 rbegin() 00159 { return reverse_iterator(end()); } 00160 00161 const_reverse_iterator 00162 rbegin() const 00163 { return const_reverse_iterator(end()); } 00164 00165 reverse_iterator 00166 rend() 00167 { return reverse_iterator(begin()); } 00168 00169 const_reverse_iterator 00170 rend() const 00171 { return const_reverse_iterator(begin()); } 00172 00173 // 21.3.3 capacity: 00174 using _Base::size; 00175 using _Base::length; 00176 using _Base::max_size; 00177 00178 void 00179 resize(size_type __n, _CharT __c) 00180 { 00181 _Base::resize(__n, __c); 00182 this->_M_invalidate_all(); 00183 } 00184 00185 void 00186 resize(size_type __n) 00187 { this->resize(__n, _CharT()); } 00188 00189 using _Base::capacity; 00190 using _Base::reserve; 00191 00192 void 00193 clear() 00194 { 00195 _Base::clear(); 00196 this->_M_invalidate_all(); 00197 } 00198 00199 using _Base::empty; 00200 00201 // 21.3.4 element access: 00202 const_reference 00203 operator[](size_type __pos) const 00204 { 00205 _GLIBCXX_DEBUG_VERIFY(__pos <= this->size(), 00206 _M_message(::__gnu_debug::__msg_subscript_oob) 00207 ._M_sequence(*this, "this") 00208 ._M_integer(__pos, "__pos") 00209 ._M_integer(this->size(), "size")); 00210 return _M_base()[__pos]; 00211 } 00212 00213 reference 00214 operator[](size_type __pos) 00215 { 00216 __glibcxx_check_subscript(__pos); 00217 return _M_base()[__pos]; 00218 } 00219 00220 using _Base::at; 00221 00222 // 21.3.5 modifiers: 00223 basic_string& 00224 operator+=(const basic_string& __str) 00225 { 00226 _M_base() += __str; 00227 this->_M_invalidate_all(); 00228 return *this; 00229 } 00230 00231 basic_string& 00232 operator+=(const _CharT* __s) 00233 { 00234 __glibcxx_check_string(__s); 00235 _M_base() += __s; 00236 this->_M_invalidate_all(); 00237 return *this; 00238 } 00239 00240 basic_string& 00241 operator+=(_CharT __c) 00242 { 00243 _M_base() += __c; 00244 this->_M_invalidate_all(); 00245 return *this; 00246 } 00247 00248 basic_string& 00249 append(const basic_string& __str) 00250 { 00251 _Base::append(__str); 00252 this->_M_invalidate_all(); 00253 return *this; 00254 } 00255 00256 basic_string& 00257 append(const basic_string& __str, size_type __pos, size_type __n) 00258 { 00259 _Base::append(__str, __pos, __n); 00260 this->_M_invalidate_all(); 00261 return *this; 00262 } 00263 00264 basic_string& 00265 append(const _CharT* __s, size_type __n) 00266 { 00267 __glibcxx_check_string_len(__s, __n); 00268 _Base::append(__s, __n); 00269 this->_M_invalidate_all(); 00270 return *this; 00271 } 00272 00273 basic_string& 00274 append(const _CharT* __s) 00275 { 00276 __glibcxx_check_string(__s); 00277 _Base::append(__s); 00278 this->_M_invalidate_all(); 00279 return *this; 00280 } 00281 00282 basic_string& 00283 append(size_type __n, _CharT __c) 00284 { 00285 _Base::append(__n, __c); 00286 this->_M_invalidate_all(); 00287 return *this; 00288 } 00289 00290 template<typename _InputIterator> 00291 basic_string& 00292 append(_InputIterator __first, _InputIterator __last) 00293 { 00294 __glibcxx_check_valid_range(__first, __last); 00295 _Base::append(__first, __last); 00296 this->_M_invalidate_all(); 00297 return *this; 00298 } 00299 00300 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00301 // 7. string clause minor problems 00302 void 00303 push_back(_CharT __c) 00304 { 00305 _Base::push_back(__c); 00306 this->_M_invalidate_all(); 00307 } 00308 00309 basic_string& 00310 assign(const basic_string& __x) 00311 { 00312 _Base::assign(__x); 00313 this->_M_invalidate_all(); 00314 return *this; 00315 } 00316 00317 basic_string& 00318 assign(const basic_string& __str, size_type __pos, size_type __n) 00319 { 00320 _Base::assign(__str, __pos, __n); 00321 this->_M_invalidate_all(); 00322 return *this; 00323 } 00324 00325 basic_string& 00326 assign(const _CharT* __s, size_type __n) 00327 { 00328 __glibcxx_check_string_len(__s, __n); 00329 _Base::assign(__s, __n); 00330 this->_M_invalidate_all(); 00331 return *this; 00332 } 00333 00334 basic_string& 00335 assign(const _CharT* __s) 00336 { 00337 __glibcxx_check_string(__s); 00338 _Base::assign(__s); 00339 this->_M_invalidate_all(); 00340 return *this; 00341 } 00342 00343 basic_string& 00344 assign(size_type __n, _CharT __c) 00345 { 00346 _Base::assign(__n, __c); 00347 this->_M_invalidate_all(); 00348 return *this; 00349 } 00350 00351 template<typename _InputIterator> 00352 basic_string& 00353 assign(_InputIterator __first, _InputIterator __last) 00354 { 00355 __glibcxx_check_valid_range(__first, __last); 00356 _Base::assign(__first, __last); 00357 this->_M_invalidate_all(); 00358 return *this; 00359 } 00360 00361 basic_string& 00362 insert(size_type __pos1, const basic_string& __str) 00363 { 00364 _Base::insert(__pos1, __str); 00365 this->_M_invalidate_all(); 00366 return *this; 00367 } 00368 00369 basic_string& 00370 insert(size_type __pos1, const basic_string& __str, 00371 size_type __pos2, size_type __n) 00372 { 00373 _Base::insert(__pos1, __str, __pos2, __n); 00374 this->_M_invalidate_all(); 00375 return *this; 00376 } 00377 00378 basic_string& 00379 insert(size_type __pos, const _CharT* __s, size_type __n) 00380 { 00381 __glibcxx_check_string(__s); 00382 _Base::insert(__pos, __s, __n); 00383 this->_M_invalidate_all(); 00384 return *this; 00385 } 00386 00387 basic_string& 00388 insert(size_type __pos, const _CharT* __s) 00389 { 00390 __glibcxx_check_string(__s); 00391 _Base::insert(__pos, __s); 00392 this->_M_invalidate_all(); 00393 return *this; 00394 } 00395 00396 basic_string& 00397 insert(size_type __pos, size_type __n, _CharT __c) 00398 { 00399 _Base::insert(__pos, __n, __c); 00400 this->_M_invalidate_all(); 00401 return *this; 00402 } 00403 00404 iterator 00405 insert(iterator __p, _CharT __c) 00406 { 00407 __glibcxx_check_insert(__p); 00408 typename _Base::iterator __res = _Base::insert(__p.base(), __c); 00409 this->_M_invalidate_all(); 00410 return iterator(__res, this); 00411 } 00412 00413 void 00414 insert(iterator __p, size_type __n, _CharT __c) 00415 { 00416 __glibcxx_check_insert(__p); 00417 _Base::insert(__p.base(), __n, __c); 00418 this->_M_invalidate_all(); 00419 } 00420 00421 template<typename _InputIterator> 00422 void 00423 insert(iterator __p, _InputIterator __first, _InputIterator __last) 00424 { 00425 __glibcxx_check_insert_range(__p, __first, __last); 00426 _Base::insert(__p.base(), __first, __last); 00427 this->_M_invalidate_all(); 00428 } 00429 00430 basic_string& 00431 erase(size_type __pos = 0, size_type __n = _Base::npos) 00432 { 00433 _Base::erase(__pos, __n); 00434 this->_M_invalidate_all(); 00435 return *this; 00436 } 00437 00438 iterator 00439 erase(iterator __position) 00440 { 00441 __glibcxx_check_erase(__position); 00442 typename _Base::iterator __res = _Base::erase(__position.base()); 00443 this->_M_invalidate_all(); 00444 return iterator(__res, this); 00445 } 00446 00447 iterator 00448 erase(iterator __first, iterator __last) 00449 { 00450 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00451 // 151. can't currently clear() empty container 00452 __glibcxx_check_erase_range(__first, __last); 00453 typename _Base::iterator __res = _Base::erase(__first.base(), 00454 __last.base()); 00455 this->_M_invalidate_all(); 00456 return iterator(__res, this); 00457 } 00458 00459 basic_string& 00460 replace(size_type __pos1, size_type __n1, const basic_string& __str) 00461 { 00462 _Base::replace(__pos1, __n1, __str); 00463 this->_M_invalidate_all(); 00464 return *this; 00465 } 00466 00467 basic_string& 00468 replace(size_type __pos1, size_type __n1, const basic_string& __str, 00469 size_type __pos2, size_type __n2) 00470 { 00471 _Base::replace(__pos1, __n1, __str, __pos2, __n2); 00472 this->_M_invalidate_all(); 00473 return *this; 00474 } 00475 00476 basic_string& 00477 replace(size_type __pos, size_type __n1, const _CharT* __s, 00478 size_type __n2) 00479 { 00480 __glibcxx_check_string_len(__s, __n2); 00481 _Base::replace(__pos, __n1, __s, __n2); 00482 this->_M_invalidate_all(); 00483 return *this; 00484 } 00485 00486 basic_string& 00487 replace(size_type __pos, size_type __n1, const _CharT* __s) 00488 { 00489 __glibcxx_check_string(__s); 00490 _Base::replace(__pos, __n1, __s); 00491 this->_M_invalidate_all(); 00492 return *this; 00493 } 00494 00495 basic_string& 00496 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) 00497 { 00498 _Base::replace(__pos, __n1, __n2, __c); 00499 this->_M_invalidate_all(); 00500 return *this; 00501 } 00502 00503 basic_string& 00504 replace(iterator __i1, iterator __i2, const basic_string& __str) 00505 { 00506 __glibcxx_check_erase_range(__i1, __i2); 00507 _Base::replace(__i1.base(), __i2.base(), __str); 00508 this->_M_invalidate_all(); 00509 return *this; 00510 } 00511 00512 basic_string& 00513 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) 00514 { 00515 __glibcxx_check_erase_range(__i1, __i2); 00516 __glibcxx_check_string_len(__s, __n); 00517 _Base::replace(__i1.base(), __i2.base(), __s, __n); 00518 this->_M_invalidate_all(); 00519 return *this; 00520 } 00521 00522 basic_string& 00523 replace(iterator __i1, iterator __i2, const _CharT* __s) 00524 { 00525 __glibcxx_check_erase_range(__i1, __i2); 00526 __glibcxx_check_string(__s); 00527 _Base::replace(__i1.base(), __i2.base(), __s); 00528 this->_M_invalidate_all(); 00529 return *this; 00530 } 00531 00532 basic_string& 00533 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c) 00534 { 00535 __glibcxx_check_erase_range(__i1, __i2); 00536 _Base::replace(__i1.base(), __i2.base(), __n, __c); 00537 this->_M_invalidate_all(); 00538 return *this; 00539 } 00540 00541 template<typename _InputIterator> 00542 basic_string& 00543 replace(iterator __i1, iterator __i2, 00544 _InputIterator __j1, _InputIterator __j2) 00545 { 00546 __glibcxx_check_erase_range(__i1, __i2); 00547 __glibcxx_check_valid_range(__j1, __j2); 00548 _Base::replace(__i1.base(), __i2.base(), __j1, __j2); 00549 this->_M_invalidate_all(); 00550 return *this; 00551 } 00552 00553 size_type 00554 copy(_CharT* __s, size_type __n, size_type __pos = 0) const 00555 { 00556 __glibcxx_check_string_len(__s, __n); 00557 return _Base::copy(__s, __n, __pos); 00558 } 00559 00560 void 00561 swap(basic_string<_CharT,_Traits,_Allocator>& __x) 00562 { 00563 _Base::swap(__x); 00564 this->_M_swap(__x); 00565 this->_M_invalidate_all(); 00566 __x._M_invalidate_all(); 00567 } 00568 00569 // 21.3.6 string operations: 00570 const _CharT* 00571 c_str() const 00572 { 00573 const _CharT* __res = _Base::c_str(); 00574 this->_M_invalidate_all(); 00575 return __res; 00576 } 00577 00578 const _CharT* 00579 data() const 00580 { 00581 const _CharT* __res = _Base::data(); 00582 this->_M_invalidate_all(); 00583 return __res; 00584 } 00585 00586 using _Base::get_allocator; 00587 00588 size_type 00589 find(const basic_string& __str, size_type __pos = 0) const 00590 { return _Base::find(__str, __pos); } 00591 00592 size_type 00593 find(const _CharT* __s, size_type __pos, size_type __n) const 00594 { 00595 __glibcxx_check_string(__s); 00596 return _Base::find(__s, __pos, __n); 00597 } 00598 00599 size_type 00600 find(const _CharT* __s, size_type __pos = 0) const 00601 { 00602 __glibcxx_check_string(__s); 00603 return _Base::find(__s, __pos); 00604 } 00605 00606 size_type 00607 find(_CharT __c, size_type __pos = 0) const 00608 { return _Base::find(__c, __pos); } 00609 00610 size_type 00611 rfind(const basic_string& __str, size_type __pos = _Base::npos) const 00612 { return _Base::rfind(__str, __pos); } 00613 00614 size_type 00615 rfind(const _CharT* __s, size_type __pos, size_type __n) const 00616 { 00617 __glibcxx_check_string_len(__s, __n); 00618 return _Base::rfind(__s, __pos, __n); 00619 } 00620 00621 size_type 00622 rfind(const _CharT* __s, size_type __pos = _Base::npos) const 00623 { 00624 __glibcxx_check_string(__s); 00625 return _Base::rfind(__s, __pos); 00626 } 00627 00628 size_type 00629 rfind(_CharT __c, size_type __pos = _Base::npos) const 00630 { return _Base::rfind(__c, __pos); } 00631 00632 size_type 00633 find_first_of(const basic_string& __str, size_type __pos = 0) const 00634 { return _Base::find_first_of(__str, __pos); } 00635 00636 size_type 00637 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const 00638 { 00639 __glibcxx_check_string(__s); 00640 return _Base::find_first_of(__s, __pos, __n); 00641 } 00642 00643 size_type 00644 find_first_of(const _CharT* __s, size_type __pos = 0) const 00645 { 00646 __glibcxx_check_string(__s); 00647 return _Base::find_first_of(__s, __pos); 00648 } 00649 00650 size_type 00651 find_first_of(_CharT __c, size_type __pos = 0) const 00652 { return _Base::find_first_of(__c, __pos); } 00653 00654 size_type 00655 find_last_of(const basic_string& __str, size_type __pos = _Base::npos) const 00656 { return _Base::find_last_of(__str, __pos); } 00657 00658 size_type 00659 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const 00660 { 00661 __glibcxx_check_string(__s); 00662 return _Base::find_last_of(__s, __pos, __n); 00663 } 00664 00665 size_type 00666 find_last_of(const _CharT* __s, size_type __pos = _Base::npos) const 00667 { 00668 __glibcxx_check_string(__s); 00669 return _Base::find_last_of(__s, __pos); 00670 } 00671 00672 size_type 00673 find_last_of(_CharT __c, size_type __pos = _Base::npos) const 00674 { return _Base::find_last_of(__c, __pos); } 00675 00676 size_type 00677 find_first_not_of(const basic_string& __str, size_type __pos = 0) const 00678 { return _Base::find_first_not_of(__str, __pos); } 00679 00680 size_type 00681 find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const 00682 { 00683 __glibcxx_check_string_len(__s, __n); 00684 return _Base::find_first_not_of(__s, __pos, __n); 00685 } 00686 00687 size_type 00688 find_first_not_of(const _CharT* __s, size_type __pos = 0) const 00689 { 00690 __glibcxx_check_string(__s); 00691 return _Base::find_first_not_of(__s, __pos); 00692 } 00693 00694 size_type 00695 find_first_not_of(_CharT __c, size_type __pos = 0) const 00696 { return _Base::find_first_not_of(__c, __pos); } 00697 00698 size_type 00699 find_last_not_of(const basic_string& __str, 00700 size_type __pos = _Base::npos) const 00701 { return _Base::find_last_not_of(__str, __pos); } 00702 00703 size_type 00704 find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const 00705 { 00706 __glibcxx_check_string(__s); 00707 return _Base::find_last_not_of(__s, __pos, __n); 00708 } 00709 00710 size_type 00711 find_last_not_of(const _CharT* __s, size_type __pos = _Base::npos) const 00712 { 00713 __glibcxx_check_string(__s); 00714 return _Base::find_last_not_of(__s, __pos); 00715 } 00716 00717 size_type 00718 find_last_not_of(_CharT __c, size_type __pos = _Base::npos) const 00719 { return _Base::find_last_not_of(__c, __pos); } 00720 00721 basic_string 00722 substr(size_type __pos = 0, size_type __n = _Base::npos) const 00723 { return basic_string(_Base::substr(__pos, __n)); } 00724 00725 int 00726 compare(const basic_string& __str) const 00727 { return _Base::compare(__str); } 00728 00729 int 00730 compare(size_type __pos1, size_type __n1, 00731 const basic_string& __str) const 00732 { return _Base::compare(__pos1, __n1, __str); } 00733 00734 int 00735 compare(size_type __pos1, size_type __n1, const basic_string& __str, 00736 size_type __pos2, size_type __n2) const 00737 { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); } 00738 00739 int 00740 compare(const _CharT* __s) const 00741 { 00742 __glibcxx_check_string(__s); 00743 return _Base::compare(__s); 00744 } 00745 00746 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00747 // 5. string::compare specification questionable 00748 int 00749 compare(size_type __pos1, size_type __n1, const _CharT* __s) const 00750 { 00751 __glibcxx_check_string(__s); 00752 return _Base::compare(__pos1, __n1, __s); 00753 } 00754 00755 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00756 // 5. string::compare specification questionable 00757 int 00758 compare(size_type __pos1, size_type __n1,const _CharT* __s, 00759 size_type __n2) const 00760 { 00761 __glibcxx_check_string_len(__s, __n2); 00762 return _Base::compare(__pos1, __n1, __s, __n2); 00763 } 00764 00765 _Base& 00766 _M_base() { return *this; } 00767 00768 const _Base& 00769 _M_base() const { return *this; } 00770 00771 using _Safe_base::_M_invalidate_all; 00772 }; 00773 00774 template<typename _CharT, typename _Traits, typename _Allocator> 00775 inline basic_string<_CharT,_Traits,_Allocator> 00776 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00777 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00778 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; } 00779 00780 template<typename _CharT, typename _Traits, typename _Allocator> 00781 inline basic_string<_CharT,_Traits,_Allocator> 00782 operator+(const _CharT* __lhs, 00783 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00784 { 00785 __glibcxx_check_string(__lhs); 00786 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; 00787 } 00788 00789 template<typename _CharT, typename _Traits, typename _Allocator> 00790 inline basic_string<_CharT,_Traits,_Allocator> 00791 operator+(_CharT __lhs, 00792 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00793 { return basic_string<_CharT,_Traits,_Allocator>(1, __lhs) += __rhs; } 00794 00795 template<typename _CharT, typename _Traits, typename _Allocator> 00796 inline basic_string<_CharT,_Traits,_Allocator> 00797 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00798 const _CharT* __rhs) 00799 { 00800 __glibcxx_check_string(__rhs); 00801 return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; 00802 } 00803 00804 template<typename _CharT, typename _Traits, typename _Allocator> 00805 inline basic_string<_CharT,_Traits,_Allocator> 00806 operator+(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00807 _CharT __rhs) 00808 { return basic_string<_CharT,_Traits,_Allocator>(__lhs) += __rhs; } 00809 00810 template<typename _CharT, typename _Traits, typename _Allocator> 00811 inline bool 00812 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00813 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00814 { return __lhs._M_base() == __rhs._M_base(); } 00815 00816 template<typename _CharT, typename _Traits, typename _Allocator> 00817 inline bool 00818 operator==(const _CharT* __lhs, 00819 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00820 { 00821 __glibcxx_check_string(__lhs); 00822 return __lhs == __rhs._M_base(); 00823 } 00824 00825 template<typename _CharT, typename _Traits, typename _Allocator> 00826 inline bool 00827 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00828 const _CharT* __rhs) 00829 { 00830 __glibcxx_check_string(__rhs); 00831 return __lhs._M_base() == __rhs; 00832 } 00833 00834 template<typename _CharT, typename _Traits, typename _Allocator> 00835 inline bool 00836 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00837 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00838 { return __lhs._M_base() != __rhs._M_base(); } 00839 00840 template<typename _CharT, typename _Traits, typename _Allocator> 00841 inline bool 00842 operator!=(const _CharT* __lhs, 00843 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00844 { 00845 __glibcxx_check_string(__lhs); 00846 return __lhs != __rhs._M_base(); 00847 } 00848 00849 template<typename _CharT, typename _Traits, typename _Allocator> 00850 inline bool 00851 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00852 const _CharT* __rhs) 00853 { 00854 __glibcxx_check_string(__rhs); 00855 return __lhs._M_base() != __rhs; 00856 } 00857 00858 template<typename _CharT, typename _Traits, typename _Allocator> 00859 inline bool 00860 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00861 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00862 { return __lhs._M_base() < __rhs._M_base(); } 00863 00864 template<typename _CharT, typename _Traits, typename _Allocator> 00865 inline bool 00866 operator<(const _CharT* __lhs, 00867 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00868 { 00869 __glibcxx_check_string(__lhs); 00870 return __lhs < __rhs._M_base(); 00871 } 00872 00873 template<typename _CharT, typename _Traits, typename _Allocator> 00874 inline bool 00875 operator<(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00876 const _CharT* __rhs) 00877 { 00878 __glibcxx_check_string(__rhs); 00879 return __lhs._M_base() < __rhs; 00880 } 00881 00882 template<typename _CharT, typename _Traits, typename _Allocator> 00883 inline bool 00884 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00885 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00886 { return __lhs._M_base() <= __rhs._M_base(); } 00887 00888 template<typename _CharT, typename _Traits, typename _Allocator> 00889 inline bool 00890 operator<=(const _CharT* __lhs, 00891 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00892 { 00893 __glibcxx_check_string(__lhs); 00894 return __lhs <= __rhs._M_base(); 00895 } 00896 00897 template<typename _CharT, typename _Traits, typename _Allocator> 00898 inline bool 00899 operator<=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00900 const _CharT* __rhs) 00901 { 00902 __glibcxx_check_string(__rhs); 00903 return __lhs._M_base() <= __rhs; 00904 } 00905 00906 template<typename _CharT, typename _Traits, typename _Allocator> 00907 inline bool 00908 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00909 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00910 { return __lhs._M_base() >= __rhs._M_base(); } 00911 00912 template<typename _CharT, typename _Traits, typename _Allocator> 00913 inline bool 00914 operator>=(const _CharT* __lhs, 00915 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00916 { 00917 __glibcxx_check_string(__lhs); 00918 return __lhs >= __rhs._M_base(); 00919 } 00920 00921 template<typename _CharT, typename _Traits, typename _Allocator> 00922 inline bool 00923 operator>=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00924 const _CharT* __rhs) 00925 { 00926 __glibcxx_check_string(__rhs); 00927 return __lhs._M_base() >= __rhs; 00928 } 00929 00930 template<typename _CharT, typename _Traits, typename _Allocator> 00931 inline bool 00932 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00933 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00934 { return __lhs._M_base() > __rhs._M_base(); } 00935 00936 template<typename _CharT, typename _Traits, typename _Allocator> 00937 inline bool 00938 operator>(const _CharT* __lhs, 00939 const basic_string<_CharT,_Traits,_Allocator>& __rhs) 00940 { 00941 __glibcxx_check_string(__lhs); 00942 return __lhs > __rhs._M_base(); 00943 } 00944 00945 template<typename _CharT, typename _Traits, typename _Allocator> 00946 inline bool 00947 operator>(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 00948 const _CharT* __rhs) 00949 { 00950 __glibcxx_check_string(__rhs); 00951 return __lhs._M_base() > __rhs; 00952 } 00953 00954 // 21.3.7.8: 00955 template<typename _CharT, typename _Traits, typename _Allocator> 00956 inline void 00957 swap(basic_string<_CharT,_Traits,_Allocator>& __lhs, 00958 basic_string<_CharT,_Traits,_Allocator>& __rhs) 00959 { __lhs.swap(__rhs); } 00960 00961 template<typename _CharT, typename _Traits, typename _Allocator> 00962 std::basic_ostream<_CharT, _Traits>& 00963 operator<<(std::basic_ostream<_CharT, _Traits>& __os, 00964 const basic_string<_CharT, _Traits, _Allocator>& __str) 00965 { return __os << __str._M_base(); } 00966 00967 template<typename _CharT, typename _Traits, typename _Allocator> 00968 std::basic_istream<_CharT,_Traits>& 00969 operator>>(std::basic_istream<_CharT,_Traits>& __is, 00970 basic_string<_CharT,_Traits,_Allocator>& __str) 00971 { 00972 std::basic_istream<_CharT,_Traits>& __res = __is >> __str._M_base(); 00973 __str._M_invalidate_all(); 00974 return __res; 00975 } 00976 00977 template<typename _CharT, typename _Traits, typename _Allocator> 00978 std::basic_istream<_CharT,_Traits>& 00979 getline(std::basic_istream<_CharT,_Traits>& __is, 00980 basic_string<_CharT,_Traits,_Allocator>& __str, _CharT __delim) 00981 { 00982 std::basic_istream<_CharT,_Traits>& __res = getline(__is, 00983 __str._M_base(), 00984 __delim); 00985 __str._M_invalidate_all(); 00986 return __res; 00987 } 00988 00989 template<typename _CharT, typename _Traits, typename _Allocator> 00990 std::basic_istream<_CharT,_Traits>& 00991 getline(std::basic_istream<_CharT,_Traits>& __is, 00992 basic_string<_CharT,_Traits,_Allocator>& __str) 00993 { 00994 std::basic_istream<_CharT,_Traits>& __res = getline(__is, 00995 __str._M_base()); 00996 __str._M_invalidate_all(); 00997 return __res; 00998 } 00999 } // namespace __gnu_debug 01000 01001 #endif

Generated on Wed Sep 8 10:19:53 2004 for libstdc++-v3 Source by doxygen 1.3.8