Function replace

Summary

#include <include/EASTL/string.h>

(1) this_type & replace(size_type position, size_type n, const this_type &x)

(2) this_type & replace(size_type pos1, size_type n1, const this_type &x, size_type pos2, size_type n2=npos)

(3) this_type & replace(size_type position, size_type n1, const value_type *p, size_type n2)

(4) this_type & replace(size_type position, size_type n1, const value_type *p)

(5) this_type & replace(size_type position, size_type n1, size_type n2, value_type c)

(6) this_type & replace(const_iterator first, const_iterator last, const this_type &x)

(7) this_type & replace(const_iterator first, const_iterator last, const value_type *p, size_type n)

(8) this_type & replace(const_iterator first, const_iterator last, const value_type *p)

(9) this_type & replace(const_iterator first, const_iterator last, size_type n, value_type c)

(10) this_type & replace(const_iterator first, const_iterator last, const value_type *pBegin, const value_type *pEnd)

Function overload

Synopsis

#include <include/EASTL/string.h>

this_type & replace(size_type position, size_type n, const this_type &x)

Description

Replacement operations.

Source

Lines 2393-2409 in include/EASTL/string.h. Line 669 in include/EASTL/string.h.

template <typename T, typename Allocator>
basic_string<T, Allocator>& basic_string<T, Allocator>::replace(size_type position, size_type n, const this_type& x)
{
    #if EASTL_STRING_OPT_RANGE_ERRORS
        if(EASTL_UNLIKELY(position > internalLayout().GetSize()))
            ThrowRangeException();
    #endif
    const size_type nLength = eastl::min_alt(n, internalLayout().GetSize() - position);
    #if EASTL_STRING_OPT_LENGTH_ERRORS
        if(EASTL_UNLIKELY((internalLayout().GetSize() - nLength) >= (max_size() - x.internalLayout().GetSize())))
            ThrowLengthException();
    #endif
    return replace(internalLayout().BeginPtr() + position, internalLayout().BeginPtr() + position + nLength, x.internalLayout().BeginPtr(), x.internalLayout().EndPtr());
}

Synopsis

#include <include/EASTL/string.h>

this_type & replace(size_type pos1, size_type n1, const this_type &x, size_type pos2, size_type n2=npos)

Description

No description yet.

Source

Lines 2412-2429 in include/EASTL/string.h. Line 670 in include/EASTL/string.h.

template <typename T, typename Allocator>
basic_string<T, Allocator>& basic_string<T, Allocator>::replace(size_type pos1, size_type n1, const this_type& x, size_type pos2, size_type n2)
{
    #if EASTL_STRING_OPT_RANGE_ERRORS
    if(EASTL_UNLIKELY((pos1 > internalLayout().GetSize()) || (pos2 > x.internalLayout().GetSize())))
            ThrowRangeException();
    #endif
    const size_type nLength1 = eastl::min_alt(n1, internalLayout().GetSize() - pos1);
    const size_type nLength2 = eastl::min_alt(n2, x.internalLayout().GetSize() - pos2);
    #if EASTL_STRING_OPT_LENGTH_ERRORS
        if(EASTL_UNLIKELY((internalLayout().GetSize() - nLength1) >= (max_size() - nLength2)))
            ThrowLengthException();
    #endif
    return replace(internalLayout().BeginPtr() + pos1, internalLayout().BeginPtr() + pos1 + nLength1, x.internalLayout().BeginPtr() + pos2, x.internalLayout().BeginPtr() + pos2 + nLength2);
}

Synopsis

#include <include/EASTL/string.h>

this_type & replace(size_type position, size_type n1, const value_type *p, size_type n2)

Description

No description yet.

Source

Lines 2432-2448 in include/EASTL/string.h. Line 671 in include/EASTL/string.h.

template <typename T, typename Allocator>
basic_string<T, Allocator>& basic_string<T, Allocator>::replace(size_type position, size_type n1, const value_type* p, size_type n2)
{
    #if EASTL_STRING_OPT_RANGE_ERRORS
        if(EASTL_UNLIKELY(position > internalLayout().GetSize()))
            ThrowRangeException();
    #endif
    const size_type nLength = eastl::min_alt(n1, internalLayout().GetSize() - position);
    #if EASTL_STRING_OPT_LENGTH_ERRORS
        if(EASTL_UNLIKELY((n2 > max_size()) || ((internalLayout().GetSize() - nLength) >= (max_size() - n2))))
            ThrowLengthException();
    #endif
    return replace(internalLayout().BeginPtr() + position, internalLayout().BeginPtr() + position + nLength, p, p + n2);
}

