11 : collapse_multiple_(collapse_multiple), trim_edges_(trim_edges) {
23 bool prev_was_whitespace =
false;
25 for (
const auto& rune : input) {
26 if (rune.is_whitespace()) {
28 if (collapse_multiple_) {
30 if (!prev_was_whitespace) {
37 prev_was_whitespace =
true;
41 prev_was_whitespace =
false;
51 auto start_it = temp_result.
begin();
52 while (start_it != temp_result.
end() && start_it->is_whitespace()) {
57 auto end_it = temp_result.
end();
58 while (end_it != start_it && (end_it - 1)->is_whitespace()) {
64 if (start_it < end_it) {
66 result.
reserve(std::distance(start_it, end_it));
67 for (
auto it = start_it; it != end_it; ++it) {
76 std::string desc =
"Whitespace normalizer (";
77 if (collapse_multiple_) {
78 desc +=
"collapse multiple";
79 if (trim_edges_) desc +=
", ";
reference emplace_back(Args &&... args)
bool empty() const noexcept
void reserve(size_type new_cap)
void push_back(const Rune &rune)
size_type size() const noexcept
iterator begin() noexcept
WhitespaceNormalizer(bool collapse_multiple=true, bool trim_edges=true)
Construct a WhitespaceNormalizer.
std::string description() const override
Get the spell's description.
RuneSequence operator()(const RuneSequence &input) const override
Apply the spell transformation.
RuneString RuneSequence
Backward compatibility alias for RuneString.
Simple and unified spell system for text transformation.