From 7fcbd6e474235957f2785c3d9b5344b2acf3ff77 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 4 Jun 2026 22:39:44 +0200 Subject: upgrade to std::string_view --- src/error.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/error.cpp') diff --git a/src/error.cpp b/src/error.cpp index d0c8a53..3fd18ea 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -11,20 +11,22 @@ #include #include #include +#include #include namespace winapi { namespace error { namespace { -std::wstring trim_trailing_newline(const std::wstring& s) { +std::wstring trim_trailing_newline(std::wstring_view s) { const auto last_pos = s.find_last_not_of(L"\r\n"); - if (std::wstring::npos == last_pos) + if (std::wstring_view::npos == last_pos) return {}; - return s.substr(0, last_pos + 1); + const auto sub = s.substr(0, last_pos + 1); + return {sub.data(), sub.length()}; } -std::string build_what(DWORD code, const char* function) { +std::string build_what(DWORD code, std::string_view function) { std::ostringstream what; what << "Function " << function << " failed with error code " << code; return what.str(); -- cgit v1.3