📄 xstring
字号:
public:
typedef basic_string<_Elem, _Traits, _Ax> _Myt;
typedef _String_val<_Elem, _Ax> _Mybase;
typedef typename _Mybase::_Alty _Alloc;
typedef typename _Alloc::size_type size_type;
typedef typename _Alloc::difference_type difference_type;
typedef typename _Alloc::pointer pointer;
typedef typename _Alloc::const_pointer const_pointer;
typedef typename _Alloc::reference reference;
typedef typename _Alloc::const_reference const_reference;
typedef typename _Alloc::value_type value_type;
typedef _String_iterator<_Elem, _Traits, _Alloc> iterator;
typedef _String_const_iterator<_Elem, _Traits, _Alloc> const_iterator;
typedef _STD reverse_iterator<iterator> reverse_iterator;
typedef _STD reverse_iterator<const_iterator> const_reverse_iterator;
basic_string(const _Myt& _Right)
: _Mybase(_Right._Alval)
{ // construct by copying _Right
_Tidy();
assign(_Right, 0, npos);
}
basic_string()
: _Mybase()
{ // construct empty string
_Tidy();
}
explicit basic_string(const _Alloc& _Al)
: _Mybase(_Al)
{ // construct empty string with allocator
_Tidy();
}
basic_string(const _Myt& _Right, size_type _Roff,
size_type _Count = npos)
: _Mybase(_Right._Alval)
{ // construct from _Right [_Roff, _Roff + _Count)
_Tidy();
assign(_Right, _Roff, _Count);
}
basic_string(const _Myt& _Right, size_type _Roff, size_type _Count,
const _Alloc& _Al)
: _Mybase(_Al)
{ // construct from _Right [_Roff, _Roff + _Count) with allocator
_Tidy();
assign(_Right, _Roff, _Count);
}
basic_string(const _Elem *_Ptr, size_type _Count)
: _Mybase()
{ // construct from [_Ptr, _Ptr + _Count)
_Tidy();
assign(_Ptr, _Count);
}
basic_string(const _Elem *_Ptr, size_type _Count, const _Alloc& _Al)
: _Mybase(_Al)
{ // construct from [_Ptr, _Ptr + _Count) with allocator
_Tidy();
assign(_Ptr, _Count);
}
basic_string(const _Elem *_Ptr)
: _Mybase()
{ // construct from [_Ptr, <null>)
_Tidy();
assign(_Ptr);
}
basic_string(const _Elem *_Ptr, const _Alloc& _Al)
: _Mybase(_Al)
{ // construct from [_Ptr, <null>) with allocator
_Tidy();
assign(_Ptr);
}
basic_string(size_type _Count, _Elem _Ch)
: _Mybase()
{ // construct from _Count * _Ch
_Tidy();
assign(_Count, _Ch);
}
basic_string(size_type _Count, _Elem _Ch, const _Alloc& _Al)
: _Mybase(_Al)
{ // construct from _Count * _Ch with allocator
_Tidy();
assign(_Count, _Ch);
}
template<class _It>
basic_string(_It _First, _It _Last)
: _Mybase()
{ // construct from [_First, _Last)
_Tidy();
_Construct(_First, _Last, _Iter_cat(_First));
}
template<class _It>
basic_string(_It _First, _It _Last, const _Alloc& _Al)
: _Mybase(_Al)
{ // construct from [_First, _Last) with allocator
_Tidy();
_Construct(_First, _Last, _Iter_cat(_First));
}
template<class _It>
void _Construct(_It _Count,
_It _Ch, _Int_iterator_tag)
{ // initialize from _Count * _Ch
assign((size_type)_Count, (_Elem)_Ch);
}
template<class _It>
void _Construct(_It _First,
_It _Last, input_iterator_tag)
{ // initialize from [_First, _Last), input iterators
_TRY_BEGIN
for (; _First != _Last; ++_First)
append((size_type)1, (_Elem)*_First);
_CATCH_ALL
_Tidy(true);
_RERAISE;
_CATCH_END
}
template<class _It>
void _Construct(_It _First,
_It _Last, forward_iterator_tag)
{ // initialize from [_First, _Last), forward iterators
_DEBUG_RANGE(_First, _Last);
size_type _Count = 0;
_Distance(_First, _Last, _Count);
reserve(_Count);
_TRY_BEGIN
for (; _First != _Last; ++_First)
append((size_type)1, (_Elem)*_First);
_CATCH_ALL
_Tidy(true);
_RERAISE;
_CATCH_END
}
basic_string(const_pointer _First, const_pointer _Last)
: _Mybase()
{ // construct from [_First, _Last), const pointers
_DEBUG_RANGE(_First, _Last);
_Tidy();
if (_First != _Last)
assign(&*_First, _Last - _First);
}
basic_string(const_pointer _First, const_pointer _Last,
const _Alloc& _Al)
: _Mybase(_Al)
{ // construct from [_First, _Last), const pointers
_DEBUG_RANGE(_First, _Last);
_Tidy();
if (_First != _Last)
assign(&*_First, _Last - _First);
}
basic_string(const_iterator _First, const_iterator _Last)
: _Mybase()
{ // construct from [_First, _Last), const_iterators
_DEBUG_RANGE(_First, _Last);
_Tidy();
if (_First != _Last)
assign(&*_First, _Last - _First);
}
basic_string(_Myt&& _Right)
: _Mybase(_STD forward<_Alloc>(_Right._Alval))
{ // construct by moving _Right
_Tidy();
assign(_STD forward<_Myt>(_Right));
}
_Myt& operator=(_Myt&& _Right)
{ // assign by moving _Right
return (assign(_STD forward<_Myt>(_Right)));
}
_Myt& assign(_Myt&& _Right)
{ // assign by moving _Right
if (this == &_Right)
;
else if (get_allocator() != _Right.get_allocator()
&& this->_BUF_SIZE <= _Right._Myres)
*this = _Right;
else
{ // not same, clear this and steal from _Right
_Tidy(true);
if (_Right._Myres < this->_BUF_SIZE)
_Traits::move(this->_Bx._Buf, _Right._Bx._Buf,
_Right._Mysize + 1);
else
{ // copy pointer
this->_Bx._Ptr = _Right._Bx._Ptr;
_Right._Bx._Ptr = 0;
}
this->_Mysize = _Right._Mysize;
this->_Myres = _Right._Myres;
_Right._Mysize = 0;
_Right._Myres = 0;
}
return (*this);
}
void swap(_Myt&& _Right)
{ // exchange contents with movable _Right
if (this != &_Right)
{ // swap with emptied container
#if 0 < _ITERATOR_DEBUG_LEVEL
this->_Orphan_all();
this->_Swap_all(_Right);
#endif /* 0 < _ITERATOR_DEBUG_LEVEL */
assign(_STD forward<_Myt>(_Right));
}
}
~basic_string()
{ // destroy the string
_Tidy(true);
}
typedef _Traits traits_type;
typedef _Alloc allocator_type;
_PGLOBAL static const size_type npos; // bad/missing length/position
_Myt& operator=(const _Myt& _Right)
{ // assign _Right
return (assign(_Right));
}
_Myt& operator=(const _Elem *_Ptr)
{ // assign [_Ptr, <null>)
return (assign(_Ptr));
}
_Myt& operator=(_Elem _Ch)
{ // assign 1 * _Ch
return (assign(1, _Ch));
}
_Myt& operator+=(const _Myt& _Right)
{ // append _Right
return (append(_Right));
}
_Myt& operator+=(const _Elem *_Ptr)
{ // append [_Ptr, <null>)
return (append(_Ptr));
}
_Myt& operator+=(_Elem _Ch)
{ // append 1 * _Ch
return (append((size_type)1, _Ch));
}
_Myt& append(const _Myt& _Right)
{ // append _Right
return (append(_Right, 0, npos));
}
_Myt& append(const _Myt& _Right,
size_type _Roff, size_type _Count)
{ // append _Right [_Roff, _Roff + _Count)
if (_Right.size() < _Roff)
_Xran(); // _Roff off end
size_type _Num = _Right.size() - _Roff;
if (_Num < _Count)
_Count = _Num; // trim _Count to size
if (npos - this->_Mysize <= _Count)
_Xlen(); // result too long
if (0 < _Count && _Grow(_Num = this->_Mysize + _Count))
{ // make room and append new stuff
_Traits::copy(_Myptr() + this->_Mysize,
_Right._Myptr() + _Roff, _Count);
_Eos(_Num);
}
return (*this);
}
_Myt& append(const _Elem *_Ptr, size_type _Count)
{ // append [_Ptr, _Ptr + _Count)
#if _ITERATOR_DEBUG_LEVEL == 2
if (_Count != 0)
_DEBUG_POINTER(_Ptr);
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
if (_Inside(_Ptr))
return (append(*this, _Ptr - _Myptr(), _Count)); // substring
if (npos - this->_Mysize <= _Count)
_Xlen(); // result too long
size_type _Num;
if (0 < _Count && _Grow(_Num = this->_Mysize + _Count))
{ // make room and append new stuff
_Traits::copy(_Myptr() + this->_Mysize, _Ptr, _Count);
_Eos(_Num);
}
return (*this);
}
_Myt& append(const _Elem *_Ptr)
{ // append [_Ptr, <null>)
_DEBUG_POINTER(_Ptr);
return (append(_Ptr, _Traits::length(_Ptr)));
}
_Myt& append(size_type _Count, _Elem _Ch)
{ // append _Count * _Ch
if (npos - this->_Mysize <= _Count)
_Xlen(); // result too long
size_type _Num;
if (0 < _Count && _Grow(_Num = this->_Mysize + _Count))
{ // make room and append new stuff using assign
_Chassign(this->_Mysize, _Count, _Ch);
_Eos(_Num);
}
return (*this);
}
template<class _It>
_Myt& append(_It _First, _It _Last)
{ // append [_First, _Last)
return (_Append(_First, _Last, _Iter_cat(_First)));
}
template<class _It>
_Myt& _Append(_It _Count, _It _Ch, _Int_iterator_tag)
{ // append _Count * _Ch
return (append((size_type)_Count, (_Elem)_Ch));
}
template<class _It>
_Myt& _Append(_It _First, _It _Last, input_iterator_tag)
{ // append [_First, _Last), input iterators
return (replace(end(), end(), _First, _Last));
}
_Myt& append(const_pointer _First, const_pointer _Last)
{ // append [_First, _Last), const pointers
return (replace(end(), end(), _First, _Last));
}
_Myt& append(const_iterator _First, const_iterator _Last)
{ // append [_First, _Last), const_iterators
return (replace(end(), end(), _First, _Last));
}
_Myt& assign(const _Myt& _Right)
{ // assign _Right
return (assign(_Right, 0, npos));
}
_Myt& assign(const _Myt& _Right,
size_type _Roff, size_type _Count)
{ // assign _Right [_Roff, _Roff + _Count)
if (_Right.size() < _Roff)
_Xran(); // _Roff off end
size_type _Num = _Right.size() - _Roff;
if (_Count < _Num)
_Num = _Count; // trim _Num to size
if (this == &_Right)
erase((size_type)(_Roff + _Num)), erase(0, _Roff); // substring
else if (_Grow(_Num))
{ // make room and assign new stuff
_Traits::copy(_Myptr(), _Right._Myptr() + _Roff, _Num);
_Eos(_Num);
}
return (*this);
}
_Myt& assign(const _Elem *_Ptr, size_type _Count)
{ // assign [_Ptr, _Ptr + _Count)
#if _ITERATOR_DEBUG_LEVEL == 2
if (_Count != 0)
_DEBUG_POINTER(_Ptr);
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
if (_Inside(_Ptr))
return (assign(*this, _Ptr - _Myptr(), _Count)); // substring
if (_Grow(_Count))
{ // make room and assign new stuff
_Traits::copy(_Myptr(), _Ptr, _Count);
_Eos(_Count);
}
return (*this);
}
_Myt& assign(const _Elem *_Ptr)
{ // assign [_Ptr, <null>)
_DEBUG_POINTER(_Ptr);
return (assign(_Ptr, _Traits::length(_Ptr)));
}
_Myt& assign(size_type _Count, _Elem _Ch)
{ // assign _Count * _Ch
if (_Count == npos)
_Xlen(); // result too long
if (_Grow(_Count))
{ // make room and assign new stuff
_Chassign(0, _Count, _Ch);
_Eos(_Count);
}
return (*this);
}
template<class _It>
_Myt& assign(_It _First, _It _Last)
{ // assign [First, _Last)
return (_Assign(_First, _Last, _Iter_cat(_First)));
}
template<class _It>
_Myt& _Assign(_It _Count, _It _Ch, _Int_iterator_tag)
{ // assign _Count * _Ch
return (assign((size_type)_Count, (_Elem)_Ch));
}
template<class _It>
_Myt& _Assign(_It _First, _It _Last, input_iterator_tag)
{ // assign [First, _Last), input iterators
return (replace(begin(), end(), _First, _Last));
}
_Myt& assign(const_pointer _First, const_pointer _Last)
{ // assign [First, _Last), const pointers
return (replace(begin(), end(), _First, _Last));
}
_Myt& assign(const_iterator _First, const_iterator _Last)
{ // assign [First, _Last), const_iterators
return (replace(begin(), end(), _First, _Last));
}
_Myt& insert(size_type _Off, const _Myt& _Right)
{ // insert _Right at _Off
return (insert(_Off, _Right, 0, npos));
}
_Myt& insert(size_type _Off,
const _Myt& _Right, size_type _Roff, size_type _Count)
{ // insert _Right [_Roff, _Roff + _Count) at _Off
if (this->_Mysize < _Off || _Right.size() < _Roff)
_Xran(); // _Off or _Roff off end
size_type _Num = _Right.size() - _Roff;
if (_Num < _Count)
_Count = _Num; // trim _Count to size
if (npos - this->_Mysize <= _Count)
_Xlen(); // result too long
if (0 < _Count && _Grow(_Num = this->_Mysize + _Count))
{ // make room and insert new stuff
_Traits::move(_Myptr() + _Off + _Count,
_Myptr() + _Off, this->_Mysize - _Off); // empty out hole
if (this == &_Right)
_Traits::move(_Myptr() + _Off,
_Myptr() + (_Off < _Roff ? _Roff + _Count : _Roff),
_Count); // substring
else
_Traits::copy(_Myptr() + _Off,
_Right._Myptr() + _Roff, _Count); // fill hole
_Eos(_Num);
}
return (*this);
}
_Myt& insert(size_type _Off,
const _Elem *_Ptr, size_type _Count)
{ // insert [_Ptr, _Ptr + _Count) at _Off
#if _ITERATOR_DEBUG_LEVEL == 2
if (_Count != 0)
_DEBUG_POINTER(_Ptr);
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
if (_Inside(_Ptr))
return (insert(_Off, *this,
_Ptr - _Myptr(), _Count)); // substring
if (this->_Mysize < _Off)
_Xran(); // _Off off end
if (npos - this->_Mysize <= _Count)
_Xlen(); // result too long
size_type _Num;
if (0 < _Count && _Grow(_Num = this->_Mysize + _Count))
{ // make room and insert new stuff
_Traits::move(_Myptr() + _Off + _Count,
_Myptr() + _Off, this->_Mysize - _Off); // empty out hole
_Traits::copy(_Myptr() + _Off, _Ptr, _Count); // fill hole
_Eos(_Num);
}
return (*this);
}
_Myt& insert(size_type _Off, const _Elem *_Ptr)
{ // insert [_Ptr, <null>) at _Off
_DEBUG_POINTER(_Ptr);
return (insert(_Off, _Ptr, _Traits::length(_Ptr)));
}
_Myt& insert(size_type _Off,
size_type _Count, _Elem _Ch)
{ // insert _Count * _Ch at _Off
if (this->_Mysize < _Off)
_Xran(); // _Off off end
if (npos - this->_Mysize <= _Count)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -