VirtualBox

Changeset 73907 in vbox for trunk/include/iprt/cpp


Ignore:
Timestamp:
Aug 27, 2018 9:54:04 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124626
Message:

iprt/cpp/ministring.h: Added a much of NoThrow variants of the assign, append and replace methods, returning an IPRT status code instead of throwing stuff.

File:
1 edited

Legend:

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

    r69105 r73907  
    264264     * @param   cb              New minimum size (in bytes) of member memory buffer.
    265265     */
    266     int reserveNoThrow(size_t cb)
     266    int reserveNoThrow(size_t cb) RT_NOEXCEPT
    267267    {
    268268        if (    cb != m_cbAllocated
     
    338338
    339339    /**
     340     * Assigns a copy of another RTCString.
     341     *
     342     * @param   a_rSrc          Reference to the source string.
     343     * @returns VINF_SUCCESS or VERR_NO_STRING_MEMORY.
     344     */
     345    int assignNoThrow(const RTCString &a_rSrc) RT_NOEXCEPT;
     346
     347    /**
    340348     * Assigns a copy of a C-style string.
    341349     *
     
    345353     */
    346354    RTCString &assign(const char *a_pszSrc);
     355
     356    /**
     357     * Assigns a copy of a C-style string.
     358     *
     359     * @param   a_pszSrc        Pointer to the C-style source string.
     360     * @returns VINF_SUCCESS or VERR_NO_STRING_MEMORY.
     361     * @remarks ASSUMES valid
     362     */
     363    int assignNoThrow(const char *a_pszSrc) RT_NOEXCEPT;
    347364
    348365    /**
     
    353370     * @param   a_cchSrc        The max number of chars (encoded UTF-8 bytes)
    354371     *                          to copy from the source string.
     372     * @throws  std::bad_alloc  On allocation error.  The object is left unchanged.
    355373     */
    356374    RTCString &assign(const RTCString &a_rSrc, size_t a_offSrc, size_t a_cchSrc = npos);
     375
     376    /**
     377     * Assigns a partial copy of another RTCString.
     378     *
     379     * @param   a_rSrc          The source string.
     380     * @param   a_offSrc        The byte offset into the source string.
     381     * @param   a_cchSrc        The max number of chars (encoded UTF-8 bytes)
     382     *                          to copy from the source string.
     383     * @returns VINF_SUCCESS or VERR_NO_STRING_MEMORY.
     384     */
     385    int assignNoThrow(const RTCString &a_rSrc, size_t a_offSrc, size_t a_cchSrc = npos) RT_NOEXCEPT;
    357386
    358387    /**
     
    362391     * @param   a_cchSrc        The max number of chars (encoded UTF-8 bytes)
    363392     *                          to copy from the source string.
     393     * @throws  std::bad_alloc  On allocation error.  The object is left unchanged.
    364394     */
    365395    RTCString &assign(const char *a_pszSrc, size_t a_cchSrc);
     396
     397    /**
     398     * Assigns a partial copy of a C-style string.
     399     *
     400     * @param   a_pszSrc        The source string (UTF-8).
     401     * @param   a_cchSrc        The max number of chars (encoded UTF-8 bytes)
     402     *                          to copy from the source string.
     403     * @returns VINF_SUCCESS or VERR_NO_STRING_MEMORY.
     404     */
     405    int assignNoThrow(const char *a_pszSrc, size_t a_cchSrc) RT_NOEXCEPT;
    366406
    367407    /**
     
    370410     * @param   a_cTimes        The number of times the character is repeated.
    371411     * @param   a_ch            The character to fill the string with.
     412     * @throws  std::bad_alloc  On allocation error.  The object is left unchanged.
    372413     */
    373414    RTCString &assign(size_t a_cTimes, char a_ch);
     415
     416    /**
     417     * Assigs a string containing @a a_cTimes repetitions of the character @a a_ch.
     418     *
     419     * @param   a_cTimes        The number of times the character is repeated.
     420     * @param   a_ch            The character to fill the string with.
     421     * @returns VINF_SUCCESS or VERR_NO_STRING_MEMORY.
     422     */
     423    int assignNoThrow(size_t a_cTimes, char a_ch) RT_NOEXCEPT;
    374424
    375425    /**
     
    388438
    389439    /**
     440     * Assigns the output of the string format operation (RTStrPrintf).
     441     *
     442     * @param   pszFormat       Pointer to the format string,
     443     *                          @see pg_rt_str_format.
     444     * @param   ...             Ellipsis containing the arguments specified by
     445     *                          the format string.
     446     *
     447     * @returns VINF_SUCCESS or VERR_NO_STRING_MEMORY.
     448     */
     449    int printfNoThrow(const char *pszFormat, ...) RT_NOEXCEPT RT_IPRT_FORMAT_ATTR(1, 2);
     450
     451    /**
    390452     * Assigns the output of the string format operation (RTStrPrintfV).
    391453     *
     
    402464
    403465    /**
     466     * Assigns the output of the string format operation (RTStrPrintfV).
     467     *
     468     * @param   pszFormat       Pointer to the format string,
     469     *                          @see pg_rt_str_format.
     470     * @param   va              Argument vector containing the arguments
     471     *                          specified by the format string.
     472     *
     473     * @returns VINF_SUCCESS or VERR_NO_STRING_MEMORY.
     474     */
     475    int printfVNoThrow(const char *pszFormat, va_list va) RT_NOEXCEPT RT_IPRT_FORMAT_ATTR(1, 0);
     476
     477    /**
    404478     * Appends the string @a that to @a rThat.
    405479     *
     
    411485
    412486    /**
     487     * Appends the string @a that to @a rThat.
     488     *
     489     * @param   rThat            The string to append.
     490     * @returns VINF_SUCCESS or VERR_NO_STRING_MEMORY.
     491     */
     492    int appendNoThrow(const RTCString &rThat) RT_NOEXCEPT;
     493
     494    /**
    413495     * Appends the string @a pszSrc to @a this.
    414496     *
     
    418500     */
    419501    RTCString &append(const char *pszSrc);
     502
     503    /**
     504     * Appends the string @a pszSrc to @a this.
     505     *
     506     * @param   pszSrc          The C-style string to append.
     507     * @returns VINF_SUCCESS or VERR_NO_STRING_MEMORY.
     508     */
     509    int appendNoThrow(const char *pszSrc) RT_NOEXCEPT;
    420510
    421511    /**
     
    432522
    433523    /**
     524     * Appends the a substring from @a rThat to @a this.
     525     *
     526     * @param   rThat           The string to append a substring from.
     527     * @param   offStart        The start of the substring to append (byte offset,
     528     *                          not codepoint).
     529     * @param   cchMax          The maximum number of bytes to append.
     530     * @returns VINF_SUCCESS or VERR_NO_STRING_MEMORY.
     531     */
     532    int appendNoThrow(const RTCString &rThat, size_t offStart, size_t cchMax = RTSTR_MAX) RT_NOEXCEPT;
     533
     534    /**
    434535     * Appends the first @a cchMax chars from string @a pszThat to @a this.
    435536     *
     
    442543
    443544    /**
     545     * Appends the first @a cchMax chars from string @a pszThat to @a this.
     546     *
     547     * @param   pszThat         The C-style string to append.
     548     * @param   cchMax          The maximum number of bytes to append.
     549     * @returns VINF_SUCCESS or VERR_NO_STRING_MEMORY.
     550     */
     551    int appendNoThrow(const char *pszThat, size_t cchMax) RT_NOEXCEPT;
     552
     553    /**
    444554     * Appends the given character to @a this.
    445555     *
     
    451561
    452562    /**
     563     * Appends the given character to @a this.
     564     *
     565     * @param   ch              The character to append.
     566     * @returns VINF_SUCCESS or VERR_NO_STRING_MEMORY.
     567     */
     568    int appendNoThrow(char ch) RT_NOEXCEPT;
     569
     570    /**
    453571     * Appends the given unicode code point to @a this.
    454572     *
     
    458576     */
    459577    RTCString &appendCodePoint(RTUNICP uc);
     578
     579    /**
     580     * Appends the given unicode code point to @a this.
     581     *
     582     * @param   uc              The unicode code point to append.
     583     * @returns VINF_SUCCESS, VERR_INVALID_UTF8_ENCODING or VERR_NO_STRING_MEMORY.
     584     */
     585    int appendCodePointNoThrow(RTUNICP uc) RT_NOEXCEPT;
    460586
    461587    /**
     
    557683
    558684    /**
     685     * Replaces a span of @a this string with a replacement string.
     686     *
     687     * @returns VINF_SUCCESS, VERR_OUT_OF_RANGE or VERR_NO_STRING_MEMORY.
     688     * @param   offStart        Where in @a this string to start replacing.
     689     * @param   cchLength       How much following @a offStart to replace.  npos is
     690     *                          accepted.
     691     * @param   rStrReplacement The replacement string.
     692     */
     693    int replaceNoThrow(size_t offStart, size_t cchLength, const RTCString &rStrReplacement) RT_NOEXCEPT;
     694
     695    /**
    559696     * Replaces a span of @a this string with a replacement substring.
    560697     *
     
    579716
    580717    /**
     718     * Replaces a span of @a this string with a replacement substring.
     719     *
     720     * @returns VINF_SUCCESS, VERR_OUT_OF_RANGE or VERR_NO_STRING_MEMORY.
     721     * @param   offStart        Where in @a this string to start replacing.
     722     * @param   cchLength       How much following @a offStart to replace.  npos is
     723     *                          accepted.
     724     * @param   rStrReplacement The string from which a substring is taken.
     725     * @param   offReplacement  The offset into @a rStrReplacement where the
     726     *                          replacement substring starts.
     727     * @param   cchReplacement   The maximum length of the replacement substring.
     728     */
     729    int replaceNoThrow(size_t offStart, size_t cchLength, const RTCString &rStrReplacement,
     730                       size_t offReplacement, size_t cchReplacement) RT_NOEXCEPT;
     731
     732    /**
    581733     * Replaces a span of @a this string with the replacement string.
    582734     *
     
    593745     */
    594746    RTCString &replace(size_t offStart, size_t cchLength, const char *pszReplacement);
     747
     748    /**
     749     * Replaces a span of @a this string with the replacement string.
     750     *
     751     * @returns VINF_SUCCESS, VERR_OUT_OF_RANGE or VERR_NO_STRING_MEMORY.
     752     * @param   offStart        Where in @a this string to start replacing.
     753     * @param   cchLength       How much following @a offStart to replace.  npos is
     754     *                          accepted.
     755     * @param   pszReplacement  The replacement string.
     756     */
     757    int replaceNoThrow(size_t offStart, size_t cchLength, const char *pszReplacement) RT_NOEXCEPT;
    595758
    596759    /**
     
    612775     */
    613776    RTCString &replace(size_t offStart, size_t cchLength, const char *pszReplacement, size_t cchReplacement);
     777
     778    /**
     779     * Replaces a span of @a this string with the replacement string.
     780     *
     781     * @returns VINF_SUCCESS, VERR_OUT_OF_RANGE or VERR_NO_STRING_MEMORY.
     782     * @param   offStart        Where in @a this string to start replacing.
     783     * @param   cchLength       How much following @a offStart to replace.  npos is
     784     *                          accepted.
     785     * @param   pszReplacement  The replacement string.
     786     * @param   cchReplacement  How much of @a pszReplacement to use at most.  If a
     787     *                          zero terminator is found before reaching this value,
     788     *                          we'll stop there.
     789     */
     790    int replaceNoThrow(size_t offStart, size_t cchLength, const char *pszReplacement, size_t cchReplacement) RT_NOEXCEPT;
    614791
    615792    /**
     
    12081385
    12091386    /**
     1387     * Appends exactly @a cchSrc chars from @a pszSrc to @a this.
     1388     *
     1389     * This is an internal worker for the appendNoThrow() methods.
     1390     *
     1391     * @returns VINF_SUCCESS or VERR_NO_STRING_MEMORY.
     1392     * @param   pszSrc          The source string.
     1393     * @param   cchSrc          The source string length (exact).
     1394     */
     1395    int appendWorkerNoThrow(const char *pszSrc, size_t cchSrc) RT_NOEXCEPT;
     1396
     1397    /**
    12101398     * Replaces exatly @a cchLength chars at @a offStart with @a cchSrc from @a
    12111399     * pszSrc.
     
    12221410    RTCString &replaceWorker(size_t offStart, size_t cchLength, const char *pszSrc, size_t cchSrc);
    12231411
     1412    /**
     1413     * Replaces exatly @a cchLength chars at @a offStart with @a cchSrc from @a
     1414     * pszSrc.
     1415     *
     1416     * @returns VINF_SUCCESS, VERR_OUT_OF_RANGE or VERR_NO_STRING_MEMORY.
     1417     * @param   offStart        Where in @a this string to start replacing.
     1418     * @param   cchLength       How much following @a offStart to replace.  npos is
     1419     *                          accepted.
     1420     * @param   pszSrc          The replacement string.
     1421     * @param   cchSrc          The exactly length of the replacement string.
     1422     */
     1423    int replaceWorkerNoThrow(size_t offStart, size_t cchLength, const char *pszSrc, size_t cchSrc) RT_NOEXCEPT;
     1424
    12241425    static DECLCALLBACK(size_t) printfOutputCallback(void *pvArg, const char *pachChars, size_t cbChars);
     1426    static DECLCALLBACK(size_t) printfOutputCallbackNoThrow(void *pvArg, const char *pachChars, size_t cbChars) RT_NOEXCEPT;
    12251427
    12261428    char   *m_psz;                      /**< The string buffer. */
Note: See TracChangeset for help on using the changeset viewer.

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