From 014bfb0f18e1f1008dba58696f189af618a38e49 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 1 Sep 2024 07:12:36 +0200 Subject: [PATCH] Match: pass std::string_view to Compile() --- src/ListWindow.cxx | 12 +++--------- src/ListWindow.hxx | 6 +++--- src/Match.cxx | 4 ++-- src/Match.hxx | 2 +- src/screen_find.cxx | 4 ++-- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/ListWindow.cxx b/src/ListWindow.cxx index ceac4de1..0cf50830 100644 --- a/src/ListWindow.cxx +++ b/src/ListWindow.cxx @@ -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; @@ -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; @@ -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; diff --git a/src/ListWindow.hxx b/src/ListWindow.hxx index 8462022a..426976ad 100644 --- a/src/ListWindow.hxx +++ b/src/ListWindow.hxx @@ -57,7 +57,7 @@ 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; @@ -65,7 +65,7 @@ public: * 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; @@ -73,5 +73,5 @@ public: * 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; }; diff --git a/src/Match.cxx b/src/Match.cxx index edcabeac..635001ac 100644 --- a/src/Match.cxx +++ b/src/Match.cxx @@ -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; @@ -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 diff --git a/src/Match.hxx b/src/Match.hxx index 49f236bb..8f391fdf 100644 --- a/src/Match.hxx +++ b/src/Match.hxx @@ -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; diff --git a/src/screen_find.cxx b/src/screen_find.cxx index dff389b6..cbaf5390 100644 --- a/src/screen_find.cxx +++ b/src/screen_find.cxx @@ -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) {