Skip to content

Commit

Permalink
Completion: pass std::string::starts_with()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Sep 11, 2024
1 parent a5a6075 commit 58cfb5b
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/Completion.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,15 @@

#include <assert.h>

static bool
StartsWith(const std::string &haystack, const std::string &needle) noexcept
{
return haystack.length() >= needle.length() &&
std::equal(needle.begin(), needle.end(), haystack.begin());
}

Completion::Result
Completion::Complete(const std::string &prefix) const noexcept
{
auto lower = list.lower_bound(prefix);
if (lower == list.end() || !StartsWith(*lower, prefix))
if (lower == list.end() || !lower->starts_with(prefix))
return {std::string(), {lower, lower}};

auto upper = list.upper_bound(prefix);
while (upper != list.end() && StartsWith(*upper, prefix))
while (upper != list.end() && upper->starts_with(prefix))
++upper;

assert(upper != lower);
Expand Down

0 comments on commit 58cfb5b

Please sign in to comment.