diff options
| author | Egor Tensin <egor@tensin.name> | 2026-06-04 22:39:44 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-06-04 22:42:12 +0200 |
| commit | 7fcbd6e474235957f2785c3d9b5344b2acf3ff77 (patch) | |
| tree | 4c1a2d5971a9db5330963ac7d77501638efeb4c0 /src/error.cpp | |
| parent | upgrade to `using` instead of typedef (diff) | |
| download | winapi-common-7fcbd6e474235957f2785c3d9b5344b2acf3ff77.tar.gz winapi-common-7fcbd6e474235957f2785c3d9b5344b2acf3ff77.zip | |
upgrade to std::string_view
Diffstat (limited to '')
| -rw-r--r-- | src/error.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
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 <cstdint> #include <sstream> #include <string> +#include <string_view> #include <system_error> 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(); |
