VirtualBox

Changeset 73908 in vbox for trunk


Ignore:
Timestamp:
Aug 27, 2018 10:15:30 AM (6 years ago)
Author:
vboxsync
Message:

iprt/cpp/ministring.h: Added appendPrintf with all variants. Marked a lot of methods with noexcept.

Location:
trunk
Files:
2 edited

Legend:

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

    r73907 r73908  
    586586
    587587    /**
     588     * Appends the output of the string format operation (RTStrPrintf).
     589     *
     590     * @param   pszFormat       Pointer to the format string,
     591     *                          @see pg_rt_str_format.
     592     * @param   ...             Ellipsis containing the arguments specified by
     593     *                          the format string.
     594     *
     595     * @throws  std::bad_alloc  On allocation error.  The object is left unchanged.
     596     *
     597     * @returns Reference to the object.
     598     */
     599    RTCString &appendPrintf(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
     600
     601    /**
     602     * Appends the output of the string format operation (RTStrPrintf).
     603     *
     604     * @param   pszFormat       Pointer to the format string,
     605     *                          @see pg_rt_str_format.
     606     * @param   ...             Ellipsis containing the arguments specified by
     607     *                          the format string.
     608     *
     609     * @returns VINF_SUCCESS or VERR_NO_STRING_MEMORY.
     610     */
     611    int appendPrintfNoThrow(const char *pszFormat, ...) RT_NOEXCEPT RT_IPRT_FORMAT_ATTR(1, 2);
     612
     613    /**
     614     * Appends the output of the string format operation (RTStrPrintfV).
     615     *
     616     * @param   pszFormat       Pointer to the format string,
     617     *                          @see pg_rt_str_format.
     618     * @param   va              Argument vector containing the arguments
     619     *                          specified by the format string.
     620     *
     621     * @throws  std::bad_alloc  On allocation error.  The object is left unchanged.
     622     *
     623     * @returns Reference to the object.
     624     */
     625    RTCString &appendPrintfV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
     626
     627    /**
     628     * Assigns the output of the string format operation (RTStrPrintfV).
     629     *
     630     * @param   pszFormat       Pointer to the format string,
     631     *                          @see pg_rt_str_format.
     632     * @param   va              Argument vector containing the arguments
     633     *                          specified by the format string.
     634     *
     635     * @returns VINF_SUCCESS or VERR_NO_STRING_MEMORY.
     636     */
     637    int appendPrintfVNoThrow(const char *pszFormat, va_list va) RT_NOEXCEPT RT_IPRT_FORMAT_ATTR(1, 0);
     638
     639    /**
    588640     * Shortcut to append(), RTCString variant.
    589641     *
     
    624676     * @returns Reference to the object.
    625677     */
    626     RTCString &toUpper()
     678    RTCString &toUpper() RT_NOEXCEPT
    627679    {
    628680        if (length())
     
    643695     * @returns Reference to the object.
    644696     */
    645     RTCString &toLower()
     697    RTCString &toLower() RT_NOEXCEPT
    646698    {
    647699        if (length())
     
    664716     * @param   cchLength       How much following @a offStart to erase.
    665717     */
    666     RTCString &erase(size_t offStart = 0, size_t cchLength = npos);
     718    RTCString &erase(size_t offStart = 0, size_t cchLength = npos) RT_NOEXCEPT;
    667719
    668720    /**
     
    800852     * @returns char at the index or null.
    801853     */
    802     inline char operator[](size_t i) const
     854    inline char operator[](size_t i) const RT_NOEXCEPT
    803855    {
    804856        if (i < length())
     
    815867     * @returns const pointer to C-style string.
    816868     */
    817     inline const char *c_str() const
     869    inline const char *c_str() const RT_NOEXCEPT
    818870    {
    819871        return (m_psz) ? m_psz : "";
     
    832884     *         may go nowhere.  Better not use mutableRaw() at all.
    833885     */
    834     char *mutableRaw()
     886    char *mutableRaw() RT_NOEXCEPT
    835887    {
    836888        return m_psz;
     
    845897     * nowhere.
    846898     */
    847     void jolt()
     899    void jolt() RT_NOEXCEPT
    848900    {
    849901        if (m_psz)
     
    869921     * @returns @c true if empty, @c false if not.
    870922     */
    871     bool isEmpty() const
     923    bool isEmpty() const RT_NOEXCEPT
    872924    {
    873925        return length() == 0;
     
    884936     * @returns @c false if empty, @c true if not.
    885937     */
    886     bool isNotEmpty() const
     938    bool isNotEmpty() const RT_NOEXCEPT
    887939    {
    888940        return length() != 0;
     
    904956     *          if larger.
    905957     */
    906     int compare(const char *pcszThat, CaseSensitivity cs = CaseSensitive) const
     958    int compare(const char *pcszThat, CaseSensitivity cs = CaseSensitive) const RT_NOEXCEPT
    907959    {
    908960        /* This klugde is for m_cch=0 and m_psz=NULL.  pcsz=NULL and psz=""
     
    924976     *          if larger.
    925977     */
    926     int compare(const RTCString &rThat, CaseSensitivity cs = CaseSensitive) const
     978    int compare(const RTCString &rThat, CaseSensitivity cs = CaseSensitive) const RT_NOEXCEPT
    927979    {
    928980        if (cs == CaseSensitive)
     
    937989     * @param   rThat    The string to compare with.
    938990     */
    939     bool equals(const RTCString &rThat) const
     991    bool equals(const RTCString &rThat) const RT_NOEXCEPT
    940992    {
    941993        return rThat.length() == length()
     
    9501002     * @param   pszThat The string to compare with.
    9511003     */
    952     bool equals(const char *pszThat) const
     1004    bool equals(const char *pszThat) const RT_NOEXCEPT
    9531005    {
    9541006        /* This klugde is for m_cch=0 and m_psz=NULL.  pcsz=NULL and psz=""
     
    9651017     * @param   that    The string to compare with.
    9661018     */
    967     bool equalsIgnoreCase(const RTCString &that) const
     1019    bool equalsIgnoreCase(const RTCString &that) const RT_NOEXCEPT
    9681020    {
    9691021        /* Unfolded upper and lower case characters may require different
     
    9781030     * @param   pszThat The string to compare with.
    9791031     */
    980     bool equalsIgnoreCase(const char *pszThat) const
     1032    bool equalsIgnoreCase(const char *pszThat) const RT_NOEXCEPT
    9811033    {
    9821034        /* This klugde is for m_cch=0 and m_psz=NULL.  pcsz=NULL and psz=""
     
    10201072     * @returns 0 based position of pszNeedle. npos if not found.
    10211073     */
    1022     size_t find(const char *pszNeedle, size_t offStart = 0) const;
     1074    size_t find(const char *pszNeedle, size_t offStart = 0) const RT_NOEXCEPT;
    10231075
    10241076    /**
     
    10361088     *          NULL or an empty string.
    10371089     */
    1038     size_t find(const RTCString *pStrNeedle, size_t offStart = 0) const;
     1090    size_t find(const RTCString *pStrNeedle, size_t offStart = 0) const RT_NOEXCEPT;
    10391091
    10401092    /**
     
    10461098     * @param   chReplace   Character to replace cFind with. Must be ASCII < 128.
    10471099     */
    1048     void findReplace(char chFind, char chReplace);
     1100    void findReplace(char chFind, char chReplace) RT_NOEXCEPT;
    10491101
    10501102    /**
     
    10541106     * @remarks QString::count
    10551107     */
    1056     size_t count(char ch) const;
     1108    size_t count(char ch) const RT_NOEXCEPT;
    10571109
    10581110    /**
     
    10631115     * @remarks QString::count
    10641116     */
    1065     size_t count(const char *psz, CaseSensitivity cs = CaseSensitive) const;
     1117    size_t count(const char *psz, CaseSensitivity cs = CaseSensitive) const RT_NOEXCEPT;
    10661118
    10671119    /**
     
    10721124     * @remarks QString::count
    10731125     */
    1074     size_t count(const RTCString *pStr, CaseSensitivity cs = CaseSensitive) const;
     1126    size_t count(const RTCString *pStr, CaseSensitivity cs = CaseSensitive) const RT_NOEXCEPT;
    10751127
    10761128    /**
     
    10791131     * @returns this
    10801132     */
    1081     RTCString &strip();
     1133    RTCString &strip() RT_NOEXCEPT;
    10821134
    10831135    /**
     
    10861138     * @returns this
    10871139     */
    1088     RTCString &stripLeft();
     1140    RTCString &stripLeft() RT_NOEXCEPT;
    10891141
    10901142    /**
     
    10931145     * @returns this
    10941146     */
    1095     RTCString &stripRight();
     1147    RTCString &stripRight() RT_NOEXCEPT;
    10961148
    10971149    /**
     
    11351187     * @returns true if match, false if mismatch.
    11361188     */
    1137     bool endsWith(const RTCString &that, CaseSensitivity cs = CaseSensitive) const;
     1189    bool endsWith(const RTCString &that, CaseSensitivity cs = CaseSensitive) const RT_NOEXCEPT;
    11381190
    11391191    /**
     
    11431195     * @returns true if match, false if mismatch.
    11441196     */
    1145     bool startsWith(const RTCString &that, CaseSensitivity cs = CaseSensitive) const;
     1197    bool startsWith(const RTCString &that, CaseSensitivity cs = CaseSensitive) const RT_NOEXCEPT;
    11461198
    11471199    /**
     
    11521204     * @returns true if match, false if mismatch.
    11531205     */
    1154     bool startsWithWord(const char *pszWord, CaseSensitivity enmCase = CaseSensitive) const;
     1206    bool startsWithWord(const char *pszWord, CaseSensitivity enmCase = CaseSensitive) const RT_NOEXCEPT;
    11551207
    11561208    /**
     
    11611213     * @returns true if match, false if mismatch.
    11621214     */
    1163     bool startsWithWord(const RTCString &rThat, CaseSensitivity enmCase = CaseSensitive) const;
     1215    bool startsWithWord(const RTCString &rThat, CaseSensitivity enmCase = CaseSensitive) const RT_NOEXCEPT;
    11641216
    11651217    /**
     
    11701222     * @returns true if found, false if not found.
    11711223     */
    1172     bool contains(const RTCString &that, CaseSensitivity cs = CaseSensitive) const;
     1224    bool contains(const RTCString &that, CaseSensitivity cs = CaseSensitive) const RT_NOEXCEPT;
    11731225
    11741226    /**
     
    11791231     * @returns true if found, false if not found.
    11801232     */
    1181     bool contains(const char *pszNeedle, CaseSensitivity cs = CaseSensitive) const;
     1233    bool contains(const char *pszNeedle, CaseSensitivity cs = CaseSensitive) const RT_NOEXCEPT;
    11821234
    11831235    /**
     
    11871239     * @returns 0 on failure.
    11881240     */
    1189     int32_t toInt32() const
     1241    int32_t toInt32() const RT_NOEXCEPT
    11901242    {
    11911243        return RTStrToInt32(c_str());
     
    11981250     * @returns 0 on failure.
    11991251     */
    1200     uint32_t toUInt32() const
     1252    uint32_t toUInt32() const RT_NOEXCEPT
    12011253    {
    12021254        return RTStrToUInt32(c_str());
     
    12091261     * @returns 0 on failure.
    12101262     */
    1211     int64_t toInt64() const
     1263    int64_t toInt64() const RT_NOEXCEPT
    12121264    {
    12131265        return RTStrToInt64(c_str());
     
    12201272     * @returns 0 on failure.
    12211273     */
    1222     uint64_t toUInt64() const
     1274    uint64_t toUInt64() const RT_NOEXCEPT
    12231275    {
    12241276        return RTStrToUInt64(c_str());
     
    12311283     * @returns IPRT error code, see RTStrToInt64.
    12321284     */
    1233     int toInt(uint64_t &i) const;
     1285    int toInt(uint64_t &i) const RT_NOEXCEPT;
    12341286
    12351287    /**
     
    12391291     * @returns IPRT error code, see RTStrToInt32.
    12401292     */
    1241     int toInt(uint32_t &i) const;
     1293    int toInt(uint32_t &i) const RT_NOEXCEPT;
    12421294
    12431295    /** Splitting behavior regarding empty sections in the string. */
     
    12541306     * @param   a_enmMode   How should empty parts be handled.
    12551307     * @returns separated strings as string list.
     1308     * @throws  std::bad_alloc  On allocation error.
    12561309     */
    12571310    RTCList<RTCString, RTCString *> split(const RTCString &a_rstrSep,
     
    12661319     * @param   a_rstrSep       The separator used for joining.
    12671320     * @returns joined string.
     1321     * @throws  std::bad_alloc  On allocation error.
    12681322     */
    12691323    static RTCString joinEx(const RTCList<RTCString, RTCString *> &a_rList,
     
    12771331     * @param   a_rstrSep   The separator used for joining.
    12781332     * @returns joined string.
     1333     * @throws  std::bad_alloc  On allocation error.
    12791334     */
    12801335    static RTCString join(const RTCList<RTCString, RTCString *> &a_rList,
     
    12881343     * @param   a_rThat  The string to swap with.
    12891344     */
    1290     inline void swap(RTCString &a_rThat) throw()
     1345    inline void swap(RTCString &a_rThat) RT_NOEXCEPT
    12911346    {
    12921347        char   *pszTmp         = m_psz;
     
    13141369     * assigning a new string.
    13151370     */
    1316     void cleanup()
     1371    void cleanup() RT_NOEXCEPT
    13171372    {
    13181373        if (m_psz)
  • trunk/src/VBox/Runtime/common/string/ministring.cpp

    r73907 r73908  
    283283}
    284284
     285RTCString &RTCString::appendPrintfV(const char *pszFormat, va_list va)
     286{
     287    RTStrFormatV(printfOutputCallback, this, NULL, NULL, pszFormat, va);
     288    return *this;
     289}
     290
    285291struct RTCSTRINGOTHROW
    286292{
     
    338344}
    339345
     346int RTCString::appendPrintfVNoThrow(const char *pszFormat, va_list va) RT_NOEXCEPT
     347{
     348    RTCSTRINGOTHROW Args = { this, VINF_SUCCESS };
     349    RTStrFormatV(printfOutputCallback, &Args, NULL, NULL, pszFormat, va);
     350    return Args.rc;
     351}
     352
     353RTCString &RTCString::appendPrintf(const char *pszFormat, ...)
     354{
     355    va_list va;
     356    va_start(va, pszFormat);
     357    appendPrintfV(pszFormat, va);
     358    va_end(va);
     359    return *this;
     360}
     361
     362int RTCString::appendPrintfNoThrow(const char *pszFormat, ...) RT_NOEXCEPT
     363{
     364    va_list va;
     365    va_start(va, pszFormat);
     366    int rc = appendPrintfVNoThrow(pszFormat, va);
     367    va_end(va);
     368    return rc;
     369}
     370
    340371RTCString &RTCString::append(const RTCString &that)
    341372{
     
    538569}
    539570
    540 
    541 RTCString &RTCString::erase(size_t offStart /*= 0*/, size_t cchLength /*= npos*/)
     571RTCString &RTCString::erase(size_t offStart /*= 0*/, size_t cchLength /*= npos*/) RT_NOEXCEPT
    542572{
    543573    size_t cch = length();
     
    592622
    593623int RTCString::replaceNoThrow(size_t offStart, size_t cchLength, const RTCString &rStrReplacement,
    594                               size_t offReplacement, size_t cchReplacement)
     624                              size_t offReplacement, size_t cchReplacement) RT_NOEXCEPT
    595625{
    596626    Assert(this != &rStrReplacement);
     
    713743
    714744
    715 size_t RTCString::find(const char *pszNeedle, size_t offStart /*= 0*/) const
     745size_t RTCString::find(const char *pszNeedle, size_t offStart /*= 0*/) const RT_NOEXCEPT
    716746{
    717747    if (offStart < length())
     
    732762}
    733763
    734 size_t RTCString::find(const RTCString *pStrNeedle, size_t offStart /*= 0*/) const
     764size_t RTCString::find(const RTCString *pStrNeedle, size_t offStart /*= 0*/) const RT_NOEXCEPT
    735765{
    736766    if (offStart < length())
     
    755785}
    756786
    757 void RTCString::findReplace(char chFind, char chReplace)
     787void RTCString::findReplace(char chFind, char chReplace) RT_NOEXCEPT
    758788{
    759789    Assert((unsigned int)chFind    < 128U);
     
    768798}
    769799
    770 size_t RTCString::count(char ch) const
     800size_t RTCString::count(char ch) const RT_NOEXCEPT
    771801{
    772802    Assert((unsigned int)ch < 128U);
     
    785815
    786816#if 0  /** @todo implement these when needed. */
    787 size_t RTCString::count(const char *psz, CaseSensitivity cs = CaseSensitive) const
    788 {
    789 }
    790 
    791 size_t RTCString::count(const RTCString *pStr, CaseSensitivity cs = CaseSensitive) const
     817size_t RTCString::count(const char *psz, CaseSensitivity cs = CaseSensitive) const RT_NOEXCEPT
     818{
     819}
     820
     821size_t RTCString::count(const RTCString *pStr, CaseSensitivity cs = CaseSensitive) const RT_NOEXCEPT
    792822{
    793823
     
    796826
    797827
    798 RTCString &RTCString::strip()
     828RTCString &RTCString::strip() RT_NOEXCEPT
    799829{
    800830    stripRight();
     
    803833
    804834
    805 RTCString &RTCString::stripLeft()
     835RTCString &RTCString::stripLeft() RT_NOEXCEPT
    806836{
    807837    char        *psz = m_psz;
     
    824854
    825855
    826 RTCString &RTCString::stripRight()
     856RTCString &RTCString::stripRight() RT_NOEXCEPT
    827857{
    828858    char  *psz = m_psz;
     
    888918}
    889919
    890 bool RTCString::endsWith(const RTCString &that, CaseSensitivity cs /*= CaseSensitive*/) const
     920bool RTCString::endsWith(const RTCString &that, CaseSensitivity cs /*= CaseSensitive*/) const RT_NOEXCEPT
    891921{
    892922    size_t l1 = length();
     
    906936}
    907937
    908 bool RTCString::startsWith(const RTCString &that, CaseSensitivity cs /*= CaseSensitive*/) const
     938bool RTCString::startsWith(const RTCString &that, CaseSensitivity cs /*= CaseSensitive*/) const RT_NOEXCEPT
    909939{
    910940    size_t l1 = length();
     
    921951}
    922952
    923 bool RTCString::startsWithWord(const char *pszWord, CaseSensitivity enmCase /*= CaseSensitive*/) const
     953bool RTCString::startsWithWord(const char *pszWord, CaseSensitivity enmCase /*= CaseSensitive*/) const RT_NOEXCEPT
    924954{
    925955    const char *pszSrc  = RTStrStripL(c_str()); /** @todo RTStrStripL doesn't use RTUniCpIsSpace (nbsp) */
     
    940970}
    941971
    942 bool RTCString::startsWithWord(const RTCString &rThat, CaseSensitivity enmCase /*= CaseSensitive*/) const
     972bool RTCString::startsWithWord(const RTCString &rThat, CaseSensitivity enmCase /*= CaseSensitive*/) const RT_NOEXCEPT
    943973{
    944974    return startsWithWord(rThat.c_str(), enmCase);
    945975}
    946976
    947 bool RTCString::contains(const RTCString &that, CaseSensitivity cs /*= CaseSensitive*/) const
     977bool RTCString::contains(const RTCString &that, CaseSensitivity cs /*= CaseSensitive*/) const RT_NOEXCEPT
    948978{
    949979    /** @todo r-bird: Not checking for NULL strings like startsWith does (and
     
    954984}
    955985
    956 bool RTCString::contains(const char *pszNeedle, CaseSensitivity cs /*= CaseSensitive*/) const
     986bool RTCString::contains(const char *pszNeedle, CaseSensitivity cs /*= CaseSensitive*/) const RT_NOEXCEPT
    957987{
    958988    /** @todo r-bird: Not checking for NULL strings like startsWith does (and
     
    963993}
    964994
    965 int RTCString::toInt(uint64_t &i) const
     995int RTCString::toInt(uint64_t &i) const RT_NOEXCEPT
    966996{
    967997    if (!m_psz)
     
    9701000}
    9711001
    972 int RTCString::toInt(uint32_t &i) const
     1002int RTCString::toInt(uint32_t &i) const RT_NOEXCEPT
    9731003{
    9741004    if (!m_psz)
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