Synopsis

#include <include/EASTL/string.h>

this_type & replace(size_type position, size_type n1, const value_type *p)

Description

No description yet.

Source

Lines 2451-2468 in include/EASTL/string.h. Line 672 in include/EASTL/string.h.

template <typename T, typename Allocator>
basic_string<T, Allocator>& basic_string<T, Allocator>::replace(size_type position, size_type n1, const value_type* p)
{
    #if EASTL_STRING_OPT_RANGE_ERRORS
        if(EASTL_UNLIKELY(position > internalLayout().GetSize()))
            ThrowRangeException();
    #endif
    const size_type nLength = eastl::min_alt(n1, internalLayout().GetSize() - position);
    #if EASTL_STRING_OPT_LENGTH_ERRORS
        const size_type n2 = (size_type)CharStrlen(p);
        if(EASTL_UNLIKELY((n2 > max_size()) || ((internalLayout().GetSize() - nLength) >= (max_size() - n2))))
            ThrowLengthException();
    #endif
    return replace(internalLayout().BeginPtr() + position, internalLayout().BeginPtr() + position + nLength, p, p + CharStrlen(p));
}

Synopsis

#include <include/EASTL/string.h>

this_type & replace(size_type position, size_type n1, size_type n2, value_type c)

Description

No description yet.

Source

Lines 2471-2487 in include/EASTL/string.h. Line 673 in include/EASTL/string.h.

template <typename T, typename Allocator>
basic_string<T, Allocator>& basic_string<T, Allocator>::replace(size_type position, size_type n1, size_type n2, value_type c)
{
    #if EASTL_STRING_OPT_RANGE_ERRORS
        if(EASTL_UNLIKELY(position > internalLayout().GetSize()))
            ThrowRangeException();
    #endif
    const size_type nLength = eastl::min_alt(n1, internalLayout().GetSize() - position);
    #if EASTL_STRING_OPT_LENGTH_ERRORS
        if(EASTL_UNLIKELY((n2 > max_size()) || (internalLayout().GetSize() - nLength) >= (max_size() - n2)))
            ThrowLengthException();
    #endif
    return replace(internalLayout().BeginPtr() + position, internalLayout().BeginPtr() + position + nLength, n2, c);
}

Synopsis

#include <include/EASTL/string.h>

this_type & replace(const_iterator first, const_iterator last, const this_type &x)

Description

No description yet.

Source

Lines 2490-2494 in include/EASTL/string.h. Line 674 in include/EASTL/string.h.

template <typename T, typename Allocator>
inline basic_string<T, Allocator>& basic_string<T, Allocator>::replace(const_iterator pBegin, const_iterator pEnd, const this_type& x)
{
    return replace(pBegin, pEnd, x.internalLayout().BeginPtr(), x.internalLayout().EndPtr());
}

Synopsis

#include <include/EASTL/string.h>

this_type & replace(const_iterator first, const_iterator last, const value_type *p, size_type n)

Description

No description yet.

Source

Lines 2497-2501 in include/EASTL/string.h. Line 675 in include/EASTL/string.h.

template <typename T, typename Allocator>
inline basic_string<T, Allocator>& basic_string<T, Allocator>::replace(const_iterator pBegin, const_iterator pEnd, const value_type* p, size_type n)
{
    return replace(pBegin, pEnd, p, p + n);
}

Synopsis

#include <include/EASTL/string.h>

this_type & replace(const_iterator first, const_iterator last, const value_type *p)

Description

No description yet.

Source

Lines 2504-2508 in include/EASTL/string.h. Line 676 in include/EASTL/string.h.

template <typename T, typename Allocator>
inline basic_string<T, Allocator>& basic_string<T, Allocator>::replace(const_iterator pBegin, const_iterator pEnd, const value_type* p)
{
    return replace(pBegin, pEnd, p, p + CharStrlen(p));
}

Synopsis

#include <include/EASTL/string.h>

this_type & replace(const_iterator first, const_iterator last, size_type n, value_type c)

Description

No description yet.

Source

Lines 2511-2533 in include/EASTL/string.h. Line 677 in include/EASTL/string.h.

