Skip to content

Commit

Permalink
Match: pass std::string_view to Compile()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Sep 1, 2024
1 parent 11bdf1a commit 014bfb0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
12 changes: 3 additions & 9 deletions src/ListWindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@ ListWindow::Paint(const ListRenderer &renderer) const noexcept

bool
ListWindow::Find(const ListText &text,
const char *str,
std::string_view str,
bool wrap,
bool bell_on_wrap) noexcept
{
unsigned i = GetCursorIndex() + 1;

assert(str != nullptr);

MatchExpression m;
if (!m.Compile(str, false))
return false;
Expand Down Expand Up @@ -91,14 +89,12 @@ ListWindow::Find(const ListText &text,

bool
ListWindow::ReverseFind(const ListText &text,
const char *str,
std::string_view str,
bool wrap,
bool bell_on_wrap) noexcept
{
int i = GetCursorIndex() - 1;

assert(str != nullptr);

if (GetLength() == 0)
return false;

Expand Down Expand Up @@ -132,10 +128,8 @@ ListWindow::ReverseFind(const ListText &text,
}

bool
ListWindow::Jump(const ListText &text, const char *str) noexcept
ListWindow::Jump(const ListText &text, std::string_view str) noexcept
{
assert(str != nullptr);

MatchExpression m;
if (!m.Compile(str, options.jump_prefix_only))
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/ListWindow.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ public:
* Find a string in a list window.
*/
bool Find(const ListText &text,
const char *str,
std::string_view str,
bool wrap,
bool bell_on_wrap) noexcept;

/**
* Find a string in a list window (reversed).
*/
bool ReverseFind(const ListText &text,
const char *str,
std::string_view str,
bool wrap,
bool bell_on_wrap) noexcept;

/**
* Find a string in a list window which begins with the given
* characters in *str.
*/
bool Jump(const ListText &text, const char *str) noexcept;
bool Jump(const ListText &text, std::string_view str) noexcept;
};
4 changes: 2 additions & 2 deletions src/Match.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ MatchExpression::~MatchExpression() noexcept
}

bool
MatchExpression::Compile(const char *src, bool anchor) noexcept
MatchExpression::Compile(std::string_view src, bool anchor) noexcept
{
#ifndef HAVE_PCRE
expression = src;
Expand All @@ -31,7 +31,7 @@ MatchExpression::Compile(const char *src, bool anchor) noexcept

int error_number;
PCRE2_SIZE error_offset;
re = pcre2_compile_8(PCRE2_SPTR8(src), PCRE2_ZERO_TERMINATED,
re = pcre2_compile_8(PCRE2_SPTR8(src.data()), src.size(),
options, &error_number, &error_offset, nullptr);
return re != nullptr;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/Match.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public:
MatchExpression(const MatchExpression &) = delete;
MatchExpression &operator=(const MatchExpression &) = delete;

bool Compile(const char *src, bool anchor) noexcept;
bool Compile(std::string_view src, bool anchor) noexcept;

[[gnu::pure]]
bool operator()(std::string_view line) const noexcept;
Expand Down
4 changes: 2 additions & 2 deletions src/screen_find.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ screen_find(ScreenManager &screen, ListWindow &lw, Command findcmd,

found = reversed
? lw.ReverseFind(text,
screen.findbuf.c_str(),
screen.findbuf,
options.find_wrap,
options.bell_on_wrap)
: lw.Find(text,
screen.findbuf.c_str(),
screen.findbuf,
options.find_wrap,
options.bell_on_wrap);
if (!found) {
Expand Down

0 comments on commit 014bfb0

Please sign in to comment.