diff options
author | Borja Lorente Escobar | 2016-03-02 17:07:50 +0100 |
---|---|---|
committer | Borja Lorente | 2016-05-16 22:01:21 +0200 |
commit | a19b50ddf26ac4e36b3e86f781ef7c2ae5fc69fd (patch) | |
tree | 09d1e0bd96a74f17b8928676b233a52fa9831f46 /common/str.h | |
parent | f397a7313810f2538a7474aa1f7040252617a2ba (diff) | |
download | scummvm-rg350-a19b50ddf26ac4e36b3e86f781ef7c2ae5fc69fd.tar.gz scummvm-rg350-a19b50ddf26ac4e36b3e86f781ef7c2ae5fc69fd.tar.bz2 scummvm-rg350-a19b50ddf26ac4e36b3e86f781ef7c2ae5fc69fd.zip |
COMMON: Add replace functions to Common and String.
COMMON: Add replacement to common/algorithm.h
COMMON: Intermediate commit to show doubts.
COMMON: Basic String::replace() methods implemented.
COMMON: Fix typo in the algorithm.h documentation.
COMMON: Fix documentation of String::replace()
COMMON: Fix formatting issues in method signatures.
COMMON: Add assert and reformat loops in str and algorithm.
COMMON: Fix typo in comment.
COMMON: Fix style in string test cases.
COMMON: Add Doxygen documentation to algorithm and String.
COMMON: Add Doxygen documentation to algorithm and String.
COMMON: Add Doxygen documentation to algorithm.
COMMON: Fix style in algorithm comments.
COMMON: Add Doxygen comments to String.
COMMON: Add Doxygen comments to algorithm test function.
COMMON: Add String support for substring replace.
COMMON: Fix string replace to comply with STL
COMMON: Fix documentation on string replace
COMMON: Fix style in string replace
COMMON: Fix unwanted reference problem in String::replace().
COMMON: Fix indentation in comments for replace
COMMON: Fix indentation in replace
COMMON: Fix comments in String::replace to match implementation.
COMMON: Remove assert to allow for not-null-terminated character arrays
COMMON: Add new test for String::replace
COMMON: Fix broken comments on String::replace
COMMON: Fix sharing bug on ensureCapacity
COMMON: Remove superfluous call to makeUnique()
Diffstat (limited to 'common/str.h')
-rw-r--r-- | common/str.h | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/common/str.h b/common/str.h index 1b41c481c7..9ada8aaaa0 100644 --- a/common/str.h +++ b/common/str.h @@ -46,6 +46,17 @@ namespace Common { class String { public: static const uint32 npos = 0xFFFFFFFF; + + typedef char value_type; + /** + * Unsigned version of the underlying type. This can be used to cast + * individual string characters to bigger integer types without sign + * extension happening. + */ + typedef unsigned char unsigned_type; + typedef char * iterator; + typedef const char * const_iterator; + protected: /** * The size of the internal storage. Increasing this means less heap @@ -222,6 +233,38 @@ public: void trim(); uint hash() const; + + /**@{ + * Functions to replace some amount of chars with chars from some other string. + * + * @note The implementation follows that of the STL's std::string: + * http://www.cplusplus.com/reference/string/string/replace/ + * + * @param pos Starting position for the replace in the original string. + * @param count Number of chars to replace from the original string. + * @param str Source of the new chars. + * @param posOri Same as pos + * @param countOri Same as count + * @param posDest Initial position to read str from. + * @param countDest Number of chars to read from str. npos by default. + */ + // Replace 'count' bytes, starting from 'pos' with str. + void replace(uint32 pos, uint32 count, const String &str); + // The same as above, but accepts a C-like array of characters. + void replace(uint32 pos, uint32 count, const char *str); + // Replace the characters in [begin, end) with str._str. + void replace(iterator begin, iterator end, const String &str); + // Replace the characters in [begin, end) with str. + void replace(iterator begin, iterator end, const char *str); + // Replace _str[posOri, posOri + countOri) with + // str._str[posDest, posDest + countDest) + void replace(uint32 posOri, uint32 countOri, const String &str, + uint32 posDest, uint32 countDest); + // Replace _str[posOri, posOri + countOri) with + // str[posDest, posDest + countDest) + void replace(uint32 posOri, uint32 countOri, const char *str, + uint32 posDest, uint32 countDest); + /**@}*/ /** * Print formatted data into a String object. Similar to sprintf, @@ -238,15 +281,6 @@ public: static String vformat(const char *fmt, va_list args); public: - typedef char value_type; - /** - * Unsigned version of the underlying type. This can be used to cast - * individual string characters to bigger integer types without sign - * extension happening. - */ - typedef unsigned char unsigned_type; - typedef char * iterator; - typedef const char * const_iterator; iterator begin() { // Since the user could potentially |