template <typename T, typename Allocator>
basic_string<T, Allocator>& basic_string<T, Allocator>::replace(const_iterator pBegin, const_iterator pEnd, size_type n, value_type c)
{
    #if EASTL_ASSERT_ENABLED
        if (EASTL_UNLIKELY((pBegin < internalLayout().BeginPtr()) || (pBegin > internalLayout().EndPtr()) ||
                           (pEnd < internalLayout().BeginPtr()) || (pEnd > internalLayout().EndPtr()) || (pEnd < pBegin)))
            EASTL_FAIL_MSG("basic_string::replace -- invalid position");
    #endif
    const size_type nLength = static_cast<size_type>(pEnd - pBegin);
    if(nLength >= n)
    {
        CharTypeAssignN(const_cast<value_type*>(pBegin), n, c);
        erase(pBegin + n, pEnd);
    }
    else
    {
        CharTypeAssignN(const_cast<value_type*>(pBegin), nLength, c);
        insert(pEnd, n - nLength, c);
    }
    return *this;
}

Synopsis

#include <include/EASTL/string.h>

this_type & replace(const_iterator first, const_iterator last, const value_type *pBegin, const value_type *pEnd)

Description

No description yet.

Source

Lines 2536-2589 in include/EASTL/string.h. Line 678 in include/EASTL/string.h.

template <typename T, typename Allocator>
basic_string<T, Allocator>& basic_string<T, Allocator>::replace(const_iterator pBegin1, const_iterator pEnd1, const value_type* pBegin2, const value_type* pEnd2)
{
    #if EASTL_ASSERT_ENABLED
        if (EASTL_UNLIKELY((pBegin1 < internalLayout().BeginPtr()) || (pBegin1 > internalLayout().EndPtr()) ||
                           (pEnd1 < internalLayout().BeginPtr()) || (pEnd1 > internalLayout().EndPtr()) || (pEnd1 < pBegin1)))
            EASTL_FAIL_MSG("basic_string::replace -- invalid position");
    #endif
    const size_type nLength1 = (size_type)(pEnd1 - pBegin1);
    const size_type nLength2 = (size_type)(pEnd2 - pBegin2);
    if(nLength1 >= nLength2) // If we have a non-expanding operation...
    {
        if((pBegin2 > pEnd1) || (pEnd2 <= pBegin1))  // If we have a non-overlapping operation...
            memcpy(const_cast<value_type*>(pBegin1), pBegin2, (size_t)(pEnd2 - pBegin2) * sizeof(value_type));
        else
            memmove(const_cast<value_type*>(pBegin1), pBegin2, (size_t)(pEnd2 - pBegin2) * sizeof(value_type));
        erase(pBegin1 + nLength2, pEnd1);
    }
    else // Else we are expanding.
    {
        if((pBegin2 > pEnd1) || (pEnd2 <= pBegin1)) // If we have a non-overlapping operation...
        {
            const value_type* const pMid2 = pBegin2 + nLength1;
            if((pEnd2 <= pBegin1) || (pBegin2 > pEnd1))
                memcpy(const_cast<value_type*>(pBegin1), pBegin2, (size_t)(pMid2 - pBegin2) * sizeof(value_type));
            else
                memmove(const_cast<value_type*>(pBegin1), pBegin2, (size_t)(pMid2 - pBegin2) * sizeof(value_type));
            insert(pEnd1, pMid2, pEnd2);
        }
        else // else we have an overlapping operation.
        {
            // I can't think of any easy way of doing this without allocating temporary memory.
            const size_type nOldSize     = internalLayout().GetSize();
            const size_type nOldCap      = capacity();
            const size_type nNewCapacity = GetNewCapacity(nOldCap, (nOldSize + (nLength2 - nLength1)) - nOldCap);
            pointer pNewBegin = DoAllocate(nNewCapacity + 1);
            pointer pNewEnd = CharStringUninitializedCopy(internalLayout().BeginPtr(), pBegin1, pNewBegin);
            pNewEnd         = CharStringUninitializedCopy(pBegin2, pEnd2,   pNewEnd);
            pNewEnd         = CharStringUninitializedCopy(pEnd1,   internalLayout().EndPtr(),   pNewEnd);
           *pNewEnd         = 0;
            DeallocateSelf();
            internalLayout().SetHeapBeginPtr(pNewBegin);
            internalLayout().SetHeapCapacity(nNewCapacity);
            internalLayout().SetHeapSize(nOldSize + (nLength2 - nLength1));
        }
    }
    return *this;
}





Add Discussion as Guest

Log in