void apply_change(
stiX::pattern_matcher const& matcher,
stiX::replacement const& replacement,
std::string_view line,
std::ostream& out
) {
size_type offset = 0;
size_type last_match = -1;
for (auto state = replacement_state(); !state.completed(); state.next(at_end(offset, line))) {
auto loc = matcher.find(line, offset);
if (!loc.match)
break;
if (last_match != loc.from || !loc.zero_width) {
auto up_to_match = line.substr(offset, loc.from - offset);
out << up_to_match;
replacement.apply(line.substr(loc.from, loc.to - loc.from), out);
}
offset = loc.to;
last_match = loc.to;
if (loc.zero_width && not_at_end(offset, line)) {
out << line[loc.from];
offset = loc.from+1;
}
}
out << line.substr(offset) << '\n';
}