VirtualBox

Ignore:
Timestamp:
Jun 27, 2017 5:11:00 PM (7 years ago)
Author:
vboxsync
Message:

IPRT: Added strip, stripLeft, and stripRight to RTCString.

File:
1 edited

Legend:

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

    r67650 r67651  
    3333*********************************************************************************************************************************/
    3434#include <iprt/cpp/ministring.h>
     35#include <iprt/ctype.h>
    3536
    3637
     
    282283#endif
    283284
     285
     286RTCString &RTCString::strip()
     287{
     288    stripRight();
     289    return stripLeft();
     290}
     291
     292
     293RTCString &RTCString::stripLeft()
     294{
     295    char        *psz = m_psz;
     296    size_t const cch = m_cch;
     297    size_t       off = 0;
     298    while (off < cch && RT_C_IS_SPACE(psz[off]))
     299        off++;
     300    if (off > 0)
     301    {
     302        if (off != cch)
     303        {
     304            memmove(psz, &psz[off], cch - off + 1);
     305            m_cch = cch - off;
     306        }
     307        else
     308            setNull();
     309    }
     310    return *this;
     311}
     312
     313
     314RTCString &RTCString::stripRight()
     315{
     316    char  *psz = m_psz;
     317    size_t cch = m_cch;
     318    while (cch > 0 && RT_C_IS_SPACE(psz[cch - 1]))
     319        cch--;
     320    if (m_cch != cch)
     321    {
     322        m_cch = cch;
     323        psz[cch] = '\0';
     324    }
     325    return *this;
     326}
     327
     328
     329
    284330RTCString RTCString::substrCP(size_t pos /*= 0*/, size_t n /*= npos*/) const
    285331{
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