From 6acd4239eb1a34adef9c72b5e2426315516b0f58 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 1 Sep 2024 20:39:21 +0200 Subject: [PATCH] BasicMarquee: change "text" parameter to std::string_view --- src/BasicMarquee.cxx | 4 +--- src/BasicMarquee.hxx | 2 +- src/StatusBar.cxx | 2 +- src/hscroll.cxx | 4 +--- src/hscroll.hxx | 2 +- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/BasicMarquee.cxx b/src/BasicMarquee.cxx index 9c58ed1c..e0ed03ae 100644 --- a/src/BasicMarquee.cxx +++ b/src/BasicMarquee.cxx @@ -20,10 +20,8 @@ BasicMarquee::ScrollString() const noexcept } bool -BasicMarquee::Set(unsigned _width, const char *_text) noexcept +BasicMarquee::Set(unsigned _width, std::string_view _text) noexcept { - assert(_text != nullptr); - if (_width == width && text == _text) /* no change, do nothing (and, most importantly, do not reset the current offset!) */ diff --git a/src/BasicMarquee.hxx b/src/BasicMarquee.hxx index 5dedfa79..7d95af6b 100644 --- a/src/BasicMarquee.hxx +++ b/src/BasicMarquee.hxx @@ -54,7 +54,7 @@ public: * @param text the text in the locale charset * @return false if nothing was changed */ - bool Set(unsigned width, const char *text) noexcept; + bool Set(unsigned width, std::string_view _text) noexcept; /** * Removes the text. It may be reused with Set(). diff --git a/src/StatusBar.cxx b/src/StatusBar.cxx index 3fd3f931..076bdff4 100644 --- a/src/StatusBar.cxx +++ b/src/StatusBar.cxx @@ -182,7 +182,7 @@ StatusBar::Update(const struct mpd_status *status, StringWidthMB(center_text.c_str()); if (width > 3 && center_width > (unsigned)width) { hscroll.Set({(int)left_width, 0}, width, - center_text.c_str(), + center_text, Style::STATUS); } else { hscroll.Clear(); diff --git a/src/hscroll.cxx b/src/hscroll.cxx index 1e565c8d..bb1b22f7 100644 --- a/src/hscroll.cxx +++ b/src/hscroll.cxx @@ -16,11 +16,9 @@ hscroll::OnTimer() noexcept } void -hscroll::Set(Point _position, unsigned _width, const char *_text, +hscroll::Set(Point _position, unsigned _width, std::string_view _text, Style _style, attr_t _attr) noexcept { - assert(_text != nullptr); - position = _position; style = _style; attr = _attr; diff --git a/src/hscroll.hxx b/src/hscroll.hxx index fa7dde86..6ac6d77a 100644 --- a/src/hscroll.hxx +++ b/src/hscroll.hxx @@ -55,7 +55,7 @@ public: * every second with the current window attributes. Call * hscroll_clear() to disable it. */ - void Set(Point _position, unsigned width, const char *text, + void Set(Point _position, unsigned width, std::string_view text, Style style, attr_t attr=0) noexcept; /**