Function InsertInternal

Synopsis

#include <include/EASTL/string.h>

iterator InsertInternal(const_iterator p, value_type c)

Description

No description yet.

Source

Lines 3191-3226 in include/EASTL/string.h. Line 761 in include/EASTL/string.h.

template <typename T, typename Allocator>
typename basic_string<T, Allocator>::iterator
basic_string<T, Allocator>::InsertInternal(const_iterator p, value_type c)
{
    iterator pNewPosition = const_cast<value_type*>(p);
    if((internalLayout().EndPtr() + 1) <= internalLayout().CapacityPtr())
    {
        const size_type nSavedSize = internalLayout().GetSize();
        memmove(const_cast<value_type*>(p) + 1, p, (size_t)(internalLayout().EndPtr() - p) * sizeof(value_type));
        *(internalLayout().EndPtr() + 1) = 0;
        *pNewPosition = c;
        internalLayout().SetSize(nSavedSize + 1);
    }
    else
    {
        const size_type nOldSize = internalLayout().GetSize();
        const size_type nOldCap  = capacity();
        const size_type nLength = GetNewCapacity(nOldCap, 1);
        iterator pNewBegin = DoAllocate(nLength + 1);
        pNewPosition = CharStringUninitializedCopy(internalLayout().BeginPtr(), p, pNewBegin);
       *pNewPosition = c;
        iterator pNewEnd = pNewPosition + 1;
        pNewEnd          = CharStringUninitializedCopy(p, internalLayout().EndPtr(), pNewEnd);
       *pNewEnd          = 0;
        DeallocateSelf();
        internalLayout().SetHeapBeginPtr(pNewBegin);
        internalLayout().SetHeapCapacity(nLength);
        internalLayout().SetHeapSize(nOldSize + 1);
    }
    return pNewPosition;
}





Add Discussion as Guest

Log in