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

📄 _string.h

📁 MONA是为数不多的C++语言编写的一个很小的操作系统
💻 H
📖 第 1 页 / 共 4 页
字号:
      append(__f, __l);    }    _STLP_UNWIND(_STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1));  }  template <class _ForwardIter> void _M_range_initialize(_ForwardIter __f, _ForwardIter __l,                            const forward_iterator_tag &) {    difference_type __n = distance(__f, __l);    this->_M_allocate_block(__n + 1);    this->_M_finish = uninitialized_copy(__f, __l, this->_M_start);    _M_terminate_string();  }  template <class _InputIter> void _M_range_initialize(_InputIter __f, _InputIter __l) {    _M_range_initialize(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));  }  template <class _Integer> void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type&) {    this->_M_allocate_block(__n + 1);    this->_M_finish = uninitialized_fill_n(this->_M_start, __n, __x);    _M_terminate_string();  }  template <class _InputIter> void _M_initialize_dispatch(_InputIter __f, _InputIter __l, const __false_type&) {     _M_range_initialize(__f, __l);  }    #else /* _STLP_MEMBER_TEMPLATES */  void _M_range_initialize(const _CharT* __f, const _CharT* __l) {    ptrdiff_t __n = __l - __f;    this->_M_allocate_block(__n + 1);    this->_M_finish = uninitialized_copy(__f, __l, this->_M_start);    _M_terminate_string();  }#endif /* _STLP_MEMBER_TEMPLATES */public:                         // Iterators.  iterator begin()             { return this->_M_start; }  iterator end()               { return this->_M_finish; }  const_iterator begin() const { return this->_M_start; }  const_iterator end()   const { return this->_M_finish; }    reverse_iterator rbegin()                 { return reverse_iterator(this->_M_finish); }  reverse_iterator rend()                   { return reverse_iterator(this->_M_start); }  const_reverse_iterator rbegin() const     { return const_reverse_iterator(this->_M_finish); }  const_reverse_iterator rend()   const     { return const_reverse_iterator(this->_M_start); }public:                         // Size, capacity, etc.  size_type size() const { return this->_M_finish - this->_M_start; }  size_type length() const { return size(); }  size_t max_size() const { return _Base::max_size(); }  void resize(size_type __n, _CharT __c) {    if (__n <= size())      erase(begin() + __n, end());    else      append(__n - size(), __c);  }  void resize(size_type __n) { resize(__n, _M_null()); }  void reserve(size_type = 0);  size_type capacity() const { return (this->_M_end_of_storage._M_data - this->_M_start) - 1; }  void clear() {    if (!empty()) {      _Traits::assign(*(this->_M_start), _M_null());      _STLP_STD::_Destroy(this->_M_start+1, this->_M_finish+1);      this->_M_finish = this->_M_start;    }  }   bool empty() const { return this->_M_start == this->_M_finish; }    public:                         // Element access.  const_reference operator[](size_type __n) const    { return *(this->_M_start + __n); }  reference operator[](size_type __n)    { return *(this->_M_start + __n); }  const_reference at(size_type __n) const {    if (__n >= size())      this->_M_throw_out_of_range();    return *(this->_M_start + __n);  }  reference at(size_type __n) {    if (__n >= size())      this->_M_throw_out_of_range();    return *(this->_M_start + __n);  }public:                         // Append, operator+=, push_back.  _Self& operator+=(const _Self& __s) { return append(__s); }  _Self& operator+=(const _CharT* __s) { _STLP_FIX_LITERAL_BUG(__s) return append(__s); }  _Self& operator+=(_CharT __c) { push_back(__c); return *this; }  _Self& append(const _Self& __s)     { return append(__s._M_start, __s._M_finish); }  _Self& append(const _Self& __s,                       size_type __pos, size_type __n)  {    if (__pos > __s.size())      this->_M_throw_out_of_range();    return append(__s._M_start + __pos,                  __s._M_start + __pos + (min) (__n, __s.size() - __pos));  }  _Self& append(const _CharT* __s, size_type __n)     { _STLP_FIX_LITERAL_BUG(__s) return append(__s, __s+__n); }  _Self& append(const _CharT* __s)     { _STLP_FIX_LITERAL_BUG(__s) return append(__s, __s + traits_type::length(__s)); }  _Self& append(size_type __n, _CharT __c);#ifdef _STLP_MEMBER_TEMPLATES  // Check to see if _InputIterator is an integer type.  If so, then  // it can't be an iterator.  template <class _InputIter> _Self& append(_InputIter __first, _InputIter __last) {    typedef typename _Is_integer<_InputIter>::_Integral _Integral;    return _M_append_dispatch(__first, __last, _Integral());  }#else /* _STLP_MEMBER_TEMPLATES */  _Self& append(const _CharT* __first, const _CharT* __last);#endif /* _STLP_MEMBER_TEMPLATES */  void push_back(_CharT __c) {    if (this->_M_finish + 1 == this->_M_end_of_storage._M_data)      reserve(size() + (max)(size(), __STATIC_CAST(size_type,1)));    _M_construct_null(this->_M_finish + 1);    _Traits::assign(*(this->_M_finish), __c);    ++this->_M_finish;  }  void pop_back() {    _Traits::assign(*(this->_M_finish - 1), _M_null());    _STLP_STD::_Destroy(this->_M_finish);    --this->_M_finish;  }private:                        // Helper functions for append.#ifdef _STLP_MEMBER_TEMPLATES  template <class _InputIter> _Self& append(_InputIter __first, _InputIter __last, const input_iterator_tag &)  {	  for ( ; __first != __last ; ++__first)	    push_back(*__first);	  return *this;	}  template <class _ForwardIter> _Self& append(_ForwardIter __first, _ForwardIter __last,                        const forward_iterator_tag &)  {    if (__first != __last) {	    const size_type __old_size = size();	    difference_type __n = distance(__first, __last);	    if (__STATIC_CAST(size_type,__n) > max_size() || __old_size > max_size() - __STATIC_CAST(size_type,__n))	      this->_M_throw_length_error();	    if (__old_size + __n > capacity()) {	      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, this->_M_finish, __new_start);	        __new_finish = uninitialized_copy(__first, __last, __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; 	    }	    else {	      _ForwardIter __f1 = __first;	      ++__f1;	      uninitialized_copy(__f1, __last, this->_M_finish + 1);	      _STLP_TRY {	        _M_construct_null(this->_M_finish + __n);	      }	      _STLP_UNWIND(_STLP_STD::_Destroy(this->_M_finish + 1, this->_M_finish + __n));	      _Traits::assign(*end(), *__first);	      this->_M_finish += __n;	    }	  }	  return *this;  	}  template <class _Integer> _Self& _M_append_dispatch(_Integer __n, _Integer __x, const __true_type&) {    return append((size_type) __n, (_CharT) __x);  }  template <class _InputIter> _Self& _M_append_dispatch(_InputIter __f, _InputIter __l,                                   const __false_type&) {    return append(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));  }#endif /* _STLP_MEMBER_TEMPLATES */public:                         // Assign    _Self& assign(const _Self& __s)     { return assign(__s._M_start, __s._M_finish); }  _Self& assign(const _Self& __s,                        size_type __pos, size_type __n) {    if (__pos > __s.size())      this->_M_throw_out_of_range();    return assign(__s._M_start + __pos,                   __s._M_start + __pos + (min) (__n, __s.size() - __pos));  }  _Self& assign(const _CharT* __s, size_type __n)    { _STLP_FIX_LITERAL_BUG(__s) return assign(__s, __s + __n); }  _Self& assign(const _CharT* __s)    { _STLP_FIX_LITERAL_BUG(__s) return assign(__s, __s + _Traits::length(__s)); }  _Self& assign(size_type __n, _CharT __c);#ifdef _STLP_MEMBER_TEMPLATESprivate:                        // Helper functions for assign.  template <class _Integer>   _Self& _M_assign_dispatch(_Integer __n, _Integer __x, const __true_type&) {    return assign((size_type) __n, (_CharT) __x);  }  template <class _InputIter>   _Self& _M_assign_dispatch(_InputIter __f, _InputIter __l,			    const __false_type&)  {    pointer __cur = this->_M_start;    while (__f != __l && __cur != this->_M_finish) {      _Traits::assign(*__cur, *__f);      ++__f;      ++__cur;    }    if (__f == __l)      erase(__cur, end());    else      append(__f, __l);    return *this;  }  public:  // Check to see if _InputIterator is an integer type.  If so, then  // it can't be an iterator.  template <class _InputIter> _Self& assign(_InputIter __first, _InputIter __last) {    typedef typename _Is_integer<_InputIter>::_Integral _Integral;    return _M_assign_dispatch(__first, __last, _Integral());  }#endif  /* _STLP_MEMBER_TEMPLATES */  // if member templates are on, this works as specialization   _Self& assign(const _CharT* __f, const _CharT* __l)  {    ptrdiff_t __n = __l - __f;    if (__STATIC_CAST(size_type,__n) <= size()) {      _Traits::copy(this->_M_start, __f, __n);      erase(begin() + __n, end());    }    else {      _Traits::copy(this->_M_start, __f, size());      append(__f + size(), __l);    }    return *this;  }  public:                         // Insert  _Self& insert(size_type __pos, const _Self& __s) {    if (__pos > size())      this->_M_throw_out_of_range();    if (size() > max_size() - __s.size())      this->_M_throw_length_error();    insert(begin() + __pos, __s._M_start, __s._M_finish);    return *this;  }  _Self& insert(size_type __pos, const _Self& __s,                       size_type __beg, size_type __n) {    if (__pos > size() || __beg > __s.size())      this->_M_throw_out_of_range();    size_type __len = (min) (__n, __s.size() - __beg);    if (size() > max_size() - __len)      this->_M_throw_length_error();    insert(begin() + __pos,           __s._M_start + __beg, __s._M_start + __beg + __len);    return *this;  }  _Self& insert(size_type __pos, const _CharT* __s, size_type __n) {    _STLP_FIX_LITERAL_BUG(__s)    if (__pos > size())      this->_M_throw_out_of_range();    if (size() > max_size() - __n)      this->_M_throw_length_error();    insert(begin() + __pos, __s, __s + __n);    return *this;  }  _Self& insert(size_type __pos, const _CharT* __s) {    _STLP_FIX_LITERAL_BUG(__s)    if (__pos > size())      this->_M_throw_out_of_range();    size_type __len = _Traits::length(__s);    if (size() > max_size() - __len)      this->_M_throw_length_error();    insert(this->_M_start + __pos, __s, __s + __len);    return *this;  }      _Self& insert(size_type __pos, size_type __n, _CharT __c) {    if (__pos > size())      this->_M_throw_out_of_range();    if (size() > max_size() - __n)      this->_M_throw_length_error();    insert(begin() + __pos, __n, __c);    return *this;  }  iterator insert(iterator __p, _CharT __c) {    _STLP_FIX_LITERAL_BUG(__p)    if (__p == end()) {      push_back(__c);      return this->_M_finish - 1;    }    else      return _M_insert_aux(__p, __c);  }  void insert(iterator __p, size_t __n, _CharT __c);#ifdef _STLP_MEMBER_TEMPLATES  // Check to see if _InputIterator is an integer type.  If so, then  // it can't be an iterator.  template <class _InputIter> void insert(iterator __p, _InputIter __first, _InputIter __last) {    typedef typename _Is_integer<_InputIter>::_Integral _Integral;    _M_insert_dispatch(__p, __first, __last, _Integral());  }#else /* _STLP_MEMBER_TEMPLATES */  void insert(iterator __p, const _CharT* __first, const _CharT* __last);#endif /* _STLP_MEMBER_TEMPLATES */private:                        // Helper functions for insert.#ifdef _STLP_MEMBER_TEMPLATES  template <class _InputIter> void insert(iterator __p, _InputIter __first, _InputIter __last,	      const input_iterator_tag &)  {	  for ( ; __first != __last; ++__first) {	    __p = insert(__p, *__first);	    ++__p;

⌨️ 快捷键说明

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