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

📄 _string.h

📁 stl的源码
💻 H
📖 第 1 页 / 共 3 页
字号:
    erase(begin() + __pos, begin() + __pos + (min) (__n, size() - __pos));    return *this;  }  iterator erase(iterator __pos) {    // The move includes the terminating _CharT().    _Traits::move(__pos, __pos + 1, this->_M_Finish() - __pos);    --this->_M_finish;    return __pos;  }  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);      this->_M_finish = this->_M_Finish() - (__last - __first);    }    return __first;  }public:                         // Replace.  (Conceptually equivalent                                // to erase followed by insert.)  _Self& replace(size_type __pos, size_type __n, const _Self& __s) {    const size_type __size = size();    if (__pos > __size)      this->_M_throw_out_of_range();    const size_type __len = (min) (__n, __size - __pos);    if (__s.size() > max_size() - (__size - __len))      this->_M_throw_length_error();    return _M_replace(begin() + __pos, begin() + __pos + __len,                      __s._M_Start(), __s._M_Finish(), &__s == this);  }  _Self& replace(size_type __pos1, size_type __n1, const _Self& __s,                 size_type __pos2, size_type __n2) {    const size_type __size1 = size();    const size_type __size2 = __s.size();    if (__pos1 > __size1 || __pos2 > __size2)      this->_M_throw_out_of_range();    const size_type __len1 = (min) (__n1, __size1 - __pos1);    const size_type __len2 = (min) (__n2, __size2 - __pos2);    if (__len2 > max_size() - (__size1 - __len1))      this->_M_throw_length_error();    return _M_replace(begin() + __pos1, begin() + __pos1 + __len1,                      __s._M_Start() + __pos2, __s._M_Start() + __pos2 + __len2, &__s == this);  }  _Self& replace(size_type __pos, size_type __n1,                 const _CharT* __s, size_type __n2) {    _STLP_FIX_LITERAL_BUG(__s)    const size_type __size = size();    if (__pos > __size)      this->_M_throw_out_of_range();    const size_type __len = (min) (__n1, __size - __pos);    if (__n2 > max_size() - (__size - __len))      this->_M_throw_length_error();    return _M_replace(begin() + __pos, begin() + __pos + __len,                      __s, __s + __n2, _M_inside(__s));  }  _Self& replace(size_type __pos, size_type __n1, const _CharT* __s) {    _STLP_FIX_LITERAL_BUG(__s)    return replace(__pos, __n1, __s, _Traits::length(__s));  }  _Self& replace(size_type __pos, size_type __n1,                 size_type __n2, _CharT __c) {    const size_type __size = size();    if (__pos > __size)      this->_M_throw_out_of_range();    const size_type __len = (min) (__n1, __size - __pos);    if (__n2 > max_size() - (__size - __len))      this->_M_throw_length_error();    return replace(begin() + __pos, begin() + __pos + __len, __n2, __c);  }  _Self& replace(iterator __first, iterator __last, const _Self& __s) {    _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last)    return _M_replace(__first, __last, __s._M_Start(), __s._M_Finish(), &__s == this);  }  _Self& replace(iterator __first, iterator __last,                 const _CharT* __s, size_type __n) {    _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last)    _STLP_FIX_LITERAL_BUG(__s)    return _M_replace(__first, __last, __s, __s + __n, _M_inside(__s));  }  _Self& replace(iterator __first, iterator __last,                 const _CharT* __s) {    _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last)    _STLP_FIX_LITERAL_BUG(__s)    return _M_replace(__first, __last, __s, __s + _Traits::length(__s), _M_inside(__s));  }  _Self& replace(iterator __first, iterator __last, size_type __n, _CharT __c);_STLP_PRIVATE:                        // Helper functions for replace.  _Self& _M_replace(iterator __first, iterator __last,                    const _CharT* __f, const _CharT* __l, bool __self_ref);#if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)  template <class _Integer>  _Self& _M_replace_dispatch(iterator __first, iterator __last,                             _Integer __n, _Integer __x, const __true_type& /*IsIntegral*/) {    _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)    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& /*IsIntegral*/) {    _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)    /* We are forced to do a temporary string to avoid the self referencing issue. */    const _Self __self(__f, __l, get_allocator());    return _M_replace(__first, __last, __self._M_Start(), __self._M_Finish(), false);  }public:  // Check to see if _InputIter is an integer type.  If so, then  // it can't be an iterator.  template <class _InputIter>  _Self& replace(iterator __first, iterator __last,                 _InputIter __f, _InputIter __l) {    _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last)    typedef typename _IsIntegral<_InputIter>::_Ret _Integral;    return _M_replace_dispatch(__first, __last, __f, __l,  _Integral());  }#endif#if !defined (_STLP_MEMBER_TEMPLATES) || !defined (_STLP_NO_METHOD_SPECIALIZATION)public:  _Self& replace(iterator __first, iterator __last,                 const _CharT* __f, const _CharT* __l) {    _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last)    _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)    return _M_replace(__first, __last, __f, __l, _M_inside(__f));  }#endifpublic:                         // 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) { this->_M_swap(__s); }#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)  void _M_swap_workaround(_Self& __x) { swap(__x); }#endifpublic:                         // 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()); }  size_type find_first_not_of(const _CharT* __s, size_type __pos = 0) const  { _STLP_FIX_LITERAL_BUG(__s) return find_first_not_of(__s, __pos, _Traits::length(__s)); }  size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const;  size_type find_first_not_of(_CharT __c, size_type __pos = 0) const;public: // find_last_not_of  size_type find_last_not_of(const _Self& __s, size_type __pos = npos) const  { return find_last_not_of(__s._M_Start(), __pos, __s.size()); }  size_type find_last_not_of(const _CharT* __s, size_type __pos = npos) const  { _STLP_FIX_LITERAL_BUG(__s) return find_last_not_of(__s, __pos, _Traits::length(__s)); }  size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const;  size_type find_last_not_of(_CharT __c, size_type __pos = npos) const;public: // Substring.  _Self substr(size_type __pos = 0, size_type __n = npos) const  { return _Self(*this, __pos, __n, get_allocator()); }public: // Compare  int compare(const _Self& __s) const  { return _M_compare(this->_M_Start(), this->_M_Finish(), __s._M_Start(), __s._M_Finish()); }  int compare(size_type __pos1, size_type __n1, const _Self& __s) const {    if (__pos1 > size())      this->_M_throw_out_of_range();    return _M_compare(this->_M_Start() + __pos1,                      this->_M_Start() + __pos1 + (min) (__n1, size() - __pos1),                      __s._M_Start(), __s._M_Finish());  }  int compare(size_type __pos1, size_type __n1, const _Self& __s,              size_type __pos2, size_type __n2) const {    if (__pos1 > size() || __pos2 > __s.size())      this->_M_throw_out_of_range();    return _M_compare(this->_M_Start() + __pos1,                      this->_M_Start() + __pos1 + (min) (__n1, size() - __pos1),                      __s._M_Start() + __pos2,                      __s._M_Start() + __pos2 + (min) (__n2, __s.size() - __pos2));  }  int compare(const _CharT* __s) const {    _STLP_FIX_LITERAL_BUG(__s)    return _M_compare(this->_M_Start(), this->_M_Finish(), __s, __s + _Traits::length(__s));  }  int compare(size_type __pos1, size_type __n1, const _CharT* __s) const {    _STLP_FIX_LITERAL_BUG(__s)    if (__pos1 > size())      this->_M_throw_out_of_range();    return _M_compare(this->_M_Start() + __pos1,                      this->_M_Start() + __pos1 + (min) (__n1, size() - __pos1),                      __s, __s + _Traits::length(__s));  }  int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const {    _STLP_FIX_LITERAL_BUG(__s)    if (__pos1 > size())      this->_M_throw_out_of_range();    return _M_compare(this->_M_Start() + __pos1,                      this->_M_Start() + __pos1 + (min) (__n1, size() - __pos1),                      __s, __s + __n2);  }public: // Helper functions for compare.  static int _STLP_CALL _M_compare(const _CharT* __f1, const _CharT* __l1,                                   const _CharT* __f2, const _CharT* __l2) {    const ptrdiff_t __n1 = __l1 - __f1;    const ptrdiff_t __n2 = __l2 - __f2;    const int cmp = _Traits::compare(__f1, __f2, (min) (__n1, __n2));    return cmp != 0 ? cmp : (__n1 < __n2 ? -1 : (__n1 > __n2 ? 1 : 0));  }#if defined (_STLP_USE_TEMPLATE_EXPRESSION) && !defined (_STLP_DEBUG) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)#  define _STLP_STRING_SUM_BASE(__reserve, __size, __alloc) _STLP_PRIV _String_base<_CharT,_Alloc>(__alloc, __size + 1)#  include <stl/_string_sum_methods.h>#  undef _STLP_STRING_SUM_BASE#endif};#undef _STLP_PRIVATE#if defined (__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 96)template <class _CharT, class _Traits, class _Alloc>const size_t basic_string<_CharT, _Traits, _Alloc>::npos = ~(size_t) 0;#endif#if defined (_STLP_USE_TEMPLATE_EXPORT)_STLP_EXPORT_TEMPLATE_CLASS basic_string<char, char_traits<char>, allocator<char> >;#  if defined (_STLP_HAS_WCHAR_T)_STLP_EXPORT_TEMPLATE_CLASS basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;#  endif#endif /* _STLP_USE_TEMPLATE_EXPORT */#if defined (basic_string)_STLP_MOVE_TO_STD_NAMESPACE#  undef basic_string#endif_STLP_END_NAMESPACE#if defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)#  include <stl/_string_workaround.h>#endif#if defined (_STLP_DEBUG)#  include <stl/debug/_string.h>#endif_STLP_BEGIN_NAMESPACE// ------------------------------------------------------------// Non-member functions.// Swap.#if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)template <class _CharT, class _Traits, class _Alloc>inline void _STLP_CALLswap(basic_string<_CharT,_Traits,_Alloc>& __x,     basic_string<_CharT,_Traits,_Alloc>& __y){ __x.swap(__y); }#elseinline void _STLP_CALL swap(string& __x, string& __y){ __x.swap(__y); }#  if defined (_STLP_HAS_WCHAR_T)inline void _STLP_CALL swap(wstring& __x, wstring& __y){ __x.swap(__y); }#  endif#endif#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_NO_MOVE_SEMANTIC)template <class _CharT, class _Traits, class _Alloc>struct __move_traits<basic_string<_CharT, _Traits, _Alloc> > {  typedef __true_type implemented;  //Completness depends on the allocator:  typedef typename __move_traits<_Alloc>::complete complete;};/*#else * There is no need to specialize for string and wstring in this case * as the default __move_traits will already tell that string is movable * but not complete. We cannot define it as complete as nothing guaranty * that the STLport user hasn't specialized std::allocator for char or * wchar_t. */#endif_STLP_MOVE_TO_PRIV_NAMESPACEtemplate <class _CharT, class _Traits, class _Alloc>void _STLP_CALL _S_string_copy(const basic_string<_CharT,_Traits,_Alloc>& __s,                               _CharT* __buf, size_t __n);#if defined(_STLP_USE_WIDE_INTERFACE)// A couple of functions to transfer between ASCII/Unicodewstring __ASCIIToWide(const char *ascii);string __WideToASCII(const wchar_t *wide);#endifinline const char* _STLP_CALL__get_c_string(const string& __str) { return __str.c_str(); }_STLP_MOVE_TO_STD_NAMESPACE_STLP_END_NAMESPACE#include <stl/_string_operators.h>#if defined(_STLP_USE_NO_IOSTREAMS) || \    (defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION))#  include <stl/_string.c>#endif#endif /* _STLP_INTERNAL_STRING_H *//* * Local Variables: * mode:C++ * End: */

⌨️ 快捷键说明

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