Class basic_string

Synopsis

#include <include/EASTL/string.h>

template <typename T, typename Allocator = EASTLAllocatorType>
class basic_string

Description

basic_string

Implements a templated string class, somewhat like C++ std::basic_string.

Notes: As of this writing, an insert of a string into itself necessarily triggers a reallocation, even if there is enough capacity in self to handle the increase in size. This is due to the slightly tricky nature of the operation of modifying one's self with one's self, and thus the source and destination are being modified during the operation. It might be useful to rectify this to the extent possible.

Our usage of noexcept specifiers is a little different from the requirements specified by std::basic_string in C++11. This is because our allocators are instances and not types and thus can be non-equal and result in exceptions during assignments that theoretically can't occur with std containers.

Mentioned in

Structures

CtorConvertCtorConvert exists so that we can have a constructor that implements string encoding conversion, such as between UCS2 char16_t and UTF8 char8_t.
CtorDoNotInitialize'npos' means non-valid position or simply non-position.
CtorSprintfCtorSprintf exists so that we can create a constructor that accepts printf-style arguments but also doesn't collide with any other constructor declaration.
HeapLayoutThe view of memory when the string data is obtained from the allocator.
LayoutThis implements the 'short string optimization' or SSO
RawLayoutThis view of memory is a utility structure for easy copying of the string data.
SSOLayoutThe view of memory when the string data is able to store the string data locally (without a heap allocation).
SSOPadding
SSOPadding< CharT, 1 >

Methods

basic_string overloadConstructor, destructor.
basic_string overloadCtorDoNotInitialize exists so that we can create a version that allocates but doesn't initialize but also doesn't collide with any other constructor declaration.
basic_string overloadCtorSprintf exists so that we can create a version that does a variable argument sprintf but also doesn't collide with any other constructor declaration.
~basic_string
AllocateSelf overload
append overload
append_convert overload
append_sprintf

Mentioned in

append_sprintf_va_list
assign overloadAssignment operations.
assign_convert overload
at overload
back overload
begin overloadIterators.
c_str

Mentioned in

capacity
cbegin
cend
CharTypeStringFindEndReplacements for STL template functions.
CharTypeStringFindFirstNotOfCharTypeStringFindFirstNotOf Specialized value_type version of STL find_first_not_of() function.
CharTypeStringFindFirstOfCharTypeStringFindFirstOf Specialized value_type version of STL find_first_of() function
CharTypeStringRFindCharTypeStringRFind Specialized value_type version of STL find() function in reverse.
CharTypeStringRFindFirstNotOfCharTypeStringRFindFirstNotOf Specialized value_type version of STL find_first_not_of() function in reverse.
CharTypeStringRFindFirstOfCharTypeStringRFindFirstOf Specialized value_type version of STL find_first_of() function in reverse
CharTypeStringRSearchCharTypeStringRSearch Specialized value_type version of STL find_end() function (which really is a reverse search function)
CharTypeStringSearchCharTypeStringSearch Specialized value_type version of STL search() function
clear
compare overloadComparison operations.
comparei overloadCase-insensitive comparison functions. Not part of C++ this_type. Only ASCII-level locale functionality is supported. Thus this is not suitable for localization purposes.
copy
crbegin
crend
data overloadRaw access.
DeallocateSelf
detachDetach memory.
DoAllocateHelper functions for initialization/insertion operations.
DoFree
emptySize-related functionality.
end overload
erase overloadErase operations.
find overloadFind operations.
find_first_not_of overloadFind first not-of operations.
find_first_of overloadFind first-of operations.
find_last_not_of overloadFind last not-of operations.
find_last_of overloadFind last-of operations.
force_size
front overload
get_allocator overloadAllocator.
GetNewCapacity overload
insert overloadInsertion operations.
InsertInternal
internalAllocator overload
internalLayout overload
IsSSO
left
length

Mentioned in

