VirtualBox

Changeset 68094 in vbox


Ignore:
Timestamp:
Jul 24, 2017 12:44:02 PM (7 years ago)
Author:
vboxsync
Message:

RTCString: Added startsWithWord method.

Location:
trunk
Files:
2 edited

Legend:

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

    r67690 r68094  
    927927     */
    928928    bool startsWith(const RTCString &that, CaseSensitivity cs = CaseSensitive) const;
     929
     930    /**
     931     * Checks if the string starts with the given word, ignoring leading blanks.
     932     *
     933     * @param   pszWord The word to test for.
     934     * @param   enmCase Case sensitivity selector.
     935     * @returns true if match, false if mismatch.
     936     */
     937    bool startsWithWord(const char *pszWord, CaseSensitivity enmCase = CaseSensitive) const;
     938
     939    /**
     940     * Checks if the string starts with the given word, ignoring leading blanks.
     941     *
     942     * @param   rThat   Prefix to test for.
     943     * @param   enmCase Case sensitivity selector.
     944     * @returns true if match, false if mismatch.
     945     */
     946    bool startsWithWord(const RTCString &rThat, CaseSensitivity enmCase = CaseSensitive) const;
    929947
    930948    /**
  • trunk/src/VBox/Runtime/common/string/ministring.cpp

    r67688 r68094  
    3434#include <iprt/cpp/ministring.h>
    3535#include <iprt/ctype.h>
     36#include <iprt/uni.h>
    3637
    3738
     
    488489}
    489490
     491bool RTCString::startsWithWord(const char *pszWord, CaseSensitivity enmCase /*= CaseSensitive*/) const
     492{
     493    const char *pszSrc  = RTStrStripL(c_str()); /** @todo RTStrStripL doesn't use RTUniCpIsSpace (nbsp) */
     494    size_t      cchWord = strlen(pszWord);
     495    if (  enmCase == CaseSensitive
     496        ? RTStrNCmp(pszSrc, pszWord, cchWord) == 0
     497        : RTStrNICmp(pszSrc, pszWord, cchWord) == 0)
     498    {
     499        if (   pszSrc[cchWord] == '\0'
     500            || RT_C_IS_SPACE(pszSrc[cchWord])
     501            || RT_C_IS_PUNCT(pszSrc[cchWord]) )
     502            return true;
     503        RTUNICP uc = RTStrGetCp(&pszSrc[cchWord]);
     504        if (RTUniCpIsSpace(uc))
     505            return true;
     506    }
     507    return false;
     508}
     509
     510bool RTCString::startsWithWord(const RTCString &rThat, CaseSensitivity enmCase /*= CaseSensitive*/) const
     511{
     512    return startsWithWord(rThat.c_str(), enmCase);
     513}
     514
    490515bool RTCString::contains(const RTCString &that, CaseSensitivity cs /*= CaseSensitive*/) const
    491516{
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