General Utility Library for C++14  2.12
Functions
gul14/replace.h

Detailed Description

Replacing all occurrences of a string within another string.

Functions

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

Function Documentation

◆ replace()

std::string gul14::replace ( string_view  haystack,
string_view  needle,
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.

◆ replace_inplace()

std::string & gul14::replace_inplace ( std::string &  haystack,
string_view  needle,
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.