From b4f56ae29a6a9437f1b1dca34d57b3208f630db0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 30 Aug 2024 13:31:26 +0200 Subject: [PATCH] BasicMarquee: ScrollString() returns std::string_view --- src/BasicMarquee.cxx | 4 ++-- src/BasicMarquee.hxx | 7 ++----- src/hscroll.cxx | 2 +- test/run_hscroll.cxx | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/BasicMarquee.cxx b/src/BasicMarquee.cxx index f0f383c6..6b2e5ca5 100644 --- a/src/BasicMarquee.cxx +++ b/src/BasicMarquee.cxx @@ -7,14 +7,14 @@ #include #include -std::pair +std::string_view BasicMarquee::ScrollString() const noexcept { assert(separator != nullptr); const char *p = AtCharMB(buffer.data(), buffer.length(), offset); const char *end = AtWidthMB(p, strlen(p), width); - return std::make_pair(p, size_t(end - p)); + return {p, end}; } bool diff --git a/src/BasicMarquee.hxx b/src/BasicMarquee.hxx index fb402b8a..7f85f963 100644 --- a/src/BasicMarquee.hxx +++ b/src/BasicMarquee.hxx @@ -1,8 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef BASIC_MARQUEE_HXX -#define BASIC_MARQUEE_HXX +#pragma once #include #include @@ -73,7 +72,5 @@ public: } [[gnu::pure]] - std::pair ScrollString() const noexcept; + std::string_view ScrollString() const noexcept; }; - -#endif diff --git a/src/hscroll.cxx b/src/hscroll.cxx index 9bdcf50c..926efc1a 100644 --- a/src/hscroll.cxx +++ b/src/hscroll.cxx @@ -52,7 +52,7 @@ hscroll::Paint() const noexcept /* scroll the string, and draw it */ const auto s = basic.ScrollString(); - mvwaddnstr(w, position.y, position.x, s.first, s.second); + mvwaddnstr(w, position.y, position.x, s.data(), s.size()); if (attr != 0) wattroff(w, attr); diff --git a/test/run_hscroll.cxx b/test/run_hscroll.cxx index 316882bd..8192c3ed 100644 --- a/test/run_hscroll.cxx +++ b/test/run_hscroll.cxx @@ -30,7 +30,7 @@ int main(int argc, char **argv) for (unsigned i = 0; i < count; ++i) { const auto s = hscroll.ScrollString(); - fprintf(stderr, "%.*s\n", int(s.second), s.first); + fprintf(stderr, "%.*s\n", int(s.size()), s.data()); hscroll.Step(); }