VirtualBox

Ignore:
Timestamp:
Jun 28, 2017 10:26:10 PM (7 years ago)
Author:
vboxsync
Message:

RTCString: Added append methods for appending a substring.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/string/ministring.cpp

    r67673 r67674  
    104104RTCString &RTCString::append(const RTCString &that)
    105105{
    106     size_t cchThat = that.length();
    107     if (cchThat)
     106    Assert(&that != this);
     107    return appendWorker(that.c_str(), that.length());
     108}
     109
     110RTCString &RTCString::append(const char *pszThat)
     111{
     112    return appendWorker(pszThat, strlen(pszThat));
     113}
     114
     115RTCString &RTCString::append(const RTCString &rThat, size_t offStart, size_t cchMax /*= RTSTR_MAX*/)
     116{
     117    if (offStart < rThat.length())
     118    {
     119        size_t cchLeft = rThat.length() - offStart;
     120        return appendWorker(rThat.c_str() + offStart, RT_MIN(cchLeft, cchMax));
     121    }
     122    return *this;
     123}
     124
     125RTCString &RTCString::append(const char *pszThat, size_t cchMax)
     126{
     127    return appendWorker(pszThat, RTStrNLen(pszThat, cchMax));
     128}
     129
     130RTCString &RTCString::appendWorker(const char *pszSrc, size_t cchSrc)
     131{
     132    if (cchSrc)
    108133    {
    109134        size_t cchThis = length();
    110         size_t cchBoth = cchThis + cchThat;
     135        size_t cchBoth = cchThis + cchSrc;
    111136
    112137        if (cchBoth >= m_cbAllocated)
     
    119144        }
    120145
    121         memcpy(m_psz + cchThis, that.m_psz, cchThat);
    122         m_psz[cchBoth] = '\0';
    123         m_cch = cchBoth;
    124     }
    125     return *this;
    126 }
    127 
    128 RTCString &RTCString::append(const char *pszThat)
    129 {
    130     size_t cchThat = strlen(pszThat);
    131     if (cchThat)
    132     {
    133         size_t cchThis = length();
    134         size_t cchBoth = cchThis + cchThat;
    135 
    136         if (cchBoth >= m_cbAllocated)
    137         {
    138             reserve(RT_ALIGN_Z(cchBoth + 1, IPRT_MINISTRING_APPEND_ALIGNMENT));
    139             // calls realloc(cchBoth + 1) and sets m_cbAllocated; may throw bad_alloc.
    140 #ifndef RT_EXCEPTIONS_ENABLED
    141             AssertRelease(capacity() > cchBoth);
    142 #endif
    143         }
    144 
    145         memcpy(&m_psz[cchThis], pszThat, cchThat);
     146        memcpy(&m_psz[cchThis], pszSrc, cchSrc);
    146147        m_psz[cchBoth] = '\0';
    147148        m_cch = cchBoth;
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