109{
110 std::string out;
111 const std::string *in = &ain;
112 std::string temp;
113 temp.reserve(in->size());
114
116 if (substitution.regexp) {
117 temp.clear();
118 temp.reserve(in->size());
119 boost::regex_replace(ToStringIterator(temp), in->begin(), in->end(),
120 substitution.regexp_pattern, substitution.format,
121 (substitution.single_line ? boost::match_single_line | boost::match_default :
boost::match_not_dot_newline |
boost::match_default) |
boost::format_all);
122 std::swap(out, temp);
123 } else {
124 if (in == &ain)
125 out = ain;
126
127 if (substitution.case_insensitive) {
128 if (substitution.whole_word)
130 [](const std::string &str, size_t start_pos, const std::string &match) {
131 auto begin = str.begin() + start_pos;
132 boost::iterator_range<std::string::const_iterator> r1(begin, str.end());
133 boost::iterator_range<std::string::const_iterator> r2(match.begin(), match.end());
134 auto res = boost::ifind_first(r1, r2);
135 return res ? std::make_pair(size_t(res.begin() - str.begin()), size_t(res.end() - str.begin())) : std::make_pair(std::string::npos, std::string::npos);
136 });
137 else
138 boost::ireplace_all(out, substitution.plain_pattern, substitution.format);
139 } else {
140 if (substitution.whole_word)
142 [](const std::string &str, size_t start_pos, const std::string &match) {
143 size_t pos = str.find(match, start_pos);
144 return std::make_pair(pos, pos + (pos == std::string::npos ? 0 : match.size()));
145 });
146 else
147 boost::replace_all(out, substitution.plain_pattern, substitution.format);
148 }
149 }
150 in = &out;
151 }
152
153 return out;
154}
static void find_and_replace_whole_word(std::string &inout, const std::string &match, const std::string &replace, FindFn find_fn)
Definition FindReplace.cpp:86