Skip to content

Commit

Permalink
BasicMarquee: ScrollString() returns std::string_view
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Aug 30, 2024
1 parent 70f9612 commit b4f56ae
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/BasicMarquee.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
#include <assert.h>
#include <string.h>

std::pair<const char *, size_t>
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
Expand Down
7 changes: 2 additions & 5 deletions src/BasicMarquee.hxx
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <utility>
Expand Down Expand Up @@ -73,7 +72,5 @@ public:
}

[[gnu::pure]]
std::pair<const char *, size_t> ScrollString() const noexcept;
std::string_view ScrollString() const noexcept;
};

#endif
2 changes: 1 addition & 1 deletion src/hscroll.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/run_hscroll.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit b4f56ae

Please sign in to comment.