[Base] Dedupe new/old separators in UTF-8 fps.

[Base] Dedupe new/old separators in UTF-8 fix_path_separators.
This commit is contained in:
gibbed 2021-05-02 08:10:46 -05:00 committed by Rick Gibbed
parent de3825274e
commit 46dfb3449c
1 changed files with 13 additions and 1 deletions

View File

@ -517,8 +517,20 @@ std::string fix_path_separators(const std::string_view path,
std::string result;
auto it = path_begin;
auto last = it;
auto is_separator = [old_separator, new_separator](char32_t c) {
return c == uint32_t(old_separator) || c == uint32_t(new_separator);
};
// Begins with a separator
if (is_separator(*it)) {
utfcpp::append(new_separator, result);
++it;
last = it;
}
for (;;) {
it = std::find(it, path_end, uint32_t(old_separator));
it = std::find_if(it, path_end, is_separator);
if (it == path_end) {
break;
}