Skip to content

Commit

Permalink
feat(core): ldml marker: assert that all markers were re-added 🙀
Browse files Browse the repository at this point in the history
For: #10369
  • Loading branch information
srl295 committed Jan 19, 2024
1 parent 9ff937b commit ade29e0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/src/ldml/ldml_markers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@ static void add_back_markers(std::u32string &str, const std::u32string &src, mar
str.clear();
// iterator over the marker map
auto marki = map2.rbegin();
// number of markers left to process
size_t processed_count = map2.size();

// add any end-of-text markers
while(marki != map2.rend() && marki->first == MARKER_BEFORE_EOT) {
prepend_marker(str, (marki++)->second, encoding);
prepend_marker(str, marki->second, encoding);
processed_count--;
marki->second = 0; // mark as done
marki++;
}

// go from end to beginning of string
Expand All @@ -81,6 +86,7 @@ static void add_back_markers(std::u32string &str, const std::u32string &src, mar
// set to '0' if already applied
prepend_marker(str, marki->second, encoding);
marki->second = 0; // mark as already applied
processed_count--;
}
}

Expand All @@ -89,10 +95,11 @@ static void add_back_markers(std::u32string &str, const std::u32string &src, mar
if (marki2->second != 0 && marki2->first == ch) {
prepend_marker(str, marki2->second, encoding);
marki2->second = 0; // mark as already applied
processed_count--;
}
}
}
// assert(marki == map.rend()); // that we consumed everything
assert(processed_count == 0); // assert that we consumed all marks
}

bool normalize_nfd_markers_segment(std::u32string &str, marker_map &map, marker_encoding encoding) {
Expand Down

0 comments on commit ade29e0

Please sign in to comment.