📄 string
字号:
// 21.3.6.5, p4
size_type find_first_not_of (const_pointer, size_type,
size_type) const;
// 21.3.6.5, p5
size_type find_first_not_of (const_pointer, size_type = 0) const;
// 21.3.6.5, p7
size_type find_first_not_of (value_type, size_type = 0) const;
// 21.3.6.6, p1
size_type find_last_not_of (const basic_string &__str,
size_type __pos = npos) const {
return find_last_not_of (__str.c_str (), __pos, __str.size ());
}
// 21.3.6.6, p4
size_type find_last_not_of (const_pointer, size_type, size_type) const;
// 21.3.6.6, p6
size_type find_last_not_of (const_pointer __s,
size_type __pos = npos) const {
return find_last_not_of (__s, __pos, traits_type::length (__s));
}
// 21.3.6.6, p7
size_type find_last_not_of (value_type, size_type = npos) const;
// 21.3.6.7
basic_string substr (size_type = 0, size_type = npos) const;
int compare (const basic_string &__str) const;
int compare (size_type __pos, size_type __n, const basic_string &__str) const {
return compare (__pos, __n, __str.c_str(), __str.size());
}
int compare (size_type, size_type, const basic_string&,
size_type, size_type) const;
int compare (const_pointer __s) const {
return compare (0, size (), __s, traits_type::length(__s));
}
// LWG Issue #5.
int compare (size_type __pos, size_type __n, const_pointer __s) const {
return compare(__pos, __n, __s, traits_type::length (__s));
}
int compare (size_type, size_type, const_pointer, size_type) const;
protected:
void _C_cow () { // Do copy on write as necessary
if (_C_pref ()->_C_ref_count() > 1)
_C_clone ();
}
void _C_cow (size_type __nc) { // Do copy on write w/ new capacity
if (_C_pref ()->_C_ref_count () > 1 || capacity () < __nc)
_C_clone (__nc);
}
private:
void _C_initn (size_type, value_type);
void _C_clone (size_type __nc = npos);
_C_string_ref_type* _C_pref () const {
return _RWSTD_REINTERPRET_CAST (_C_string_ref_type*, _C_data) - 1;
}
void _C_unlink ();
friend struct _RW::__string_ref<value_type, traits_type, allocator_type>;
#ifndef _RWSTD_NO_COLLAPSE_TEMPLATE_STATICS
static _RW::__null_ref<_CharT, _Traits, _Allocator> __nullref;
static pointer _C_null () {
return __nullref.data ();
}
#else // if defined (_RWSTD_NO_COLLAPSE_TEMPLATE_STATICS)
static pointer _C_null () {
typedef _RW::__null_ref<_CharT, _Traits, _Allocator> _NullRef;
return _RWSTD_REINTERPRET_CAST (_NullRef*, &_RW::__nullref)->data ();
}
#endif // _RWSTD_NO_COLLAPSE_TEMPLATE_STATICS
_C_string_ref_type * _C_getRep (size_type, size_type);
// for convenience
pointer _C_allocate (size_type __cur, size_type __cap, size_type __size) {
return _C_getRep (max (size_type (_RW::__rw_new_capacity (__cur, this)),
__cap), __size)->data ();
}
pointer _C_data;
};
typedef basic_string<char, char_traits<char>, allocator<char> > string;
#ifndef _RWSTD_NO_WCHAR_T
typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >
wstring;
#endif // _RWSTD_NO_WCHAR_T
template <class _CharT, class _Traits , class _Allocator>
inline void basic_string<_CharT, _Traits, _Allocator>::_C_unlink()
{
_RWSTD_ASSERT (0 != _C_data);
if (data () == _C_null ())
return;
if (_C_pref ()->_C_ref_count () == 0 || _C_pref ()->_C_dec_ref () == 0) {
// Required to pass same size to deallocate as allocate (see string.cc).
// Also note that we cannot call capacity() after the destroy() call.
size_type __size =
capacity () + sizeof (_C_string_ref_type) / sizeof (value_type) + 2;
// explicitly destroy POD
_C_pref ()->_C_destroy ();
_C_ref_alloc_type (*this).destroy (_C_pref ());
_RWSTD_VALUE_ALLOC (_C_value_alloc_type,
deallocate (_RWSTD_REINTERPRET_CAST (pointer,
_C_pref()),
__size));
}
}
template <class _CharT, class _Traits , class _Allocator>
inline basic_string<_CharT, _Traits, _Allocator>::
basic_string (const basic_string<_CharT, _Traits, _Allocator> &__s)
: allocator_type (__s.get_allocator ())
{
if (__s._C_pref()->_C_ref_count () > 0) {
_C_data = __s._C_data;
_C_pref()->_C_inc_ref ();
}
else {
size_type __n = __s.size();
_C_data = _C_getRep (__n, __n)->data ();
traits_type::copy (_C_data, __s.c_str (), __n);
}
}
template <class _CharT, class _Traits , class _Allocator>
inline basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::erase (size_type __pos,
size_type __n)
{
_RWSTD_REQUIRES (__pos <= size (),
(_RWSTD_ERROR_OUT_OF_RANGE,
_RWSTD_FUNC ("basic_string::erase(size_type, size_type)"),
__pos, size ()));
const value_type __tmp = value_type () ;
size_type __len = size () - __pos;
return replace (__pos, __n < __len ? __n : __len, &__tmp, 0);
}
template <class _CharT, class _Traits , class _Allocator>
inline _TYPENAME basic_string<_CharT, _Traits, _Allocator>::const_reference
basic_string<_CharT, _Traits, _Allocator>::operator[] (size_type __pos) const
{
#ifdef _RWSTD_BOUNDS_CHECKING
_RWSTD_REQUIRES (__pos <= size (),
(_RWSTD_ERROR_OUT_OF_RANGE,
_RWSTD_FUNC ("basic_string::operator[](size_type) const"),
__pos, size ()));
#endif // _RWSTD_BOUNDS_CHECKING
// reference counting still enabled
return _C_data [__pos];
}
template <class _CharT, class _Traits , class _Allocator>
inline _TYPENAME basic_string<_CharT, _Traits, _Allocator>::reference
basic_string<_CharT, _Traits, _Allocator>::operator[] (size_type __pos)
{
#ifdef _RWSTD_BOUNDS_CHECKING
// 21.3.4, p1 - behavior is undefined if __pos == size ()
_RWSTD_REQUIRES (__pos < size (),
(_RWSTD_ERROR_OUT_OF_RANGE,
_RWSTD_FUNC ("basic_string::operator[](size_type)"),
__pos, size ()));
#endif // _RWSTD_BOUNDS_CHECKING
// prevent reference counting
return begin ()[__pos];
}
template <class _CharT, class _Traits , class _Allocator>
inline _TYPENAME basic_string<_CharT, _Traits, _Allocator>::const_reference
basic_string<_CharT, _Traits, _Allocator>::at (size_type __pos) const
{
_RWSTD_REQUIRES (__pos < size (),
(_RWSTD_ERROR_OUT_OF_RANGE,
_RWSTD_FUNC ("basic_string::at (size_type) const"),
__pos, size ()));
// reference counting still enabled
return _C_data [__pos];
}
template <class _CharT, class _Traits , class _Allocator>
inline _TYPENAME basic_string<_CharT, _Traits, _Allocator>::reference
basic_string<_CharT, _Traits, _Allocator>::at (size_type __pos)
{
_RWSTD_REQUIRES (__pos < size (),
(_RWSTD_ERROR_OUT_OF_RANGE,
_RWSTD_FUNC ("basic_string::at (size_type)"),
__pos, size ()));
// prevent reference counting
return begin ()[__pos];
}
template <class _CharT, class _Traits , class _Allocator>
inline void
basic_string<_CharT, _Traits, _Allocator>::
resize (size_type __n, value_type __c)
{
_RWSTD_REQUIRES (__n <= max_size (),
(_RWSTD_ERROR_LENGTH_ERROR,
_RWSTD_FUNC ("basic_string::resize(size_type, "
"value_type)"), __n, max_size ()));
if (__n < size())
erase (__n, size () - __n);
else
replace (size (), 0, __n - size (), __c);
}
template <class _CharT, class _Traits , class _Allocator>
inline void basic_string<_CharT, _Traits, _Allocator>::
reserve (size_type __n)
{
_RWSTD_REQUIRES (__n <= max_size (),
(_RWSTD_ERROR_LENGTH_ERROR,
_RWSTD_FUNC ("basic_string::reserve(size_type)"),
__n, max_size ()));
if (__n > capacity ())
_C_clone (__n);
}
template <class _CharT, class _Traits , class _Allocator>
inline _TYPENAME basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::
find (const_pointer __s, size_type __pos) const
{
_RWSTD_ASSERT (__s != 0);
// 21.3.6.1, p1, bullet 1
if (__pos > size ())
return npos;
const_pointer __where =
_RW::rw_traits<value_type, traits_type>::find (_C_data + __pos, __s);
return __where ? __where - _C_data : npos;
}
template <class _CharT, class _Traits , class _Allocator>
inline _TYPENAME basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::
find (value_type __c, size_type __pos) const
{
if (__pos > size())
return npos;
const_pointer __where = traits_type::find (_C_data + __pos,
size() - __pos, __c);
return __where ? __where - _C_data : npos;
}
template <class _CharT, class _Traits , class _Allocator>
inline _TYPENAME basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::
rfind (value_type __c, size_type __pos) const
{
if (!size ())
return npos;
if (__pos >= size ())
__pos = size () - 1; // start at the last valid position
const_pointer __where =
_RW::rw_traits<value_type, traits_type>::rfind (_C_data,
__c, __pos);
return __where ? __where - _C_data : npos;
}
template <class _CharT, class _Traits , class _Allocator>
inline _TYPENAME basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::
find_first_of (const_pointer __s, size_type __pos) const
{
_RWSTD_ASSERT (__s != 0);
if (__pos > size())
return npos;
typedef _RW::rw_traits<_CharT, _Traits> __rw_traits;
size_type __i = __rw_traits::find_first_of (_C_data + __pos, __s) + __pos;
return __i >= size () ? npos : __i;
}
template <class _CharT, class _Traits , class _Allocator>
inline _TYPENAME basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::
find_first_not_of (const_pointer __s, size_type __pos) const
{
_RWSTD_ASSERT (__s != 0);
if (__pos > size())
return npos;
typedef _RW::rw_traits<_CharT, _Traits> __rw_traits;
size_type __i = __rw_traits::find_first_not_of(_C_data + __pos, __s)+ __pos;
return __i >= size () ? npos : __i;
}
template <class _CharT, class _Traits , class _Allocator>
inline _TYPENAME basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::
find_first_not_of (value_type __c, size_type __pos) const
{
return find_first_not_of (&__c, __pos, 1);
}
template <class _CharT, class _Traits , class _Allocator>
inline _TYPENAME basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::
find_last_not_of (value_type __c, size_type __pos) const
{
#if 0
// disabled to work around a bug in several compilers
const value_type __tmp [] = { __c, value_type () };
#else
value_type __tmp [2];
traits_type::assign (__tmp [0], __c);
traits_type::assign (__tmp [1], value_type ());
#endif // 0/1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -