Factor out count_preceding_backslashes

Now that we have multiple clients of count_preceding_backslashes, factor
it out from fish_indent into wcstringutil.h, and then use the shared
implementation.
This commit is contained in:
ridiculousfish
2021-01-30 16:20:20 -08:00
parent cff5aa9130
commit 409ed7d6d0
4 changed files with 19 additions and 33 deletions

View File

@@ -74,6 +74,15 @@ wcstring wcstolower(wcstring input) {
return result;
}
size_t count_preceding_backslashes(const wcstring &text, size_t idx) {
assert(idx <= text.size() && "Out of bounds");
size_t backslashes = 0;
while (backslashes < idx && text.at(idx - backslashes - 1) == L'\\') {
backslashes++;
}
return backslashes;
}
bool string_prefixes_string(const wchar_t *proposed_prefix, const wcstring &value) {
return string_prefixes_string(proposed_prefix, value.c_str());
}