📄 simple_string.hpp
字号:
/* /////////////////////////////////////////////////////////////////////////
* File: stlsoft/string/simple_string.hpp (originally MSString.h, ::SynesisDev)
*
* Purpose: basic_simple_string class template.
*
* Created: 19th March 1993
* Updated: 11th June 2006
*
* Home: http://stlsoft.org/
*
* Copyright (c) 1993-2006, Matthew Wilson and Synesis Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
* any contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* ////////////////////////////////////////////////////////////////////// */
/** \file stlsoft/string/simple_string.hpp
*
* \brief [C++ only] Definition of the stlsoft::basic_simple_string class
* template.
* (\ref group__library__string "String" Library.)
*/
///
/// basic_simple_string class template.
#ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SIMPLE_STRING
#define STLSOFT_INCL_STLSOFT_STRING_HPP_SIMPLE_STRING
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define STLSOFT_VER_STLSOFT_STRING_HPP_SIMPLE_STRING_MAJOR 4
# define STLSOFT_VER_STLSOFT_STRING_HPP_SIMPLE_STRING_MINOR 0
# define STLSOFT_VER_STLSOFT_STRING_HPP_SIMPLE_STRING_REVISION 1
# define STLSOFT_VER_STLSOFT_STRING_HPP_SIMPLE_STRING_EDIT 220
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* Compatibility
*/
/*
[Incompatibilies-start]
STLSOFT_COMPILER_IS_WATCOM:
[Incompatibilies-end]
*/
/* /////////////////////////////////////////////////////////////////////////
* Includes
*/
#ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
# include <stlsoft/stlsoft.h>
#endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
#ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_CHAR_TRAITS
# include <stlsoft/string/char_traits.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_CHAR_TRAITS */
#ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TRAITS_FWD
# include <stlsoft/string/string_traits_fwd.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TRAITS_FWD */
#ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_HPP_COLLECTIONS
# include <stlsoft/collections/collections.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_COLLECTIONS_HPP_COLLECTIONS */
#ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_BASE
# include <stlsoft/memory/allocator_base.hpp> // for STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT
#endif /* !STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_BASE */
#ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_SELECTOR
# include <stlsoft/memory/allocator_selector.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_SELECTOR */
#ifndef STLSOFT_INCL_STLSOFT_HPP_MEMORY_AUTO_BUFFER
# include <stlsoft/memory/auto_buffer.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_HPP_MEMORY_AUTO_BUFFER */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_STD_SWAP
# include <stlsoft/util/std_swap.hpp> // for stlsoft::std_swap()
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_STD_SWAP */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_GENERATORS
# include <stlsoft/util/std/iterator_generators.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_GENERATORS */
#ifndef STLSOFT_INCL_STLSOFT_HPP_ALGORITHMS
# include <stlsoft/algorithms.hpp> // for stlsoft::copy_n()
#endif /* !STLSOFT_INCL_STLSOFT_HPP_ALGORITHMS */
#ifndef STLSOFT_INCL_STLSOFT_HPP_MINMAX
# include <stlsoft/minmax.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_HPP_MINMAX */
#ifndef STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST
# include <stlsoft/conversion/sap_cast.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST */
#ifdef STLSOFT_UNITTEST
# include <stdio.h>
# include <string>
#endif /* STLSOFT_UNITTEST */
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
# include <stdexcept> // for std::out_of_range
#endif /* !STLSOFT_CF_EXCEPTION_SUPPORT */
/* /////////////////////////////////////////////////////////////////////////
*
*/
#if defined(STLSOFT_COMPILER_IS_MSVC) && \
_MSC_VER < 1200
# define STLSOFT_SIMPLE_STRING_ITERATOR_METHODS_INLINE
#endif /* compiler */
/* /////////////////////////////////////////////////////////////////////////
* Namespace
*/
#ifndef _STLSOFT_NO_NAMESPACE
namespace stlsoft
{
#endif /* _STLSOFT_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* Classes
*/
// class basic_simple_string
/** \brief Simple string class
*
* \param C The character type
* \param T The traits type. On translators that support default template arguments this is defaulted to char_traits<C>
* \param A The allocator type. On translators that support default template arguments this is defaulted to allocator_selector<C>::allocator_type
*
* \ingroup group__library__string
*/
template< ss_typename_param_k C
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
, ss_typename_param_k T = stlsoft_char_traits<C>
, ss_typename_param_k A = ss_typename_type_def_k allocator_selector<C>::allocator_type
#else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
, ss_typename_param_k T /* = stlsoft_char_traits<C> */
, ss_typename_param_k A /* = allocator_selector<C>::allocator_type */
#endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
>
class basic_simple_string
: public stl_collection_tag
{
/// \name Types
/// @{
public:
/// The value type
typedef C value_type;
/// The traits type
typedef T traits_type;
/// The allocator type
typedef A allocator_type;
/// The current parameterisation of the type
typedef basic_simple_string<C, T, A> class_type;
/// The character type
typedef value_type char_type;
/// The pointer type
typedef value_type *pointer;
/// The non-mutable (const) pointer type
typedef value_type const *const_pointer;
/// The reference type
typedef value_type &reference;
/// The non-mutable (const) reference type
typedef value_type const &const_reference;
/// The size type
typedef ss_size_t size_type;
/// The difference type
typedef ss_ptrdiff_t difference_type;
/// The iterator type
typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
ss_typename_type_k
#endif /* compiler */
pointer_iterator < value_type
, pointer
, reference
>::type iterator;
/// The non-mutating (const) iterator type
typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
ss_typename_type_k
#endif /* compiler */
pointer_iterator < value_type const
, const_pointer
, const_reference
>::type const_iterator;
#if defined(STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
/// The mutating (non-const) reverse iterator type
typedef ss_typename_type_k reverse_iterator_generator < iterator
, value_type
, reference
, pointer
, difference_type
>::type reverse_iterator;
/// The non-mutating (const) reverse iterator type
typedef ss_typename_type_k const_reverse_iterator_generator < const_iterator
, value_type
, const_reference
, const_pointer
, difference_type
>::type const_reverse_iterator;
#endif /* STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT */
private:
/// The allocator type for allocating bytes
///
/// \note This has to be defined here, rather than on a use-by-use basis, because
/// Borland gets very upset.
#ifdef STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT
typedef ss_typename_type_k A::ss_template_qual_k rebind<ss_byte_t>::other byte_ator_type;
#else /* ? STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT */
typedef ss_typename_type_k allocator_selector<ss_byte_t>::allocator_type byte_ator_type;
#endif /* STLSOFT_LF_ALLOCATOR_REBIND_SUPPORT */
/// @}
/// \name Construction
/// @{
public:
/// Default constructor
basic_simple_string();
/// Copy constructor
basic_simple_string(class_type const &rhs);
/// Construct from the given string at the specified position
basic_simple_string(class_type const &s, size_type pos);
/// Construct with \c cch characters from the given string at the specified position
basic_simple_string(class_type const &s, size_type pos, size_type cch);
/// Construct from the given character string
basic_simple_string(char_type const *s); // Not, not explicit. Sigh
/// Construct with \c cch characters from the given character string
basic_simple_string(char_type const *s, size_type cch);
/// Construct with \c cch characters each set to \c ch
basic_simple_string(size_type cch, char_type ch);
/// Construct from the range [first:last)
#if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
basic_simple_string(char_type const *first, char_type const *last);
#else /* ? STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT */
template <ss_typename_param_k II>
basic_simple_string(II first, II last)
: m_buffer(NULL)
{
assign(first, last);
}
#endif /* STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT */
/// Destructor
~basic_simple_string() stlsoft_throw_0();
/// @}
/// \name Assignment
/// @{
public:
/// Assigns from the given character string
class_type &assign(char_type const *s);
/// Assigns with \c cch characters from the given character string
class_type &assign(char_type const *s, size_type cch);
/// Assigns with \c cch characters from the given character string at the specified position
class_type &assign(class_type const &str, size_type pos, size_type cch);
/// Assigns from the given string
class_type &assign(class_type const &str);
/// Assigns \c cch characters with the value \c ch
class_type &assign(size_type cch, char_type ch);
/// Assigns from the range [first:last)
#if !defined(STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT)
class_type &assign(const_iterator first, const_iterator last);
#else /* ? STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT */
template <ss_typename_param_k II>
class_type &assign(II first, II last)
{
# if defined(STLSOFT_COMPILER_IS_GCC) && \
__GNUC__ < 3
typedef ss_typename_type_k std::iterator_traits<II> traits_t;
return assign_(first, last, traits_t::iterator_category());
# elif defined(STLSOFT_COMPILER_IS_MWERKS) || \
defined(STLSOFT_COMPILER_IS_DMC)
return assign_(first, last, stlsoft_iterator_query_category_ptr(II, first));
# else /* ? compiler */
return assign_(first, last, stlsoft_iterator_query_category(II, first));
# endif /* compiler */
}
#endif /* STLSOFT_CF_MEMBER_TEMPLATE_RANGE_METHOD_SUPPORT */
/// Copy assignment operator
class_type const &operator =(class_type const &rhs);
/// Assignment operator
class_type const &operator =(char_type const *s);
/// Assignment operator
class_type const &operator =(char_type ch);
/// @}
/// \name Appending
/// @{
public:
/// Appends the given character string
class_type &append(char_type const *s);
/// Appends \c cch characters from the given character string
class_type &append(char_type const *s, size_type cch);
/// Assigns \c cch characters from the given character string at the specified position
class_type &append(class_type const &str, size_type pos, size_type cch);
/// Appends the given string
class_type &append(class_type const &str);
/// Appends \c cch characters with the value \c ch
class_type &append(size_type cch, char_type ch);
/// Appends the range [first:last)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -