xieite::str_replace()

Defined in header <xieite/data/str_replace.hpp>

Replaces all occurrences of a substring within a string with yet another string.


Declaration

#0
template<typename Char, typename Traits = std::char_traits<Char>, typename Alloc = std::allocator<Char>>
[[nodiscard]] constexpr std::basic_string<Char, Traits, Alloc> str_replace(std::basic_string_view<Chars, Traits> strv, std::type_identity_t<std::basic_string_view<Char, Traits>> orig, std::type_identity_t<std::basic_string_view<Char, Traits>> with, const Alloc& alloc = {}) noexcept(false);

#1
template<typename Char, typename Traits = std::char_traits<Char>, typename Alloc = std::allocator<Char>>
[[nodiscard]] constexpr auto str_replace(std::basic_string_view<Chars, Traits> strv, Char orig, std::type_identity_t<std::basic_string_view<Char, Traits>> with, const Alloc& alloc = {})
	XIEITE_ARROW(xieite::str_replace(strv, xieite::str_view(orig), with, alloc))

#2
template<typename Char, typename Traits = std::char_traits<Char>, typename Alloc = std::allocator<Char>>
[[nodiscard]] constexpr auto str_replace(std::basic_string_view<Chars, Traits> strv, std::type_identity_t<std::basic_string_view<Char, Traits>> orig, Char with, const Alloc& alloc = {})
	XIEITE_ARROW(xieite::str_replace(strv, orig, xieite::str_view(with), alloc))

#3
template<typename Char, typename Traits = std::char_traits<Char>, typename Alloc = std::allocator<Char>>
[[nodiscard]] constexpr auto str_replace(std::basic_string_view<Chars, Traits> strv, Char orig, Char with, const Alloc& alloc = {})
	XIEITE_ARROW(xieite::str_replace(strv, xieite::str_view(orig), xieite::str_view(with), alloc))

#4
template<typename Char, typename Traits = std::char_traits<Char>, typename Alloc = std::allocator<Char>>
[[nodiscard]] constexpr auto str_replace(const std::basic_string<Char, Traits, Alloc>& str, auto&& orig, auto&& with, const Alloc& alloc = {})
	XIEITE_ARROW(xieite::str_replace(xieite::str_view(str), XIEITE_FWD(orig), XIEITE_FWD(with), alloc))

#5
template<xieite::is_char Char, typename Traits = std::char_traits<Char>, typename Alloc = std::allocator<Char>, std::size_t length>
[[nodiscard]] constexpr auto str_replace(const xieite::paren<Char[length]>& str, auto&& orig, auto&& with, const Alloc& alloc = {})
	XIEITE_ARROW(xieite::str_replace(xieite::str_view<Char, Traits>(str), XIEITE_FWD(orig), XIEITE_FWD(with), alloc))


Example

int main() {
	xieite::dump(xieite::str_replace("Hello, %NAME%!", "%NAME%", "world"));
}
Output:
Hello, world!
[View in Compiler Explorer]