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/path.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/path.cpp') diff --git a/src/path.cpp b/src/path.cpp index 409fc44..5c78fe9 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -18,7 +18,7 @@ namespace winapi { namespace { -std::wstring do_canonicalize(const std::wstring& path) { +std::wstring do_canonicalize(std::wstring_view path) { static constexpr std::size_t init_buffer_size = MAX_PATH; static_assert(init_buffer_size > 0, "init_buffer_size must be positive"); @@ -28,8 +28,8 @@ std::wstring do_canonicalize(const std::wstring& path) { while (true) { if (buffer.size() > std::numeric_limits::max()) throw std::range_error{"Path buffer is too large"}; - const auto nch = ::GetFullPathNameW( - path.c_str(), static_cast(buffer.size()), buffer.data(), NULL); + const auto nch = + ::GetFullPathNameW(path.data(), static_cast(buffer.size()), buffer.data(), NULL); if (nch == 0) { throw error::windows(GetLastError(), "GetFullPathNameW"); @@ -47,9 +47,9 @@ std::wstring do_canonicalize(const std::wstring& path) { } // namespace -CanonicalPath::CanonicalPath(const std::string& path) : m_path(canonicalize(path)) {} +CanonicalPath::CanonicalPath(std::string_view path) : m_path{canonicalize(path)} {} -std::string CanonicalPath::canonicalize(const std::string& path) { +std::string CanonicalPath::canonicalize(std::string_view path) { return narrow(do_canonicalize(widen(path))); } -- cgit v1.3