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()
This commit is contained in:
parent
f397a73138
commit
a19b50ddf2
5 changed files with 259 additions and 27 deletions
|
@ -270,5 +270,26 @@ T gcd(T a, T b) {
|
|||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Replacement algorithm for iterables.
|
||||
*
|
||||
* Replaces all occurrences of "original" in [begin, end) with occurrences of "replaced".
|
||||
*
|
||||
* @param[in, out] begin: First element to be examined.
|
||||
* @param[in] end: Last element in the seubsection. Not examined.
|
||||
* @param[in] original: Elements to be replaced.
|
||||
* @param[in] replaced: Element to replace occurrences of "original".
|
||||
*
|
||||
* @note Usage examples and unit tests may be found in "test/common/algorithm.h"
|
||||
*/
|
||||
template<class It, class Dat>
|
||||
void replace(It begin, It end, const Dat &original, const Dat &replaced) {
|
||||
for (; begin != end; ++begin) {
|
||||
if (*begin == original) {
|
||||
*begin = replaced;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Common
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue