⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _string.h

📁 MONA是为数不多的C++语言编写的一个很小的操作系统
💻 H
📖 第 1 页 / 共 4 页
字号:
	  }	}  template <class _ForwardIter>   void insert(iterator __position, _ForwardIter __first, _ForwardIter __last, 	      const forward_iterator_tag &)  {    if (__first != __last) {      difference_type __n = distance(__first, __last);      if (this->_M_end_of_storage._M_data - this->_M_finish >= __n + 1) {	const difference_type __elems_after = this->_M_finish - __position;	pointer __old_finish = this->_M_finish;	if (__elems_after >= __n) {	  uninitialized_copy((this->_M_finish - __n) + 1, this->_M_finish + 1,			     this->_M_finish + 1);	  this->_M_finish += __n;	  _Traits::move(__position + __n,			__position, (__elems_after - __n) + 1);	  _M_move(__first, __last, __position);	      }	else {	  _ForwardIter __mid = __first;	  advance(__mid, __elems_after + 1);	  uninitialized_copy(__mid, __last, this->_M_finish + 1);	  this->_M_finish += __n - __elems_after;	        _STLP_TRY {	          uninitialized_copy(__position, __old_finish + 1, this->_M_finish);	          this->_M_finish += __elems_after;	        }	        _STLP_UNWIND((_STLP_STD::_Destroy(__old_finish + 1, this->_M_finish), 	                      this->_M_finish = __old_finish));	        _M_move(__first, __mid, __position);	}      }      else {	const size_type __old_size = size();        	const size_type __len	  = __old_size + (max)(__old_size, __STATIC_CAST(size_type,__n)) + 1;	      pointer __new_start = this->_M_end_of_storage.allocate(__len);	      pointer __new_finish = __new_start;	      _STLP_TRY {	        __new_finish = uninitialized_copy(this->_M_start, __position, __new_start);	        __new_finish = uninitialized_copy(__first, __last, __new_finish);	        __new_finish	          = uninitialized_copy(__position, this->_M_finish, __new_finish);	        _M_construct_null(__new_finish);	      }	      _STLP_UNWIND((_STLP_STD::_Destroy(__new_start,__new_finish),	                    this->_M_end_of_storage.deallocate(__new_start,__len)));	      _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);	      this->_M_deallocate_block();	      this->_M_start = __new_start;	      this->_M_finish = __new_finish;	      this->_M_end_of_storage._M_data = __new_start + __len; 	    }    }  }  template <class _Integer> void _M_insert_dispatch(iterator __p, _Integer __n, _Integer __x,                          const __true_type&) {    insert(__p, (size_type) __n, (_CharT) __x);  }  template <class _InputIter> void _M_insert_dispatch(iterator __p, _InputIter __first, _InputIter __last,                          const __false_type&) {    insert(__p, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIter));  }  template <class _InputIterator> void   _M_copy(_InputIterator __first, _InputIterator __last, pointer __result) {    for ( ; __first != __last; ++__first, ++__result)      _Traits::assign(*__result, *__first);  }  template <class _InputIterator>  void _M_move(_InputIterator __first, _InputIterator __last, pointer __result) {    //call _M_copy as being here means that __result is not within [__first, __last)    for ( ; __first != __last; ++__first, ++__result)      _Traits::assign(*__result, *__first);  }#endif /* _STLP_MEMBER_TEMPLATES */  pointer _M_insert_aux(pointer, _CharT);  void   _M_copy(const _CharT* __first, const _CharT* __last, _CharT* __result) {    _Traits::copy(__result, __first, __last - __first);  }  void _M_move(const _CharT* __first, const _CharT* __last, _CharT* __result) {    _Traits::move(__result, __first, __last - __first);  }public:                         // Erase.  _Self& erase(size_type __pos = 0, size_type __n = npos) {    if (__pos > size())      this->_M_throw_out_of_range();    erase(begin() + __pos, begin() + __pos + (min) (__n, size() - __pos));    return *this;  }    iterator erase(iterator __position) {                                // The move includes the terminating _CharT().    _Traits::move(__position, __position + 1, this->_M_finish - __position);    _STLP_STD::_Destroy(this->_M_finish);    --this->_M_finish;    return __position;  }  iterator erase(iterator __first, iterator __last) {    if (__first != __last) {                                // The move includes the terminating _CharT().      traits_type::move(__first, __last, (this->_M_finish - __last) + 1);      pointer __new_finish = this->_M_finish - (__last - __first);      _STLP_STD::_Destroy(__new_finish + 1, this->_M_finish + 1);      this->_M_finish = __new_finish;    }    return __first;  }public:                         // Replace.  (Conceptually equivalent                                // to erase followed by insert.)  _Self& replace(size_type __pos, size_type __n,                         const _Self& __s) {    if (__pos > size())      this->_M_throw_out_of_range();    const size_type __len = (min) (__n, size() - __pos);    if (size() - __len >= max_size() - __s.size())      this->_M_throw_length_error();    return replace(begin() + __pos, begin() + __pos + __len,                    __s._M_start, __s._M_finish);  }  _Self& replace(size_type __pos1, size_type __n1,                        const _Self& __s,                        size_type __pos2, size_type __n2) {    if (__pos1 > size() || __pos2 > __s.size())      this->_M_throw_out_of_range();    const size_type __len1 = (min) (__n1, size() - __pos1);    const size_type __len2 = (min) (__n2, __s.size() - __pos2);    if (size() - __len1 >= max_size() - __len2)      this->_M_throw_length_error();    return replace(begin() + __pos1, begin() + __pos1 + __len1,                   __s._M_start + __pos2, __s._M_start + __pos2 + __len2);  }  _Self& replace(size_type __pos, size_type __n1,                        const _CharT* __s, size_type __n2) {    _STLP_FIX_LITERAL_BUG(__s)    if (__pos > size())      this->_M_throw_out_of_range();    const size_type __len = (min) (__n1, size() - __pos);    if (__n2 > max_size() || size() - __len >= max_size() - __n2)      this->_M_throw_length_error();    return replace(begin() + __pos, begin() + __pos + __len,                   __s, __s + __n2);  }  _Self& replace(size_type __pos, size_type __n1,                        const _CharT* __s) {    _STLP_FIX_LITERAL_BUG(__s)    if (__pos > size())      this->_M_throw_out_of_range();    const size_type __len = (min) (__n1, size() - __pos);    const size_type __n2 = _Traits::length(__s);    if (__n2 > max_size() || size() - __len >= max_size() - __n2)      this->_M_throw_length_error();    return replace(begin() + __pos, begin() + __pos + __len,                   __s, __s + _Traits::length(__s));  }  _Self& replace(size_type __pos, size_type __n1,                        size_type __n2, _CharT __c) {    if (__pos > size())      this->_M_throw_out_of_range();    const size_type __len = (min) (__n1, size() - __pos);    if (__n2 > max_size() || size() - __len >= max_size() - __n2)      this->_M_throw_length_error();    return replace(begin() + __pos, begin() + __pos + __len, __n2, __c);  }  _Self& replace(iterator __first, iterator __last,                         const _Self& __s)     { return replace(__first, __last, __s._M_start, __s._M_finish); }  _Self& replace(iterator __first, iterator __last,                        const _CharT* __s, size_type __n)     { _STLP_FIX_LITERAL_BUG(__s) return replace(__first, __last, __s, __s + __n); }  _Self& replace(iterator __first, iterator __last,                        const _CharT* __s) {    _STLP_FIX_LITERAL_BUG(__s)    return replace(__first, __last, __s, __s + _Traits::length(__s));  }  _Self& replace(iterator __first, iterator __last,                         size_type __n, _CharT __c);  // Check to see if _InputIterator is an integer type.  If so, then  // it can't be an iterator.#ifdef _STLP_MEMBER_TEMPLATES  template <class _InputIter> _Self& replace(iterator __first, iterator __last,                        _InputIter __f, _InputIter __l) {    typedef typename _Is_integer<_InputIter>::_Integral _Integral;    return _M_replace_dispatch(__first, __last, __f, __l,  _Integral());  }#else /* _STLP_MEMBER_TEMPLATES */  _Self& replace(iterator __first, iterator __last,		 const _CharT* __f, const _CharT* __l);#endif /* _STLP_MEMBER_TEMPLATES */private:                        // Helper functions for replace.#ifdef _STLP_MEMBER_TEMPLATES  template <class _Integer> _Self& _M_replace_dispatch(iterator __first, iterator __last,                                    _Integer __n, _Integer __x,                                    const __true_type&) {    return replace(__first, __last, (size_type) __n, (_CharT) __x);  }  template <class _InputIter> _Self& _M_replace_dispatch(iterator __first, iterator __last,                                    _InputIter __f, _InputIter __l,                                    const __false_type&) {    return replace(__first, __last, __f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));  }  template <class _InputIter> _Self& replace(iterator __first, iterator __last,                        _InputIter __f, _InputIter __l, const input_iterator_tag &)  {	  for ( ; __first != __last && __f != __l; ++__first, ++__f)	    _Traits::assign(*__first, *__f);	  if (__f == __l)	    erase(__first, __last);	  else	    insert(__last, __f, __l);	  return *this;	}  template <class _InputIter>  _Self& replace(iterator __first, iterator __last,                 _InputIter __f, _InputIter __l, const random_access_iterator_tag &) {    //might be overlapping    if (_M_inside(__f)) {      difference_type __n = __l - __f;      const difference_type __len = __last - __first;      if (__len >= __n) {        _M_move(__f, __l, __first);        erase(__first + __n, __last);      }      else {        _InputIter __m = __f + __len;        if ((__l <= __first) || (__f >= __last)) {				  //no overlap:          _M_copy(__f, __m, __first);          insert(__last, __m, __l);        }        else {				  //we have to take care of reallocation:				  const difference_type __off_dest = __first - this->begin();				  const difference_type __off_src = __f - this->begin();				  insert(__last, __m, __l);				  _Traits::move(begin() + __off_dest, begin() + __off_src, __n);        }      }      return *this;    }	  else {		  return replace(__first, __last, __f, __l, forward_iterator_tag());	  }  }  template <class _ForwardIter> _Self& replace(iterator __first, iterator __last,                        _ForwardIter __f, _ForwardIter __l,                         const forward_iterator_tag &)  {	  difference_type __n = distance(__f, __l);	  const difference_type __len = __last - __first;	  if (__len >= __n) {	    _M_copy(__f, __l, __first);	    erase(__first + __n, __last);	  }	  else {	    _ForwardIter __m = __f;	    advance(__m, __len);	    _M_copy(__f, __m, __first);	    insert(__last, __m, __l);	  }	  return *this;	}#endif /* _STLP_MEMBER_TEMPLATES */public:                         // Other modifier member functions.  size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const {    _STLP_FIX_LITERAL_BUG(__s)    if (__pos > size())      this->_M_throw_out_of_range();    const size_type __len = (min) (__n, size() - __pos);    _Traits::copy(__s, this->_M_start + __pos, __len);    return __len;  }  void swap(_Self& __s) {    _STLP_STD::swap(this->_M_start, __s._M_start);    _STLP_STD::swap(this->_M_finish, __s._M_finish);    _STLP_STD::swap(this->_M_end_of_storage, __s._M_end_of_storage);  }public:                         // Conversion to C string.  const _CharT* c_str() const { return this->_M_start; }  const _CharT* data()  const { return this->_M_start; }public:                         // find.  size_type find(const _Self& __s, size_type __pos = 0) const     { return find(__s._M_start, __pos, __s.size()); }  size_type find(const _CharT* __s, size_type __pos = 0) const     { _STLP_FIX_LITERAL_BUG(__s) return find(__s, __pos, _Traits::length(__s)); }  size_type find(const _CharT* __s, size_type __pos, size_type __n) const;  // WIE: Versant schema compiler 5.2.2 ICE workaround  size_type find(_CharT __c) const    { return find(__c, 0) ; }  size_type find(_CharT __c, size_type __pos /* = 0 */) const;public:                         // rfind.  size_type rfind(const _Self& __s, size_type __pos = npos) const     { return rfind(__s._M_start, __pos, __s.size()); }  size_type rfind(const _CharT* __s, size_type __pos = npos) const     { _STLP_FIX_LITERAL_BUG(__s) return rfind(__s, __pos, _Traits::length(__s)); }  size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const;  size_type rfind(_CharT __c, size_type __pos = npos) const;public:                         // find_first_of    size_type find_first_of(const _Self& __s, size_type __pos = 0) const     { return find_first_of(__s._M_start, __pos, __s.size()); }  size_type find_first_of(const _CharT* __s, size_type __pos = 0) const     { _STLP_FIX_LITERAL_BUG(__s) return find_first_of(__s, __pos, _Traits::length(__s)); }  size_type find_first_of(const _CharT* __s, size_type __pos,                           size_type __n) const;  size_type find_first_of(_CharT __c, size_type __pos = 0) const     { return find(__c, __pos); }public:                         // find_last_of  size_type find_last_of(const _Self& __s,                         size_type __pos = npos) const    { return find_last_of(__s._M_start, __pos, __s.size()); }  size_type find_last_of(const _CharT* __s, size_type __pos = npos) const     { _STLP_FIX_LITERAL_BUG(__s) return find_last_of(__s, __pos, _Traits::length(__s)); }  size_type find_last_of(const _CharT* __s, size_type __pos,                          size_type __n) const;  size_type find_last_of(_CharT __c, size_type __pos = npos) const {    return rfind(__c, __pos);  }public:                         // find_first_not_of  size_type find_first_not_of(const _Self& __s,                               size_type __pos = 0) const     { return find_first_not_of(__s._M_start, __pos, __s.size()); }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -