draconisplusplus/include/rfl/internal/strings/replace_all.hpp

28 lines
631 B
C++
Raw Normal View History

2024-05-31 22:59:00 -04:00
#ifndef RFL_INTERNAL_STRINGS_REPLACE_ALL_HPP_
#define RFL_INTERNAL_STRINGS_REPLACE_ALL_HPP_
#include <string>
#include <vector>
namespace rfl {
2024-06-08 14:10:59 -04:00
namespace internal {
namespace strings {
2024-05-31 22:59:00 -04:00
2024-06-16 00:13:15 -04:00
inline std::string
replace_all(const std::string& _str, const std::string& _from, const std::string& _to) {
2024-06-08 14:10:59 -04:00
auto str = _str;
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
size_t pos = 0;
while ((pos = str.find(_from, pos)) != std::string::npos) {
str.replace(pos, _from.length(), _to);
pos += _to.length();
}
return str;
}
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
} // namespace strings
} // namespace internal
} // namespace rfl
2024-05-31 22:59:00 -04:00
#endif