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

📄 string.tcc

📁 c++编程宝典源码及Quincy99编译器 是《标准C++编程宝典》电子工业出版社的光盘
💻 TCC
📖 第 1 页 / 共 2 页
字号:
    basic_string<_CharT, _Traits, _Alloc>::_Rep::    _S_default_excess(size_t __s, size_t __r)#else    basic_string<_CharT, _Traits, _Alloc>::_Rep::    _S_excess_slop(size_t __s, size_t __r)#endif    {      return 2 * (__s <= 16 ? 16 : __s) < __r;    }    // Linker sets _S_empty_rep_storage to all 0s (one reference, empty string)  // at static init time (before static ctors are run).  template<typename _CharT, typename _Traits, typename _Alloc>    typename _Alloc::size_type    basic_string<_CharT, _Traits, _Alloc>::_S_empty_rep_storage[    (sizeof(_Rep) + sizeof(_CharT) + sizeof(size_type) - 1)/sizeof(size_type)];  template<typename _CharT, typename _Traits, typename _Alloc>    void    basic_string<_CharT, _Traits, _Alloc>::resize(size_type __n, _CharT __c)    {      __LENGTHERROR(__n > max_size());      size_type __size = this->size();      if (__size < __n)	this->append(__n - __size, __c);      else if (__n < __size)	this->erase(__n);      // else nothing (in particular, avoid calling _M_mutate() unnecessarily.)    }    template<typename _CharT, typename _Traits, typename _Alloc>    template<typename _InputIter>      basic_string<_CharT, _Traits, _Alloc>&      basic_string<_CharT, _Traits, _Alloc>::      _M_replace(iterator __i1, iterator __i2, _InputIter __j1, 		 _InputIter __j2, input_iterator_tag)      {	basic_string __s(__j1, __j2);	return this->replace(__i1, __i2, __s._M_ibegin(), __s._M_iend());      }  template<typename _CharT, typename _Traits, typename _Alloc>    template<typename _ForwardIter>      basic_string<_CharT, _Traits, _Alloc>&      basic_string<_CharT, _Traits, _Alloc>::      _M_replace(iterator __i1, iterator __i2, _ForwardIter __j1, 		 _ForwardIter __j2, forward_iterator_tag)      {	size_type __dold = __i2 - __i1;	size_type __dmax = this->max_size();	size_type __dnew = static_cast<size_type>(distance(__j1, __j2));	__LENGTHERROR(__dmax <= __dnew);	size_type __off = __i1 - _M_ibegin();	_M_mutate(__off, __dold, __dnew);	// Invalidated __i1, __i2	if (__dnew)	  _S_copy_chars(_M_data() + __off, __j1, __j2);		return *this;      }  template<typename _CharT, typename _Traits, typename _Alloc>    basic_string<_CharT, _Traits, _Alloc>&    basic_string<_CharT, _Traits, _Alloc>::    replace(size_type __pos1, size_type __n1, const basic_string& __str,	    size_type __pos2, size_type __n2)    {      return this->replace(_M_check(__pos1), _M_fold(__pos1, __n1),			   __str._M_check(__pos2), 			   __str._M_fold(__pos2, __n2));    }  template<typename _CharT, typename _Traits, typename _Alloc>    basic_string<_CharT, _Traits, _Alloc>&    basic_string<_CharT, _Traits, _Alloc>::    replace(iterator __i1, iterator __i2, size_type __n2, _CharT __c)    {      size_type __n1 = __i2 - __i1;      size_type __off1 = __i1 - _M_ibegin();      __LENGTHERROR(max_size() - (this->size() - __n1) <= __n2);      _M_mutate (__off1, __n1, __n2);      // Invalidated __i1, __i2      if (__n2)	traits_type::assign(_M_data() + __off1, __n2, __c);      return *this;    }      template<typename _CharT, typename _Traits, typename _Alloc>    basic_string<_CharT, _Traits, _Alloc>::size_type    basic_string<_CharT, _Traits, _Alloc>::    copy(_CharT* __s, size_type __n, size_type __pos) const    {      __OUTOFRANGE(__pos > this->size());            if (__n > this->size() - __pos)	__n = this->size() - __pos;            traits_type::copy(__s, _M_data() + __pos, __n);      // 21.3.5.7 par 3: do not append null.  (good.)      return __n;    }  // String operations  // NB: This is specialized for the standard char_traits<char>  // specialization to use the same optimizations as strchr.  template<typename _CharT, typename _Traits, typename _Alloc>    const _CharT*    basic_string<_CharT, _Traits, _Alloc>::    _S_find(const _CharT* __beg, const _CharT* __end, _CharT __c)    {      return find_if(__beg, __end, _Char_traits_match<_CharT, _Traits>(__c));    }  // Specialization for char, definitions in src/string-inst.cc.  template<>    const char*     string::_S_find(const char* __beg, const char* __end, char __c);  // Specialization for wchar_t.  template<>    const wchar_t*     wstring::_S_find(const wchar_t* __beg, const wchar_t* __end, wchar_t __c);  template<typename _CharT, typename _Traits, typename _Alloc>    basic_string<_CharT, _Traits, _Alloc>::size_type    basic_string<_CharT, _Traits, _Alloc>::    find(const _CharT* __s, size_type __pos, size_type __n) const    {      size_t __xpos = __pos;      const _CharT* __data = _M_data();      for (; __xpos + __n <= this->size(); ++__xpos)	if (traits_type::eq(__data[__xpos], *__s)	    && traits_type::compare(__data + __xpos, __s, __n) == 0)	  return __xpos;      return npos;    }  template<typename _CharT, typename _Traits, typename _Alloc>    basic_string<_CharT, _Traits, _Alloc>::size_type    basic_string<_CharT, _Traits, _Alloc>::    find(_CharT __c, size_type __pos) const    {      size_type __size = this->size();      size_type __retval = npos;      if (__pos < __size)	{	  const _CharT* __data = _M_data();	  const _CharT* __end = __data + __size;	  const _CharT* __p = _S_find(__data + __pos, __end, __c);	  if (__p != __end)	    __retval = __p - __data;	}      return __retval;    }  template<typename _CharT, typename _Traits, typename _Alloc>    basic_string<_CharT, _Traits, _Alloc>::size_type    basic_string<_CharT, _Traits, _Alloc>::    rfind(const _CharT* __s, size_type __pos, size_type __n) const    {      size_type __size = this->size();      if (__n <= __size)	{	  size_t __xpos = __size - __n;	  if (__xpos > __pos)	    __xpos = __pos;      	  for (++__xpos; __xpos-- > 0; )	    if (traits_type::eq(_M_data()[__xpos], *__s)		&& traits_type::compare(_M_data() + __xpos, __s, __n) == 0)	      return __xpos;	}      return npos;    }    template<typename _CharT, typename _Traits, typename _Alloc>    basic_string<_CharT, _Traits, _Alloc>::size_type    basic_string<_CharT, _Traits, _Alloc>::    rfind(_CharT __c, size_type __pos) const    {      size_type __size = this->size();      if (__size)	{	  size_t __xpos = __size - 1;	  if (__xpos > __pos)	    __xpos = __pos;      	  for (++__xpos; __xpos-- > 0; )	    if (traits_type::eq(_M_data()[__xpos], __c))	      return __xpos;	}      return npos;    }    template<typename _CharT, typename _Traits, typename _Alloc>    basic_string<_CharT, _Traits, _Alloc>::size_type    basic_string<_CharT, _Traits, _Alloc>::    find_first_of(const _CharT* __s, size_type __pos, size_type __n) const    {      const _CharT* __end = __s + __n;      for (; __n && __pos < this->size(); ++__pos)	{	  const _CharT* __p = _S_find(__s, __end, _M_data()[__pos]);	  if (__p != __end)	    return __pos;	}      return npos;    }   template<typename _CharT, typename _Traits, typename _Alloc>    basic_string<_CharT, _Traits, _Alloc>::size_type    basic_string<_CharT, _Traits, _Alloc>::    find_last_of(const _CharT* __s, size_type __pos, size_type __n) const    {      size_type __size = this->size();      if (__size && __n)	{ 	  if (--__size > __pos) 	    __size = __pos;	  do	    {	      const _CharT* __p = _S_find(__s, __s + __n, _M_data()[__size]);	      if (__p  != __s + __n)		return __size;	    } 	  while (__size-- != 0);	}      return npos;    }    template<typename _CharT, typename _Traits, typename _Alloc>    basic_string<_CharT, _Traits, _Alloc>::size_type    basic_string<_CharT, _Traits, _Alloc>::    find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const    {      size_t __xpos = __pos;      for (; __n && __xpos < this->size(); ++__xpos)	if (_S_find(__s, __s + __n, _M_data()[__xpos]) == __s + __n)	  return __xpos;      return npos;    }  template<typename _CharT, typename _Traits, typename _Alloc>    basic_string<_CharT, _Traits, _Alloc>::size_type    basic_string<_CharT, _Traits, _Alloc>::    find_first_not_of(_CharT __c, size_type __pos) const    {      size_t __xpos = __pos;      for (; __xpos < size(); ++__xpos)	if (!traits_type::eq(_M_data()[__xpos], __c))	  return __xpos;      return npos;    }  template<typename _CharT, typename _Traits, typename _Alloc>    basic_string<_CharT, _Traits, _Alloc>::size_type    basic_string<_CharT, _Traits, _Alloc>::    find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const    {      size_type __size = this->size();      if (__size && __n)	{ 	  if (--__size > __pos) 	    __size = __pos;	  do	    {	      if (_S_find(__s, __s + __n, _M_data()[__size]) == __s + __n)		return __size;	    } 	  while (__size--);	}      return npos;    }  template<typename _CharT, typename _Traits, typename _Alloc>    basic_string<_CharT, _Traits, _Alloc>::size_type    basic_string<_CharT, _Traits, _Alloc>::    find_last_not_of(_CharT __c, size_type __pos) const    {      size_type __size = this->size();      if (__size)	{ 	  if (--__size > __pos) 	    __size = __pos;	  do	    {	      if (!traits_type::eq(_M_data()[__size], __c))		return __size;	    } 	  while (__size--);	}      return npos;    }    template<typename _CharT, typename _Traits, typename _Alloc>    int    basic_string<_CharT, _Traits, _Alloc>::    compare(size_type __pos, size_type __n, const basic_string& __str) const    {      size_type __size = this->size();      size_type __osize = __str.size();      __OUTOFRANGE(__pos > __size);            size_type __rsize= min(__size - __pos, __n);      size_type __len = min(__rsize, __osize);      int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len);      if (!__r)	__r = __rsize - __osize;      return __r;    }  template<typename _CharT, typename _Traits, typename _Alloc>    int    basic_string<_CharT, _Traits, _Alloc>::    compare(size_type __pos1, size_type __n1, const basic_string& __str,	    size_type __pos2, size_type __n2) const    {      size_type __size = this->size();      size_type __osize = __str.size();      __OUTOFRANGE(__pos1 > __size);      __OUTOFRANGE(__pos2 > __osize);            size_type __rsize = min(__size - __pos1, __n1);      size_type __rosize = min(__osize - __pos2, __n2);      size_type __len = min(__rsize, __rosize);      int __r = traits_type::compare(_M_data() + __pos1, 				     __str.data() + __pos2, __len);      if (!__r)	__r = __rsize - __rosize;      return __r;    }  template<typename _CharT, typename _Traits, typename _Alloc>    int    basic_string<_CharT, _Traits, _Alloc>::    compare(const _CharT* __s) const    {      size_type __size = this->size();      int __r = traits_type::compare(_M_data(), __s, __size);      if (!__r)	__r = __size - traits_type::length(__s);      return __r;    }  template<typename _CharT, typename _Traits, typename _Alloc>    int    basic_string <_CharT,_Traits,_Alloc>::    compare(size_type __pos, size_type __n1, const _CharT* __s, 	    size_type __n2) const    {      size_type __size = this->size();      __OUTOFRANGE(__pos > __size);            size_type __osize = min(traits_type::length(__s), __n2);      size_type __rsize = min(__size - __pos, __n1);      size_type __len = min(__rsize, __osize);      int __r = traits_type::compare(_M_data() + __pos, __s, __len);      if (!__r)	__r = __rsize - __osize;      return __r;    }  template <class _CharT, class _Traits, class _Alloc>    void    _S_string_copy(const basic_string<_CharT, _Traits, _Alloc>& __str,		   _CharT* __buf, typename _Alloc::size_type __bufsiz)    {      typedef typename _Alloc::size_type size_type;      size_type __strsize = __str.size();      size_type __bytes = min(__strsize, __bufsiz - 1);      _Traits::copy(__buf, __str.data(), __bytes);      __buf[__bytes] = _CharT();    }} // std::#endif /* _CPP_BITS_STRING_TCC */// Local Variables:// mode:c++// End:

⌨️ 快捷键说明

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