ltrim overload
make_lowerMisc functionality, not part of C++ this_type.
make_uppermake_upper This is a very simple ASCII-only case conversion function Anything more complicated should use a more powerful separate library.
max_size
operator basic_string_view< T >Implicit conversion operator.
operator+= overloadAppend operations.
operator= overloadOperator=.
operator[] overloadElement access.
pop_back
push_back
RangeInitialize overload
rbegin overload
rend overload
replace overloadReplacement operations.
reserve
resize overload
rfind overloadReverse find operations.
rtrim overload
set_allocator
set_capacity
shrink_to_fit
size
SizeInitialize
sprintf

Mentioned in

sprintf_va_list
substrSubstring functionality.
swap
ThrowInvalidArgumentException
ThrowLengthException
ThrowRangeException
trim overload

Mentioned in

validate
validate_iterator

Source

Lines 278-790 in include/EASTL/string.h.

template <typename T, typename Allocator = EASTLAllocatorType>
class basic_string
{
public:
    typedef basic_string<T, Allocator>                      this_type;
    typedef basic_string_view<T>                            view_type;
    typedef T                                               value_type;
    typedef T*                                              pointer;
    typedef const T*                                        const_pointer;
    typedef T&                                              reference;
    typedef const T&                                        const_reference;
    typedef T*                                              iterator;           // Maintainer note: We want to leave iterator defined as T* -- at least in release builds -- as this gives some algorithms an advantage that optimizers cannot get around.
    typedef const T*                                        const_iterator;
    typedef eastl::reverse_iterator<iterator>               reverse_iterator;
    typedef eastl::reverse_iterator<const_iterator>         const_reverse_iterator;
    typedef eastl_size_t                                    size_type;          // See config.h for the definition of eastl_size_t, which defaults to size_t.
    typedef ptrdiff_t                                       difference_type;
    typedef Allocator                                       allocator_type;
static const size_type npos     = (size_type)-1;      /// 'npos' means non-valid position or simply non-position.
public:
    // CtorDoNotInitialize exists so that we can create a constructor that allocates but doesn't
    // initialize and also doesn't collide with any other constructor declaration.
    struct CtorDoNotInitialize{};
    // CtorSprintf exists so that we can create a constructor that accepts printf-style
    // arguments but also doesn't collide with any other constructor declaration.
    struct CtorSprintf{};
    // CtorConvert exists so that we can have a constructor that implements string encoding
    // conversion, such as between UCS2 char16_t and UTF8 char8_t.
    struct CtorConvert{};
protected:
    // Masks used to determine if we are in SSO or Heap
    #ifdef EA_SYSTEM_BIG_ENDIAN
        // Big Endian use LSB, unless we want to reorder struct layouts on endianness, Bit is set when we are in Heap
        static constexpr size_type kHeapMask = 0x1;
        static constexpr size_type kSSOMask  = 0x1;
    #else
        // Little Endian use MSB
        static constexpr size_type kHeapMask = ~(size_type(~size_type(0)) >> 1);
        static constexpr size_type kSSOMask  = 0x80;
    #endif
public:
    #ifdef EA_SYSTEM_BIG_ENDIAN
        static constexpr size_type kMaxSize = (~kHeapMask) >> 1;
    #else
        static constexpr size_type kMaxSize = ~kHeapMask;
    #endif
protected:
    // The view of memory when the string data is obtained from the allocator.
    struct HeapLayout
    {
        value_type* mpBegin;  // Begin of string.
        size_type mnSize;     // Size of the string. Number of characters currently in the string, not including the trailing '0'
        size_type mnCapacity; // Capacity of the string. Number of characters string can hold, not including the trailing '0'
    };
    template <typename CharT, size_t = sizeof(CharT)>
    struct SSOPadding
    {
        char padding[sizeof(CharT) - sizeof(char)];
    };
    template <typename CharT>
    struct SSOPadding<CharT, 1>
    {
        // template specialization to remove the padding structure to avoid warnings on zero length arrays
        // also, this allows us to take advantage of the empty-base-class optimization.
    };
    // The view of memory when the string data is able to store the string data locally (without a heap allocation).
    struct SSOLayout
    {
        static constexpr size_type SSO_CAPACITY = (sizeof(HeapLayout) - sizeof(char)) / sizeof(value_type);
        // mnSize must correspond to the last byte of HeapLayout.mnCapacity, so we don't want the compiler to insert
        // padding after mnSize if sizeof(value_type) != 1; Also ensures both layouts are the same size.
        struct SSOSize : SSOPadding<value_type>
        {
            char mnRemainingSize;
        };
        value_type mData[SSO_CAPACITY]; // Local buffer for string data.
        SSOSize mRemainingSizeField;
    };
    // This view of memory is a utility structure for easy copying of the string data.
    struct RawLayout
    {
        char mBuffer[sizeof(HeapLayout)];
    };
    static_assert(sizeof(SSOLayout)  == sizeof(HeapLayout), "heap and sso layout structures must be the same size");
    static_assert(sizeof(HeapLayout) == sizeof(RawLayout),  "heap and raw layout structures must be the same size");
    // This implements the 'short string optimization' or SSO. SSO reuses the existing storage of string class to
    // hold string data short enough to fit therefore avoiding a heap allocation. The number of characters stored in
    // the string SSO buffer is variable and depends on the string character width. This implementation favors a
    // consistent string size than increasing the size of the string local data to accommodate a consistent number
    // of characters despite character width.
    struct Layout
    {
        union
        {
            HeapLayout heap;
            SSOLayout sso;
            RawLayout raw;
        };
        Layout()                                                  { ResetToSSO(); } // start as SSO by default
        Layout(const Layout& other)                               { Copy(*this, other); }
        Layout(Layout&& other)                                    { Move(*this, other); }
        Layout& operator=(const Layout& other)                    { Copy(*this, other); return *this; }
        Layout& operator=(Layout&& other)                         { Move(*this, other); return *this; }
        // We are using Heap when the bit is set, easier to conceptualize checking IsHeap instead of IsSSO
        inline bool IsHeap() const EA_NOEXCEPT                    { return !!(sso.mRemainingSizeField.mnRemainingSize & kSSOMask); }
        inline bool IsSSO() const EA_NOEXCEPT                     { return !IsHeap(); }
        inline value_type* SSOBufferPtr() EA_NOEXCEPT             { return sso.mData; }
        inline const value_type* SSOBufferPtr() const EA_NOEXCEPT { return sso.mData; }
        // Largest value for SSO.mnSize == 23, which has two LSB bits set, but on big-endian (BE)
        // use least significant bit (LSB) to denote heap so shift.
        inline size_type GetSSOSize() const EA_NOEXCEPT
        {
            #ifdef EA_SYSTEM_BIG_ENDIAN
                return SSOLayout::SSO_CAPACITY - (sso.mRemainingSizeField.mnRemainingSize >> 2);
            #else
                return (SSOLayout::SSO_CAPACITY - sso.mRemainingSizeField.mnRemainingSize);
            #endif
        }
        inline size_type GetHeapSize() const EA_NOEXCEPT { return heap.mnSize; }
        inline size_type GetSize() const EA_NOEXCEPT     { return IsHeap() ? GetHeapSize() : GetSSOSize(); }
        inline void SetSSOSize(size_type size) EA_NOEXCEPT
        {
            #ifdef EA_SYSTEM_BIG_ENDIAN
                sso.mRemainingSizeField.mnRemainingSize = (char)((SSOLayout::SSO_CAPACITY - size) << 2);
            #else
                sso.mRemainingSizeField.mnRemainingSize = (char)(SSOLayout::SSO_CAPACITY - size);
            #endif
        }
        inline void SetHeapSize(size_type size) EA_NOEXCEPT          { heap.mnSize = size; }
        inline void SetSize(size_type size) EA_NOEXCEPT              { IsHeap() ? SetHeapSize(size) : SetSSOSize(size); }
        inline size_type GetRemainingCapacity() const EA_NOEXCEPT    { return size_type(CapacityPtr() - EndPtr()); }
        inline value_type* HeapBeginPtr() EA_NOEXCEPT                { return heap.mpBegin; };
        inline const value_type* HeapBeginPtr() const EA_NOEXCEPT    { return heap.mpBegin; };
        inline value_type* SSOBeginPtr() EA_NOEXCEPT                 { return sso.mData; }
        inline const value_type* SSOBeginPtr() const EA_NOEXCEPT     { return sso.mData; }
        inline value_type* BeginPtr() EA_NOEXCEPT                    { return IsHeap() ? HeapBeginPtr() : SSOBeginPtr(); }
        inline const value_type* BeginPtr() const EA_NOEXCEPT        { return IsHeap() ? HeapBeginPtr() : SSOBeginPtr(); }
        inline value_type* HeapEndPtr() EA_NOEXCEPT                  { return heap.mpBegin + heap.mnSize; }
        inline const value_type* HeapEndPtr() const EA_NOEXCEPT      { return heap.mpBegin + heap.mnSize; }
        inline value_type* SSOEndPtr() EA_NOEXCEPT                   { return sso.mData + GetSSOSize(); }
        inline const value_type* SSOEndPtr() const EA_NOEXCEPT       { return sso.mData + GetSSOSize(); }
        // Points to end of character stream, *ptr == '0'
        inline value_type* EndPtr() EA_NOEXCEPT                      { return IsHeap() ? HeapEndPtr() : SSOEndPtr(); }
        inline const value_type* EndPtr() const EA_NOEXCEPT          { return IsHeap() ? HeapEndPtr() : SSOEndPtr(); }
        inline value_type* HeapCapacityPtr() EA_NOEXCEPT             { return heap.mpBegin + GetHeapCapacity(); }
        inline const value_type* HeapCapacityPtr() const EA_NOEXCEPT { return heap.mpBegin + GetHeapCapacity(); }
        inline value_type* SSOCapacityPtr() EA_NOEXCEPT               { return sso.mData + SSOLayout::SSO_CAPACITY; }
        inline const value_type* SSOCapacityPtr() const EA_NOEXCEPT   { return sso.mData + SSOLayout::SSO_CAPACITY; }
        // Points to end of the buffer at the terminating '0', *ptr == '0' <- only true when size() == capacity()
        inline value_type* CapacityPtr() EA_NOEXCEPT                 { return IsHeap() ? HeapCapacityPtr() : SSOCapacityPtr(); }
        inline const value_type* CapacityPtr() const EA_NOEXCEPT     { return IsHeap() ? HeapCapacityPtr() : SSOCapacityPtr(); }
        inline void SetHeapBeginPtr(value_type* pBegin) EA_NOEXCEPT  { heap.mpBegin = pBegin; }
        inline void SetHeapCapacity(size_type cap) EA_NOEXCEPT
        {
        #ifdef EA_SYSTEM_BIG_ENDIAN
            heap.mnCapacity = (cap << 1) | kHeapMask;
        #else
            heap.mnCapacity = (cap | kHeapMask);
        #endif
        }
        inline size_type GetHeapCapacity() const EA_NOEXCEPT
        {
        #ifdef EA_SYSTEM_BIG_ENDIAN
            return (heap.mnCapacity >> 1);
        #else
            return (heap.mnCapacity & ~kHeapMask);
        #endif
        }
        inline void Copy(Layout& dst, const Layout& src) EA_NOEXCEPT { dst.raw = src.raw; }
        inline void Move(Layout& dst, Layout& src) EA_NOEXCEPT       { eastl::swap(dst.raw, src.raw); }
        inline void Swap(Layout& a, Layout& b) EA_NOEXCEPT           { eastl::swap(a.raw, b.raw); }
        inline void ResetToSSO() EA_NOEXCEPT { *SSOBeginPtr() = 0; SetSSOSize(0); }
    };
    eastl::compressed_pair<Layout, allocator_type> mPair;
    inline Layout& internalLayout() EA_NOEXCEPT                        { return mPair.first(); }
    inline const Layout& internalLayout() const EA_NOEXCEPT            { return mPair.first(); }
    inline allocator_type& internalAllocator() EA_NOEXCEPT             { return mPair.second(); }
    inline const allocator_type& internalAllocator() const EA_NOEXCEPT { return mPair.second(); }
public:
    // Constructor, destructor
    basic_string() EA_NOEXCEPT_IF(EA_NOEXCEPT_EXPR(EASTL_BASIC_STRING_DEFAULT_ALLOCATOR));
    explicit basic_string(const allocator_type& allocator) EA_NOEXCEPT;
    basic_string(const this_type& x, size_type position, size_type n = npos);
    basic_string(const value_type* p, size_type n, const allocator_type& allocator = EASTL_BASIC_STRING_DEFAULT_ALLOCATOR);
    EASTL_STRING_EXPLICIT basic_string(const value_type* p, const allocator_type& allocator = EASTL_BASIC_STRING_DEFAULT_ALLOCATOR);
    basic_string(size_type n, value_type c, const allocator_type& allocator = EASTL_BASIC_STRING_DEFAULT_ALLOCATOR);
    basic_string(const this_type& x);
    basic_string(const this_type& x, const allocator_type& allocator);
    basic_string(const value_type* pBegin, const value_type* pEnd, const allocator_type& allocator = EASTL_BASIC_STRING_DEFAULT_ALLOCATOR);
    basic_string(CtorDoNotInitialize, size_type n, const allocator_type& allocator = EASTL_BASIC_STRING_DEFAULT_ALLOCATOR);
    basic_string(CtorSprintf, const value_type* pFormat, ...);
    basic_string(std::initializer_list<value_type> init, const allocator_type& allocator = EASTL_BASIC_STRING_DEFAULT_ALLOCATOR);
    basic_string(this_type&& x) EA_NOEXCEPT;
    basic_string(this_type&& x, const allocator_type& allocator);
    explicit basic_string(const view_type& sv, const allocator_type& allocator = EASTL_BASIC_STRING_DEFAULT_ALLOCATOR);
    basic_string(const view_type& sv, size_type position, size_type n, const allocator_type& allocator = EASTL_BASIC_STRING_DEFAULT_ALLOCATOR);
    template <typename OtherCharType>
    basic_string(CtorConvert, const OtherCharType* p, const allocator_type& allocator = EASTL_BASIC_STRING_DEFAULT_ALLOCATOR);
    template <typename OtherCharType>
    basic_string(CtorConvert, const OtherCharType* p, size_type n, const allocator_type& allocator = EASTL_BASIC_STRING_DEFAULT_ALLOCATOR);
    template <typename OtherStringType> // Unfortunately we need the CtorConvert here because otherwise this function would collide with the value_type* constructor.
    basic_string(CtorConvert, const OtherStringType& x);
   ~basic_string();
    // Allocator
    const allocator_type& get_allocator() const EA_NOEXCEPT;
    allocator_type&       get_allocator() EA_NOEXCEPT;
    void                  set_allocator(const allocator_type& allocator);
    // Implicit conversion operator
    operator basic_string_view<T>() const EA_NOEXCEPT;
    // Operator=
    this_type& operator=(const this_type& x);
    this_type& operator=(const value_type* p);
    this_type& operator=(value_type c);
    this_type& operator=(std::initializer_list<value_type> ilist);
    this_type& operator=(view_type v);
    this_type& operator=(this_type&& x); // TODO(c++17): noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || allocator_traits<Allocator>::is_always_equal::value);
    #if EASTL_OPERATOR_EQUALS_OTHER_ENABLED
        this_type& operator=(value_type* p) { return operator=((const value_type*)p); } // We need this because otherwise the const value_type* version can collide with the const OtherStringType& version below.
        template <typename OtherCharType>
        this_type& operator=(const OtherCharType* p);
        template <typename OtherStringType>
        this_type& operator=(const OtherStringType& x);
    #endif
    void swap(this_type& x); // TODO(c++17): noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value || allocator_traits<Allocator>::is_always_equal::value);
    // Assignment operations
    this_type& assign(const this_type& x);
    this_type& assign(const this_type& x, size_type position, size_type n = npos);
    this_type& assign(const value_type* p, size_type n);
    this_type& assign(const value_type* p);
    this_type& assign(size_type n, value_type c);
    this_type& assign(const value_type* pBegin, const value_type* pEnd);
    this_type& assign(this_type&& x); // TODO(c++17): noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || allocator_traits<Allocator>::is_always_equal::value);
    this_type& assign(std::initializer_list<value_type>);
    template <typename OtherCharType>
    this_type& assign_convert(const OtherCharType* p);
    template <typename OtherCharType>
    this_type& assign_convert(const OtherCharType* p, size_type n);
    template <typename OtherStringType>
    this_type& assign_convert(const OtherStringType& x);
    // Iterators.
    iterator       begin() EA_NOEXCEPT;                 // Expanded in source code as: mpBegin
    const_iterator begin() const EA_NOEXCEPT;           // Expanded in source code as: mpBegin
    const_iterator cbegin() const EA_NOEXCEPT;
    iterator       end() EA_NOEXCEPT;                   // Expanded in source code as: mpEnd
    const_iterator end() const EA_NOEXCEPT;             // Expanded in source code as: mpEnd
    const_iterator cend() const EA_NOEXCEPT;
    reverse_iterator       rbegin() EA_NOEXCEPT;
    const_reverse_iterator rbegin() const EA_NOEXCEPT;
    const_reverse_iterator crbegin() const EA_NOEXCEPT;
    reverse_iterator       rend() EA_NOEXCEPT;
    const_reverse_iterator rend() const EA_NOEXCEPT;
    const_reverse_iterator crend() const EA_NOEXCEPT;
    // Size-related functionality
    bool      empty() const EA_NOEXCEPT;
    size_type size() const EA_NOEXCEPT;
    size_type length() const EA_NOEXCEPT;
    size_type max_size() const EA_NOEXCEPT;
    size_type capacity() const EA_NOEXCEPT;
    void      resize(size_type n, value_type c);
    void      resize(size_type n);
    void      reserve(size_type = 0);
    void      set_capacity(size_type n = npos); // Revises the capacity to the user-specified value. Resizes the container to match the capacity if the requested capacity n is less than the current size. If n == npos then the capacity is reallocated (if necessary) such that capacity == size.
    void      force_size(size_type n);          // Unilaterally moves the string end position (mpEnd) to the given location. Useful for when the user writes into the string via some extenal means such as C strcpy or sprintf. This allows for more efficient use than using resize to achieve this.
    void shrink_to_fit();
    // Raw access
    const value_type* data() const  EA_NOEXCEPT;
          value_type* data()        EA_NOEXCEPT;
    const value_type* c_str() const EA_NOEXCEPT;
    // Element access
    reference       operator[](size_type n);
    const_reference operator[](size_type n) const;
    reference       at(size_type n);
    const_reference at(size_type n) const;
    reference       front();
    const_reference front() const;
    reference       back();
    const_reference back() const;
    // Append operations
    this_type& operator+=(const this_type& x);
    this_type& operator+=(const value_type* p);
    this_type& operator+=(value_type c);
    this_type& append(const this_type& x);
    this_type& append(const this_type& x,  size_type position, size_type n = npos);
    this_type& append(const value_type* p, size_type n);
    this_type& append(const value_type* p);
    this_type& append(size_type n, value_type c);
    this_type& append(const value_type* pBegin, const value_type* pEnd);
    this_type& append_sprintf_va_list(const value_type* pFormat, va_list arguments);
    this_type& append_sprintf(const value_type* pFormat, ...);
    template <typename OtherCharType>
    this_type& append_convert(const OtherCharType* p);
    template <typename OtherCharType>
    this_type& append_convert(const OtherCharType* p, size_type n);
    template <typename OtherStringType>
    this_type& append_convert(const OtherStringType& x);
    void push_back(value_type c);
    void pop_back();
    // Insertion operations
    this_type& insert(size_type position, const this_type& x);
    this_type& insert(size_type position, const this_type& x, size_type beg, size_type n);
    this_type& insert(size_type position, const value_type* p, size_type n);
    this_type& insert(size_type position, const value_type* p);
    this_type& insert(size_type position, size_type n, value_type c);
    iterator   insert(const_iterator p, value_type c);
    iterator   insert(const_iterator p, size_type n, value_type c);
    iterator   insert(const_iterator p, const value_type* pBegin, const value_type* pEnd);
    iterator   insert(const_iterator p, std::initializer_list<value_type>);
    // Erase operations
    this_type&       erase(size_type position = 0, size_type n = npos);
    iterator         erase(const_iterator p);
    iterator         erase(const_iterator pBegin, const_iterator pEnd);
    reverse_iterator erase(reverse_iterator position);
    reverse_iterator erase(reverse_iterator first, reverse_iterator last);
    void             clear() EA_NOEXCEPT;
    // Detach memory
    pointer detach() EA_NOEXCEPT;
    // Replacement operations
    this_type&  replace(size_type position, size_type n,  const this_type& x);
    this_type&  replace(size_type pos1,     size_type n1, const this_type& x,  size_type pos2, size_type n2 = npos);
    this_type&  replace(size_type position, size_type n1, const value_type* p, size_type n2);
    this_type&  replace(size_type position, size_type n1, const value_type* p);
    this_type&  replace(size_type position, size_type n1, size_type n2, value_type c);
    this_type&  replace(const_iterator first, const_iterator last, const this_type& x);
    this_type&  replace(const_iterator first, const_iterator last, const value_type* p, size_type n);
    this_type&  replace(const_iterator first, const_iterator last, const value_type* p);
    this_type&  replace(const_iterator first, const_iterator last, size_type n, value_type c);
    this_type&  replace(const_iterator first, const_iterator last, const value_type* pBegin, const value_type* pEnd);
    size_type   copy(value_type* p, size_type n, size_type position = 0) const;
    // Find operations
    size_type find(const this_type& x,  size_type position = 0) const EA_NOEXCEPT;
    size_type find(const value_type* p, size_type position = 0) const;
    size_type find(const value_type* p, size_type position, size_type n) const;
    size_type find(value_type c, size_type position = 0) const EA_NOEXCEPT;
    // Reverse find operations
    size_type rfind(const this_type& x,  size_type position = npos) const EA_NOEXCEPT;
    size_type rfind(const value_type* p, size_type position = npos) const;
    size_type rfind(const value_type* p, size_type position, size_type n) const;
    size_type rfind(value_type c, size_type position = npos) const EA_NOEXCEPT;
    // Find first-of operations
    size_type find_first_of(const this_type& x, size_type position = 0) const EA_NOEXCEPT;
    size_type find_first_of(const value_type* p, size_type position = 0) const;
    size_type find_first_of(const value_type* p, size_type position, size_type n) const;
    size_type find_first_of(value_type c, size_type position = 0) const EA_NOEXCEPT;
    // Find last-of operations
    size_type find_last_of(const this_type& x, size_type position = npos) const EA_NOEXCEPT;
    size_type find_last_of(const value_type* p, size_type position = npos) const;
    size_type find_last_of(const value_type* p, size_type position, size_type n) const;
    size_type find_last_of(value_type c, size_type position = npos) const EA_NOEXCEPT;
    // Find first not-of operations
    size_type find_first_not_of(const this_type& x, size_type position = 0) const EA_NOEXCEPT;
    size_type find_first_not_of(const value_type* p, size_type position = 0) const;
    size_type find_first_not_of(const value_type* p, size_type position, size_type n) const;
    size_type find_first_not_of(value_type c, size_type position = 0) const EA_NOEXCEPT;
    // Find last not-of operations
    size_type find_last_not_of(const this_type& x,  size_type position = npos) const EA_NOEXCEPT;
    size_type find_last_not_of(const value_type* p, size_type position = npos) const;
    size_type find_last_not_of(const value_type* p, size_type position, size_type n) const;
    size_type find_last_not_of(value_type c, size_type position = npos) const EA_NOEXCEPT;
    // Substring functionality
    this_type substr(size_type position = 0, size_type n = npos) const;
    // Comparison operations
    int        compare(const this_type& x) const EA_NOEXCEPT;
    int        compare(size_type pos1, size_type n1, const this_type& x) const;
    int        compare(size_type pos1, size_type n1, const this_type& x, size_type pos2, size_type n2) const;
    int        compare(const value_type* p) const;
    int        compare(size_type pos1, size_type n1, const value_type* p) const;
    int        compare(size_type pos1, size_type n1, const value_type* p, size_type n2) const;
    static int compare(const value_type* pBegin1, const value_type* pEnd1, const value_type* pBegin2, const value_type* pEnd2);
    // Case-insensitive comparison functions. Not part of C++ this_type. Only ASCII-level locale functionality is supported. Thus this is not suitable for localization purposes.
    int        comparei(const this_type& x) const EA_NOEXCEPT;
    int        comparei(const value_type* p) const;
    static int comparei(const value_type* pBegin1, const value_type* pEnd1, const value_type* pBegin2, const value_type* pEnd2);
    // Misc functionality, not part of C++ this_type.
    void         make_lower();
    void         make_upper();
    void         ltrim();
    void         rtrim();
    void         trim();
    void         ltrim(const value_type* p);
    void         rtrim(const value_type* p);
    void         trim(const value_type* p);
    this_type    left(size_type n) const;
    this_type    right(size_type n) const;
    this_type&   sprintf_va_list(const value_type* pFormat, va_list arguments);
    this_type&   sprintf(const value_type* pFormat, ...);
    bool validate() const EA_NOEXCEPT;
    int  validate_iterator(const_iterator i) const EA_NOEXCEPT;
protected:
    // Helper functions for initialization/insertion operations.
    value_type* DoAllocate(size_type n);
    void        DoFree(value_type* p, size_type n);
    size_type   GetNewCapacity(size_type currentCapacity);
    size_type   GetNewCapacity(size_type currentCapacity, size_type minimumGrowSize);
    void        AllocateSelf();
    void        AllocateSelf(size_type n);
    void        DeallocateSelf();
    iterator    InsertInternal(const_iterator p, value_type c);
    void        RangeInitialize(const value_type* pBegin, const value_type* pEnd);
    void        RangeInitialize(const value_type* pBegin);
    void        SizeInitialize(size_type n, value_type c);
    bool        IsSSO() const EA_NOEXCEPT;
    void        ThrowLengthException() const;
    void        ThrowRangeException() const;
    void        ThrowInvalidArgumentException() const;
    #if EASTL_OPERATOR_EQUALS_OTHER_ENABLED
        template <typename CharType>
        void DoAssignConvert(CharType c, true_type);
        template <typename StringType>
        void DoAssignConvert(const StringType& x, false_type);
    #endif
    // Replacements for STL template functions.
    static const value_type* CharTypeStringFindEnd(const value_type* pBegin, const value_type* pEnd, value_type c);
    static const value_type* CharTypeStringRFind(const value_type* pRBegin, const value_type* pREnd, const value_type c);
    static const value_type* CharTypeStringSearch(const value_type* p1Begin, const value_type* p1End, const value_type* p2Begin, const value_type* p2End);
    static const value_type* CharTypeStringRSearch(const value_type* p1Begin, const value_type* p1End, const value_type* p2Begin, const value_type* p2End);
    static const value_type* CharTypeStringFindFirstOf(const value_type* p1Begin, const value_type* p1End, const value_type* p2Begin, const value_type* p2End);
    static const value_type* CharTypeStringRFindFirstOf(const value_type* p1RBegin, const value_type* p1REnd, const value_type* p2Begin, const value_type* p2End);
    static const value_type* CharTypeStringFindFirstNotOf(const value_type* p1Begin, const value_type* p1End, const value_type* p2Begin, const value_type* p2End);
    static const value_type* CharTypeStringRFindFirstNotOf(const value_type* p1RBegin, const value_type* p1REnd, const value_type* p2Begin, const value_type* p2End);
}; // basic_string





Add Discussion as Guest

Log in