📄 string
字号:
// -*- C++ -*-
/***************************************************************************
*
* <string> - definition of the C++ Standard Library basic_string template
*
* $Id: string,v 1.2 2003/03/31 08:44:28 wmunns Exp $
*
***************************************************************************
*
* Copyright (c) 1994-2001 Rogue Wave Software, Inc. All Rights Reserved.
*
* This computer software is owned by Rogue Wave Software, Inc. and is
* protected by U.S. copyright laws and other laws and by international
* treaties. This computer software is furnished by Rogue Wave Software,
* Inc. pursuant to a written license agreement and may be used, copied,
* transmitted, and stored only in accordance with the terms of such
* license and with the inclusion of the above copyright notice. This
* computer software or any other copies thereof may not be provided or
* otherwise made available to any other person.
*
* U.S. Government Restricted Rights. This computer software is provided
* with Restricted Rights. Use, duplication, or disclosure by the
* Government is subject to restrictions as set forth in subparagraph (c)
* (1) (ii) of The Rights in Technical Data and Computer Software clause
* at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
* Commercial Computer Software--Restricted Rights at 48 CFR 52.227-19,
* as applicable. Manufacturer is Rogue Wave Software, Inc., 5500
* Flatiron Parkway, Boulder, Colorado 80301 USA.
*
**************************************************************************/
#ifndef _RWSTD_STRING_INCLUDED
#define _RWSTD_STRING_INCLUDED
#include <iosfwd>
#include <limits>
#include <rw/_algobase.h>
#include <rw/_iterator.h>
#include <rw/_strref.h>
#include <rw/_defs.h>
#include <rw/_error.h>
_RWSTD_NAMESPACE_BEGIN (std)
template <class _CharT, class _Traits, class _Allocator>
class basic_string: private _Allocator
{
public:
typedef _Traits traits_type;
typedef _TYPENAME traits_type::char_type value_type;
typedef _Allocator allocator_type;
private:
typedef _RW::__string_ref<value_type, traits_type, allocator_type>
_C_string_ref_type;
typedef _RWSTD_ALLOC_TYPE(allocator_type, value_type)
_C_value_alloc_type;
typedef _RWSTD_REBIND(allocator_type, _C_string_ref_type)
_C_ref_alloc_type;
public:
typedef _TYPENAME allocator_type::size_type size_type;
typedef _TYPENAME allocator_type::difference_type difference_type;
typedef _TYPENAME allocator_type::reference reference;
typedef _TYPENAME allocator_type::const_reference const_reference;
typedef _TYPENAME allocator_type::pointer pointer;
typedef _TYPENAME allocator_type::const_pointer const_pointer;
#ifndef _RWSTD_NO_DEBUG_ITER
typedef _RW::__rw_debug_iter <basic_string, pointer, pointer>
iterator;
typedef _RW::__rw_debug_iter <basic_string, const_pointer, pointer>
const_iterator;
iterator _C_make_iter (const pointer& __ptr) {
return iterator (*this, __ptr);
}
const_iterator _C_make_iter (const const_pointer& __ptr) const {
return const_iterator (*this, __ptr);
}
#else // if defined (_RWSTD_NO_DEBUG_ITER)
typedef pointer iterator;
typedef const_pointer const_iterator;
iterator _C_make_iter (pointer __ptr) {
return __ptr;
}
const_iterator _C_make_iter (const_pointer __ptr) const {
return __ptr;
}
#endif // _RWSTD_NO_DEBUG_ITER
#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator;
typedef _STD::reverse_iterator<iterator> reverse_iterator;
#else
typedef _STD::reverse_iterator<const_iterator,
random_access_iterator_tag, value_type,
const_reference, const_pointer, difference_type>
const_reverse_iterator;
typedef _STD::reverse_iterator<iterator,
random_access_iterator_tag, value_type,
reference, pointer, difference_type>
reverse_iterator;
#endif
#if defined(_RWSTD_LLP64_ARCHITECTURE) && defined(_RWSTD_NO_STATIC_CONST_MEMBER_INIT)
static const size_type npos;
#else
_RWSTD_STATIC_CONST (size_type, npos = size_type(-1));
#endif
_EXPLICIT
basic_string (const allocator_type &__alloc = allocator_type ())
: allocator_type (__alloc), _C_data (_C_null ()) { }
// LWG Issue #42.
basic_string (const basic_string&);
basic_string (const basic_string&, size_type, size_type = npos,
const allocator_type& = allocator_type ());
basic_string (const_pointer, size_type,
const allocator_type& = allocator_type ());
basic_string (const_pointer, const allocator_type& = allocator_type ());
#ifndef _RWSTD_NO_MEMBER_TEMPLATES
// pointers to the incomplete types declared below are used
// to disambiguate calls to template member functions
// requires: member function and class templates
// and partial specialization
template <class _InputIterator>
basic_string (_InputIterator, _InputIterator,
const allocator_type& = allocator_type ());
basic_string (int __n, value_type __c,
const allocator_type& __alloc = allocator_type ())
: allocator_type (__alloc) {
_C_initn (_RWSTD_STATIC_CAST (size_type, __n), __c);
}
basic_string (unsigned int __n, value_type __c,
const allocator_type& __alloc = allocator_type ())
: allocator_type (__alloc) {
_C_initn (_RWSTD_STATIC_CAST (size_type, __n), __c);
}
basic_string (long __n, value_type __c,
const allocator_type& __alloc = allocator_type ())
: allocator_type (__alloc) {
_C_initn (_RWSTD_STATIC_CAST (size_type, __n), __c);
}
basic_string (unsigned long __n, value_type __c,
const allocator_type& __alloc = allocator_type ())
: allocator_type (__alloc) {
_C_initn (_RWSTD_STATIC_CAST (size_type, __n), __c);
}
basic_string (short __n, value_type __c,
const allocator_type& __alloc = allocator_type ())
: allocator_type (__alloc) {
_C_initn (_RWSTD_STATIC_CAST (size_type, __n), __c);
}
basic_string (unsigned short __n, value_type __c,
const allocator_type& __alloc = allocator_type ())
: allocator_type (__alloc) {
_C_initn (_RWSTD_STATIC_CAST (size_type, __n), __c);
}
basic_string (char __n, value_type __c,
const allocator_type& __alloc = allocator_type ())
: allocator_type (__alloc) {
_C_initn (_RWSTD_STATIC_CAST (size_type, __n), __c);
}
basic_string (unsigned char __n, value_type __c,
const allocator_type& __alloc = allocator_type ())
: allocator_type (__alloc) {
_C_initn (_RWSTD_STATIC_CAST (size_type, __n), __c);
}
#ifndef _RWSTD_NO_NATIVE_WCHAR_T
basic_string (wchar_t __n, value_type __c,
const allocator_type& __alloc = allocator_type ())
: allocator_type (__alloc) {
_C_initn (_RWSTD_STATIC_CAST (size_type, __n), __c);
}
#endif // _RWSTD_NO_NATIVE_WCHAR_T
#ifndef _RWSTD_NO_BOOL
basic_string (bool __n, value_type __c,
const allocator_type& __alloc = allocator_type ())
: allocator_type (__alloc) {
_C_initn (_RWSTD_STATIC_CAST (size_type, __n), __c);
}
#endif // _RWSTD_NO_BOOL
#else // if defined (_RWSTD_NO_MEMBER_TEMPLATES)
basic_string (size_type __n, value_type __c,
const allocator_type& __alloc = allocator_type ())
: allocator_type (__alloc) {
_C_initn (__n, __c);
}
#endif // _RWSTD_NO_MEMBER_TEMPLATES
basic_string (const_pointer, const_pointer,
const allocator_type& = allocator_type ());
~basic_string () {
_C_unlink();
}
basic_string& operator= (const basic_string&);
basic_string& operator= (const_pointer __s);
basic_string& operator= (value_type __c) {
return replace (0, size(), 1, __c);
}
iterator begin () {
_C_cow ();
_C_pref ()->_C_set_ref_count (0); // disable ref counting
return _C_make_iter (_C_data);
}
const_iterator begin () const {
return _C_make_iter (_C_data);
}
iterator end () {
// disable reference counting
return begin () + size ();
}
const_iterator end () const {
return _C_make_iter (_C_data + size ());
}
reverse_iterator rbegin () {
return reverse_iterator (end ());
}
const_reverse_iterator rbegin () const {
return const_reverse_iterator (end ());
}
reverse_iterator rend () {
return reverse_iterator (begin ());
}
const_reverse_iterator rend () const {
return const_reverse_iterator (begin ());
}
size_type size () const {
return _C_pref()->_C_size;
}
size_type length () const {
return size ();
}
size_type max_size () const {
return size_type (npos) - sizeof (_C_string_ref_type) - 2U;
}
void resize (size_type, value_type);
void resize (size_type __n) {
resize (__n, value_type ());
}
size_type capacity () const {
return _C_pref ()->capacity ();
}
void reserve (size_type = 0);
void clear () {
erase ();
}
bool empty () const {
return size () == 0;
}
const_reference operator[] (size_type) const;
reference operator[] (size_type);
const_reference at (size_type) const;
reference at (size_type);
basic_string& operator+= (const basic_string &__s) {
return append (__s);
}
basic_string& operator+= (const_pointer __s) {
return append (__s);
}
basic_string& operator+= (value_type __c) {
return append (size_type (1), __c);
}
basic_string& append (const basic_string&, size_type, size_type);
basic_string& append (const basic_string &__str);
basic_string& append (const_pointer __s, size_type __n) {
return replace (size (), 0, __s, __n, 0, __n), *this;
}
basic_string& append (const_pointer __s) {
return replace (size (), 0, __s);
}
#if !defined (_RWSTD_NO_MEMBER_TEMPLATES) \
&& !defined (_RWSTD_NO_CLASS_PARTIAL_SPEC)
template<class _InputIterator>
basic_string& append (_InputIterator __first, _InputIterator __last) {
// resolves to append (size_type, value_type) if _InputIterator
// is any integral type (even not an exact match, such as char)
// the cast to int is necessary to prevent an exact match
return append (__first, __last, _RWSTD_DISPATCH (_InputIterator));
}
template<class _InputIterator>
basic_string& append (_InputIterator __first, _InputIterator __last,
_RWSTD_DISPATCH_INT (false)) {
return replace (_C_make_iter (_C_data + size ()),
_C_make_iter (_C_data + size ()),
__first, __last), *this;
}
basic_string& append (size_type __n, value_type __c,
_RWSTD_DISPATCH_INT (true)) {
// unnamed arg is used for overload resolution
return replace (size (), 0, __n, __c);
}
#else // if defined (_RWSTD_NO_MEMBER_TEMPLATES)
basic_string& append (const_pointer __first, const_pointer __last) {
replace (size (), 0, __first, __last - __first, 0, __last - __first);
return *this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -