22 #ifndef GEARS_STRING_REPLACE_HPP
23 #define GEARS_STRING_REPLACE_HPP
25 #include "../meta/alias.hpp"
30 namespace string_replace_detail {
31 template<
typename String>
32 inline size_t nth_finder(
const String& str,
const String& find,
size_t nth) {
34 auto pos = str.find(find);
35 while(start < nth && pos != String::npos) {
36 pos = str.find(find, pos + find.length());
53 template<
typename String>
55 auto start_pos = str.find(from);
56 if(start_pos == String::npos)
58 str.replace(start_pos, from.length(), to);
72 template<
typename String>
74 auto start_pos = str.rfind(from);
75 if(start_pos == String::npos)
77 str.replace(start_pos, from.length(), to);
93 template<
typename String>
95 auto pos = string_replace_detail::nth_finder(str, from, nth);
96 if(pos == String::npos)
98 str.replace(pos, from.length(), to);
112 template<
typename String>
114 size_t start_pos = 0;
115 while((start_pos = str.find(from, start_pos)) != String::npos) {
116 str.replace(start_pos, from.length(), to);
117 start_pos += to.length();
133 template<
typename String>
135 auto start_pos = str.find(erase);
136 if(start_pos == String::npos)
138 str.replace(start_pos, erase.length(),
"");
153 template<
typename String>
155 auto start_pos = str.rfind(erase);
156 if(start_pos == String::npos)
158 str.replace(start_pos, erase.length(),
"");
174 template<
typename String>
176 auto pos = string_replace_detail::nth_finder(str, erase, nth);
177 if(pos == String::npos)
179 str.replace(pos, erase.length(),
"");
194 template<
typename String>
196 size_t start_pos = 0;
197 while((start_pos = str.find(erase, start_pos)) != String::npos) {
198 str.replace(start_pos, erase.length(),
"");
205 #endif // GEARS_STRING_REPLACE_HPP