?? xstring
字號:
// xstring internal header (from <string>)
#ifndef _XSTRING_
#define _XSTRING_
/* This file is for use only in conjunction with a valid license for
Microsoft Visual C++ V5.0. Microsoft Corporation is in no way involved
with the production or release of this file. The file is offered on an
``as is'' basis.
DINKUMWARE, LTD. AND P.J. PLAUGER MAKE NO REPRESENTATIONS OR WARRANTIES
ABOUT THE SUITABILITY OF THIS FILE, EITHER EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. DINKUMWARE, LTD.
AND P.J. PLAUGER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
LICENSEE AS A RESULT OF USING THIS FILE.
For additional information, contact Dinkumware, Ltd. (+1-888-4DINKUM or
support@dinkumware.com).
Version date: 25 May 1998
*/
#include <xmemory>
#ifdef _MSC_VER
#pragma pack(push,8)
#endif /* _MSC_VER */
#include <xutility>
_STD_BEGIN
_CRTIMP void __cdecl _Xlen();
_CRTIMP void __cdecl _Xran();
// TEMPLATE CLASS basic_string
template<class _E,
class _Tr = char_traits<_E>,
class _A = allocator<_E> >
class basic_string {
public:
typedef basic_string<_E, _Tr, _A> _Myt;
typedef _A::size_type size_type;
typedef _A::difference_type difference_type;
typedef _A::pointer pointer;
typedef _A::const_pointer const_pointer;
typedef _A::reference reference;
typedef _A::const_reference const_reference;
typedef _A::value_type value_type;
typedef _A::pointer iterator;
typedef _A::const_pointer const_iterator;
typedef reverse_iterator<const_iterator, value_type,
const_reference, const_pointer, difference_type>
const_reverse_iterator;
typedef reverse_iterator<iterator, value_type,
reference, pointer, difference_type>
reverse_iterator;
explicit basic_string(const _A& _Al = _A())
: allocator(_Al) {_Tidy(); }
basic_string(const _Myt& _X)
: allocator(_X.allocator)
{_Tidy(), assign(_X, 0, npos); }
basic_string(const _Myt& _X, size_type _P, size_type _M,
const _A& _Al = _A())
: allocator(_Al) {_Tidy(), assign(_X, _P, _M); }
basic_string(const _E *_S, size_type _N,
const _A& _Al = _A())
: allocator(_Al) {_Tidy(), assign(_S, _N); }
basic_string(const _E *_S, const _A& _Al = _A())
: allocator(_Al) {_Tidy(), assign(_S); }
basic_string(size_type _N, _E _C, const _A& _Al = _A())
: allocator(_Al) {_Tidy(), assign(_N, _C); }
typedef const_iterator _It;
basic_string(_It _F, _It _L, const _A& _Al = _A())
: allocator(_Al) {_Tidy(); assign(_F, _L); }
~basic_string()
{_Tidy(true); }
typedef _Tr traits_type;
typedef _A allocator_type;
enum _Mref {_FROZEN = 255};
static const size_type npos;
_Myt& operator=(const _Myt& _X)
{return (assign(_X)); }
_Myt& operator=(const _E *_S)
{return (assign(_S)); }
_Myt& operator=(_E _C)
{return (assign(1, _C)); }
_Myt& operator+=(const _Myt& _X)
{return (append(_X)); }
_Myt& operator+=(const _E *_S)
{return (append(_S)); }
_Myt& operator+=(_E _C)
{return (append(1, _C)); }
_Myt& append(const _Myt& _X)
{return (append(_X, 0, npos)); }
_Myt& append(const _Myt& _X, size_type _P, size_type _M)
{if (_X.size() < _P)
_Xran();
size_type _N = _X.size() - _P;
if (_N < _M)
_M = _N;
if (npos - _Len <= _M)
_Xlen();
if (0 < _M && _Grow(_N = _Len + _M))
{_Tr::copy(_Ptr + _Len, &_X.c_str()[_P], _M);
_Eos(_N); }
return (*this); }
_Myt& append(const _E *_S, size_type _M)
{if (npos - _Len <= _M)
_Xlen();
size_type _N;
if (0 < _M && _Grow(_N = _Len + _M))
{_Tr::copy(_Ptr + _Len, _S, _M);
_Eos(_N); }
return (*this); }
_Myt& append(const _E *_S)
{return (append(_S, _Tr::length(_S))); }
_Myt& append(size_type _M, _E _C)
{if (npos - _Len <= _M)
_Xlen();
size_type _N;
if (0 < _M && _Grow(_N = _Len + _M))
{_Tr::assign(_Ptr + _Len, _M, _C);
_Eos(_N); }
return (*this); }
_Myt& append(_It _F, _It _L)
{return (replace(end(), end(), _F, _L)); }
_Myt& assign(const _Myt& _X)
{return (assign(_X, 0, npos)); }
_Myt& assign(const _Myt& _X, size_type _P, size_type _M)
{if (_X.size() < _P)
_Xran();
size_type _N = _X.size() - _P;
if (_M < _N)
_N = _M;
if (this == &_X)
erase((size_type)(_P + _N)), erase(0, _P);
else if (0 < _N && _N == _X.size()
&& _Refcnt(_X.c_str()) < _FROZEN - 1
&& allocator == _X.allocator)
{_Tidy(true);
_Ptr = (_E *)_X.c_str();
_Len = _X.size();
_Res = _X.capacity();
++_Refcnt(_Ptr); }
else if (_Grow(_N, true))
{_Tr::copy(_Ptr, &_X.c_str()[_P], _N);
_Eos(_N); }
return (*this); }
_Myt& assign(const _E *_S, size_type _N)
{if (_Grow(_N, true))
{_Tr::copy(_Ptr, _S, _N);
_Eos(_N); }
return (*this); }
_Myt& assign(const _E *_S)
{return (assign(_S, _Tr::length(_S))); }
_Myt& assign(size_type _N, _E _C)
{if (_N == npos)
_Xlen();
if (_Grow(_N, true))
{_Tr::assign(_Ptr, _N, _C);
_Eos(_N); }
return (*this); }
_Myt& assign(_It _F, _It _L)
{return (replace(begin(), end(), _F, _L)); }
_Myt& insert(size_type _P0, const _Myt& _X)
{return (insert(_P0, _X, 0, npos)); }
_Myt& insert(size_type _P0, const _Myt& _X, size_type _P,
size_type _M)
{if (_Len < _P0 || _X.size() < _P)
_Xran();
size_type _N = _X.size() - _P;
if (_N < _M)
_M = _N;
if (npos - _Len <= _M)
_Xlen();
if (0 < _M && _Grow(_N = _Len + _M))
{_Tr::move(_Ptr + _P0 + _M, _Ptr + _P0, _Len - _P0);
_Tr::copy(_Ptr + _P0, &_X.c_str()[_P], _M);
_Eos(_N); }
return (*this); }
_Myt& insert(size_type _P0, const _E *_S, size_type _M)
{if (_Len < _P0)
_Xran();
if (npos - _Len <= _M)
_Xlen();
size_type _N;
if (0 < _M && _Grow(_N = _Len + _M))
{_Tr::move(_Ptr + _P0 + _M, _Ptr + _P0, _Len - _P0);
_Tr::copy(_Ptr + _P0, _S, _M);
_Eos(_N); }
return (*this); }
_Myt& insert(size_type _P0, const _E *_S)
{return (insert(_P0, _S, _Tr::length(_S))); }
_Myt& insert(size_type _P0, size_type _M, _E _C)
{if (_Len < _P0)
_Xran();
if (npos - _Len <= _M)
_Xlen();
size_type _N;
if (0 < _M && _Grow(_N = _Len + _M))
{_Tr::move(_Ptr + _P0 + _M, _Ptr + _P0, _Len - _P0);
_Tr::assign(_Ptr + _P0, _M, _C);
_Eos(_N); }
return (*this); }
iterator insert(iterator _P, _E _C)
{size_type _P0 = _Pdif(_P, begin());
insert(_P0, 1, _C);
return (begin() + _P0); }
void insert(iterator _P, size_type _M, _E _C)
{size_type _P0 = _Pdif(_P, begin());
insert(_P0, _M, _C); }
void insert(iterator _P, _It _F, _It _L)
{replace(_P, _P, _F, _L); }
_Myt& erase(size_type _P0 = 0, size_type _M = npos)
{if (_Len < _P0)
_Xran();
if (_Len - _P0 < _M)
_M = _Len - _P0;
if (0 < _M)
{_Freeze();
_Tr::move(_Ptr + _P0, _Ptr + _P0 + _M,
_Len - _P0 - _M);
size_type _N = _Len - _M;
if (_Grow(_N))
_Eos(_N); }
return (*this); }
iterator erase(iterator _P)
{size_t _M = _Pdif(_P, begin());
erase(_M, 1);
return (_Psum(_Ptr, _M)); }
iterator erase(iterator _F, iterator _L)
{size_t _M = _Pdif(_F, begin());
erase(_M, _Pdif(_L, _F));
return (_Psum(_Ptr, _M)); }
_Myt& replace(size_type _P0, size_type _N0, const _Myt& _X)
{return (replace(_P0, _N0, _X, 0, npos)); }
_Myt& replace(size_type _P0, size_type _N0, const _Myt& _X,
size_type _P, size_type _M)
{if (_Len < _P0 || _X.size() < _P)
_Xran();
if (_Len - _P0 < _N0)
_N0 = _Len - _P0;
size_type _N = _X.size() - _P;
if (_N < _M)
_M = _N;
if (npos - _M <= _Len - _N0)
_Xlen();
size_type _Nm = _Len - _N0 - _P0;
if (_M < _N0)
{_Freeze();
_Tr::move(_Ptr + _P0 + _M, _Ptr + _P0 + _N0, _Nm); }
if ((0 < _M || 0 < _N0) && _Grow(_N = _Len + _M - _N0))
{if (_N0 < _M)
_Tr::move(_Ptr + _P0 + _M, _Ptr + _P0 + _N0, _Nm);
_Tr::copy(_Ptr + _P0, &_X.c_str()[_P], _M);
_Eos(_N); }
return (*this); }
_Myt& replace(size_type _P0, size_type _N0, const _E *_S,
size_type _M)
{if (_Len < _P0)
_Xran();
if (_Len - _P0 < _N0)
_N0 = _Len - _P0;
if (npos - _M <= _Len - _N0)
_Xlen();
size_type _Nm = _Len - _N0 - _P0;
if (_M < _N0)
{_Freeze();
_Tr::move(_Ptr + _P0 + _M, _Ptr + _P0 + _N0, _Nm); }
size_type _N;
if ((0 < _M || 0 < _N0) && _Grow(_N = _Len + _M - _N0))
{if (_N0 < _M)
_Tr::move(_Ptr + _P0 + _M, _Ptr + _P0 + _N0, _Nm);
_Tr::copy(_Ptr + _P0, _S, _M);
_Eos(_N); }
return (*this); }
_Myt& replace(size_type _P0, size_type _N0, const _E *_S)
{return (replace(_P0, _N0, _S, _Tr::length(_S))); }
_Myt& replace(size_type _P0, size_type _N0,
size_type _M, _E _C)
{if (_Len < _P0)
_Xran();
if (_Len - _P0 < _N0)
_N0 = _Len - _P0;
if (npos - _M <= _Len - _N0)
_Xlen();
size_type _Nm = _Len - _N0 - _P0;
if (_M < _N0)
{_Freeze();
_Tr::move(_Ptr + _P0 + _M, _Ptr + _P0 + _N0, _Nm); }
size_type _N;
if ((0 < _M || 0 < _N0) && _Grow(_N = _Len + _M - _N0))
{if (_N0 < _M)
_Tr::move(_Ptr + _P0 + _M, _Ptr + _P0 + _N0,
_Nm);
_Tr::assign(_Ptr + _P0, _M, _C);
_Eos(_N); }
return (*this); }
_Myt& replace(iterator _F, iterator _L, const _Myt& _X)
{return (replace(
_Pdif(_F, begin()), _Pdif(_L, _F), _X)); }
_Myt& replace(iterator _F, iterator _L, const _E *_S,
size_type _M)
{return (replace(
_Pdif(_F, begin()), _Pdif(_L, _F), _S, _M)); }
_Myt& replace(iterator _F, iterator _L, const _E *_S)
{return (replace(
_Pdif(_F, begin()), _Pdif(_L, _F), _S)); }
_Myt& replace(iterator _F, iterator _L, size_type _M, _E _C)
{return (replace(
_Pdif(_F, begin()), _Pdif(_L, _F), _M, _C)); }
_Myt& replace(iterator _F1, iterator _L1,
_It _F2, _It _L2)
{size_type _P0 = _Pdif(_F1, begin());
size_type _M = 0;
_Distance(_F2, _L2, _M);
replace(_P0, _Pdif(_L1, _F1), _M, _E(0));
for (_F1 = begin() + _P0; 0 < _M; ++_F1, ++_F2, --_M)
*_F1 = *_F2;
return (*this); }
iterator begin()
{_Freeze();
return (_Ptr); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -