General Utility Library for C++17 25.4.1
Functions
gul17/replace.h

Detailed Description

Replacing all occurrences of a string within another string.

Functions

GUL_EXPORT std::string gul17::replace (std::string_view haystack, std::string_view needle, std::string_view hammer)
 Replace all occurrences of a string within another string, returning the result as a std::string.
 
GUL_EXPORT std::string & gul17::replace_inplace (std::string &haystack, std::string_view needle, std::string_view hammer)
 Replace all occurrences of a string within another string in-place.
 

Function Documentation

◆ replace()

std::string gul17::replace ( std::string_view  haystack,
std::string_view  needle,
std::string_view  hammer 
)

Replace all occurrences of a string within another string, returning the result as a std::string.

Specifically, replace all occurrences of needle within haystack by hammer.

Parameters
haystackThe string in which search&replace should take place.
needleThe string to be searched for. If this is an empty string, a copy of haystack is returned.
hammerThe replacement string.

References gul17::bit_set().

◆ replace_inplace()

std::string & gul17::replace_inplace ( std::string &  haystack,
std::string_view  needle,
std::string_view  hammer 
)

Replace all occurrences of a string within another string in-place.

This function replaces all occurrences of needle within haystack by hammer and returns a reference to the modified haystack.

Parameters
haystackThe string in which search&replace should take place.
needleThe string to be searched for. If this is an empty string, haystack is not changed.
hammerThe replacement string.
Returns
the altered haystack.

References gul17::bit_set().