Commit eb174d5b authored by Max Kellermann's avatar Max Kellermann

fs/{Allocated,}Path,Charset: use PathTraitsFS typedefs

parent 4c899e9c
...@@ -87,7 +87,7 @@ void ...@@ -87,7 +87,7 @@ void
AllocatedPath::ChopSeparators() AllocatedPath::ChopSeparators()
{ {
size_t l = length(); size_t l = length();
const char *p = data(); const auto *p = data();
while (l >= 2 && PathTraitsFS::IsSeparator(p[l - 1])) { while (l >= 2 && PathTraitsFS::IsSeparator(p[l - 1])) {
--l; --l;
......
...@@ -176,7 +176,7 @@ public: ...@@ -176,7 +176,7 @@ public:
* Allows the caller to "steal" the internal value by * Allows the caller to "steal" the internal value by
* providing a rvalue reference to the std::string attribute. * providing a rvalue reference to the std::string attribute.
*/ */
std::string &&Steal() { string &&Steal() {
return std::move(value); return std::move(value);
} }
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "Domain.hxx" #include "Domain.hxx"
#include "Limits.hxx" #include "Limits.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "Traits.hxx"
#include "lib/icu/Converter.hxx" #include "lib/icu/Converter.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
...@@ -73,13 +72,13 @@ GetFSCharset() ...@@ -73,13 +72,13 @@ GetFSCharset()
#endif #endif
} }
static inline std::string && static inline PathTraitsUTF8::string &&
FixSeparators(std::string &&s) FixSeparators(PathTraitsUTF8::string &&s)
{ {
// For whatever reason GCC can't convert constexpr to value reference. // For whatever reason GCC can't convert constexpr to value reference.
// This leads to link errors when passing separators directly. // This leads to link errors when passing separators directly.
auto from = PathTraitsFS::SEPARATOR;
auto to = PathTraitsUTF8::SEPARATOR; auto to = PathTraitsUTF8::SEPARATOR;
decltype(to) from = PathTraitsFS::SEPARATOR;
if (from != to) if (from != to)
/* convert backslash to slash on WIN32 */ /* convert backslash to slash on WIN32 */
...@@ -88,8 +87,8 @@ FixSeparators(std::string &&s) ...@@ -88,8 +87,8 @@ FixSeparators(std::string &&s)
return std::move(s); return std::move(s);
} }
std::string PathTraitsUTF8::string
PathToUTF8(const char *path_fs) PathToUTF8(PathTraitsFS::const_pointer path_fs)
{ {
#if !CLANG_CHECK_VERSION(3,6) #if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */ /* disabled on clang due to -Wtautological-pointer-compare */
...@@ -108,8 +107,8 @@ PathToUTF8(const char *path_fs) ...@@ -108,8 +107,8 @@ PathToUTF8(const char *path_fs)
#ifdef HAVE_FS_CHARSET #ifdef HAVE_FS_CHARSET
std::string PathTraitsFS::string
PathFromUTF8(const char *path_utf8) PathFromUTF8(PathTraitsUTF8::const_pointer path_utf8)
{ {
#if !CLANG_CHECK_VERSION(3,6) #if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */ /* disabled on clang due to -Wtautological-pointer-compare */
......
...@@ -22,8 +22,7 @@ ...@@ -22,8 +22,7 @@
#include "check.h" #include "check.h"
#include "Compiler.h" #include "Compiler.h"
#include "Traits.hxx"
#include <string>
#if defined(HAVE_ICU) || defined(HAVE_GLIB) #if defined(HAVE_ICU) || defined(HAVE_GLIB)
#define HAVE_FS_CHARSET #define HAVE_FS_CHARSET
...@@ -49,15 +48,15 @@ DeinitFSCharset(); ...@@ -49,15 +48,15 @@ DeinitFSCharset();
* Returns empty string on error. * Returns empty string on error.
*/ */
gcc_pure gcc_nonnull_all gcc_pure gcc_nonnull_all
std::string PathTraitsUTF8::string
PathToUTF8(const char *path_fs); PathToUTF8(PathTraitsFS::const_pointer path_fs);
/** /**
* Convert the path from UTF-8. * Convert the path from UTF-8.
* Returns empty string on error. * Returns empty string on error.
*/ */
gcc_pure gcc_nonnull_all gcc_pure gcc_nonnull_all
std::string PathTraitsFS::string
PathFromUTF8(const char *path_utf8); PathFromUTF8(PathTraitsUTF8::const_pointer path_utf8);
#endif #endif
...@@ -42,7 +42,7 @@ class Path { ...@@ -42,7 +42,7 @@ class Path {
typedef PathTraitsFS::pointer pointer; typedef PathTraitsFS::pointer pointer;
typedef PathTraitsFS::const_pointer const_pointer; typedef PathTraitsFS::const_pointer const_pointer;
const char *value; const_pointer value;
constexpr Path(const_pointer _value):value(_value) {} constexpr Path(const_pointer _value):value(_value) {}
...@@ -100,7 +100,7 @@ public: ...@@ -100,7 +100,7 @@ public:
size_t length() const { size_t length() const {
assert(value != nullptr); assert(value != nullptr);
return strlen(value); return PathTraitsFS::GetLength(value);
} }
/** /**
...@@ -153,7 +153,7 @@ public: ...@@ -153,7 +153,7 @@ public:
* nullptr on mismatch. * nullptr on mismatch.
*/ */
gcc_pure gcc_pure
const char *RelativeFS(const char *other_fs) const { const_pointer RelativeFS(const_pointer other_fs) const {
return PathTraitsFS::Relative(value, other_fs); return PathTraitsFS::Relative(value, other_fs);
} }
......
...@@ -112,7 +112,7 @@ static inline AllocatedPath SafePathFromFS(PathTraitsFS::const_pointer dir) ...@@ -112,7 +112,7 @@ static inline AllocatedPath SafePathFromFS(PathTraitsFS::const_pointer dir)
#ifdef WIN32 #ifdef WIN32
static AllocatedPath GetStandardDir(int folder_id) static AllocatedPath GetStandardDir(int folder_id)
{ {
std::array<char, MAX_PATH> dir; std::array<PathTraitsFS::value_type, MAX_PATH> dir;
auto ret = SHGetFolderPath(nullptr, folder_id | CSIDL_FLAG_DONT_VERIFY, auto ret = SHGetFolderPath(nullptr, folder_id | CSIDL_FLAG_DONT_VERIFY,
nullptr, SHGFP_TYPE_CURRENT, dir.data()); nullptr, SHGFP_TYPE_CURRENT, dir.data());
if (FAILED(ret)) if (FAILED(ret))
...@@ -287,7 +287,7 @@ AllocatedPath GetSystemConfigDir() ...@@ -287,7 +287,7 @@ AllocatedPath GetSystemConfigDir()
AllocatedPath GetAppBaseDir() AllocatedPath GetAppBaseDir()
{ {
std::array<char, MAX_PATH> app; std::array<PathTraitsFS::value_type, MAX_PATH> app;
auto ret = GetModuleFileName(nullptr, app.data(), app.size()); auto ret = GetModuleFileName(nullptr, app.data(), app.size());
// Check for error // Check for error
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment