VirtualBox

Changeset 68154 in vbox


Ignore:
Timestamp:
Jul 28, 2017 11:58:57 AM (7 years ago)
Author:
vboxsync
Message:

iprt: Added RTCString::erase.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cpp/ministring.h

    r68124 r68154  
    532532
    533533    /**
     534     * Erases a sequence from the string.
     535     *
     536     * @returns Reference to the object.
     537     * @param   offStart        Where in @a this string to start erasing.
     538     * @param   cchLength       How much following @a offStart to erase.
     539     */
     540    RTCString &erase(size_t offStart = 0, size_t cchLength = npos);
     541
     542    /**
    534543     * Replaces a span of @a this string with a replacement string.
    535544     *
  • trunk/src/VBox/Runtime/common/string/ministring.cpp

    r68125 r68154  
    278278}
    279279
     280RTCString &RTCString::erase(size_t offStart /*= 0*/, size_t cchLength /*= npos*/)
     281{
     282    size_t cch = length();
     283    if (offStart < cch)
     284    {
     285        if (cchLength >= cch - offStart)
     286        {
     287            /* Trail removal, nothing to move.  */
     288            m_cch = offStart;
     289            m_psz[offStart] = '\0';
     290        }
     291        else if (cchLength > 0)
     292        {
     293            /* Pull up the tail to offStart. */
     294            size_t cchAfter = cch - offStart - cchLength;
     295            memmove(&m_psz[offStart], &m_psz[offStart + cchLength], cchAfter);
     296            m_cch = cch -= cchLength;
     297            m_psz[cch] = '\0';
     298        }
     299    }
     300    return *this;
     301}
    280302
    281303RTCString &RTCString::replace(size_t offStart, size_t cchLength, const RTCString &rStrReplacement)
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette