diff options
author | Max Kellermann <max@musicpd.org> | 2020-04-03 15:55:19 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2020-04-03 16:21:41 +0200 |
commit | 7a58b8c3e8fef24358eb501da93ec6d2bf2de181 (patch) | |
tree | d53bb32f6ec14b40001e96c7dce9e5e9eaa04cae /src/fs | |
parent | 56b4b010d6d1e725ad033a7f3f3e0bb23e76cdcc (diff) |
fs/AllocatedPath: pass std::string_view to FromUTF8()
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/AllocatedPath.cxx | 4 | ||||
-rw-r--r-- | src/fs/AllocatedPath.hxx | 11 | ||||
-rw-r--r-- | src/fs/Charset.cxx | 9 | ||||
-rw-r--r-- | src/fs/Charset.hxx | 3 |
4 files changed, 12 insertions, 15 deletions
diff --git a/src/fs/AllocatedPath.cxx b/src/fs/AllocatedPath.cxx index 8f5d064aa..c2969580e 100644 --- a/src/fs/AllocatedPath.cxx +++ b/src/fs/AllocatedPath.cxx @@ -25,7 +25,7 @@ AllocatedPath::~AllocatedPath() noexcept = default; AllocatedPath -AllocatedPath::FromUTF8(const char *path_utf8) noexcept +AllocatedPath::FromUTF8(std::string_view path_utf8) noexcept { #ifdef FS_CHARSET_ALWAYS_UTF8 return FromFS(path_utf8); @@ -39,7 +39,7 @@ AllocatedPath::FromUTF8(const char *path_utf8) noexcept } AllocatedPath -AllocatedPath::FromUTF8Throw(const char *path_utf8) +AllocatedPath::FromUTF8Throw(std::string_view path_utf8) { #ifdef FS_CHARSET_ALWAYS_UTF8 return FromFS(path_utf8); diff --git a/src/fs/AllocatedPath.hxx b/src/fs/AllocatedPath.hxx index 5988acb79..11362ce1b 100644 --- a/src/fs/AllocatedPath.hxx +++ b/src/fs/AllocatedPath.hxx @@ -173,15 +173,18 @@ public: * Convert a UTF-8 C string to an #AllocatedPath instance. * Returns return a "nulled" instance on error. */ - gcc_pure gcc_nonnull_all - static AllocatedPath FromUTF8(const char *path_utf8) noexcept; + gcc_pure + static AllocatedPath FromUTF8(std::string_view path_utf8) noexcept; + + static AllocatedPath FromUTF8(const char *path_utf8) noexcept { + return FromUTF8(std::string_view(path_utf8)); + } /** * Convert a UTF-8 C string to an #AllocatedPath instance. * Throws a std::runtime_error on error. */ - gcc_nonnull_all - static AllocatedPath FromUTF8Throw(const char *path_utf8); + static AllocatedPath FromUTF8Throw(std::string_view path_utf8); /** * Copy an #AllocatedPath object. diff --git a/src/fs/Charset.cxx b/src/fs/Charset.cxx index 6b4ca9f0a..71cd96908 100644 --- a/src/fs/Charset.cxx +++ b/src/fs/Charset.cxx @@ -118,19 +118,14 @@ PathToUTF8(PathTraitsFS::const_pointer path_fs) #if defined(HAVE_FS_CHARSET) || defined(_WIN32) PathTraitsFS::string -PathFromUTF8(PathTraitsUTF8::const_pointer path_utf8) +PathFromUTF8(PathTraitsUTF8::string_view path_utf8) { -#if !CLANG_CHECK_VERSION(3,6) - /* disabled on clang due to -Wtautological-pointer-compare */ - assert(path_utf8 != nullptr); -#endif - #ifdef _WIN32 const auto buffer = MultiByteToWideChar(CP_UTF8, path_utf8); return PathTraitsFS::string(buffer); #else if (fs_converter == nullptr) - return path_utf8; + return PathTraitsFS::string(path_utf8); const auto buffer = fs_converter->FromUTF8(path_utf8); return PathTraitsFS::string(buffer); diff --git a/src/fs/Charset.hxx b/src/fs/Charset.hxx index 7d3ec46e1..f387176f9 100644 --- a/src/fs/Charset.hxx +++ b/src/fs/Charset.hxx @@ -53,8 +53,7 @@ PathToUTF8(PathTraitsFS::const_pointer path_fs); * * Throws std::runtime_error on error. */ -gcc_nonnull_all PathTraitsFS::string -PathFromUTF8(PathTraitsUTF8::const_pointer path_utf8); +PathFromUTF8(PathTraitsUTF8::string_view path_utf8); #endif |