diff options
Diffstat (limited to 'src/fs/Traits.hxx')
-rw-r--r-- | src/fs/Traits.hxx | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/src/fs/Traits.hxx b/src/fs/Traits.hxx index 1af8f8672..08d798f05 100644 --- a/src/fs/Traits.hxx +++ b/src/fs/Traits.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -22,24 +22,38 @@ #include "check.h" #include "Compiler.h" +#include "util/StringPointer.hxx" +#include "util/StringAPI.hxx" #ifdef WIN32 #include "util/CharUtil.hxx" +#include <tchar.h> #endif #include <string> -#include <string.h> #include <assert.h> +#ifdef WIN32 +#define PATH_LITERAL(s) _T(s) +#else +#define PATH_LITERAL(s) (s) +#endif + /** * This class describes the nature of a native filesystem path. */ struct PathTraitsFS { +#ifdef WIN32 + typedef std::wstring string; +#else typedef std::string string; - typedef char value_type; - typedef value_type *pointer; - typedef const value_type *const_pointer; +#endif + typedef string::traits_type char_traits; + typedef char_traits::char_type value_type; + typedef StringPointer<value_type> Pointer; + typedef Pointer::pointer pointer; + typedef Pointer::const_pointer const_pointer; #ifdef WIN32 static constexpr value_type SEPARATOR = '\\'; @@ -47,6 +61,8 @@ struct PathTraitsFS { static constexpr value_type SEPARATOR = '/'; #endif + static constexpr const_pointer CURRENT_DIRECTORY = PATH_LITERAL("."); + static constexpr bool IsSeparator(value_type ch) { return #ifdef WIN32 @@ -68,7 +84,7 @@ struct PathTraitsFS { --pos; return IsSeparator(*pos) ? pos : nullptr; #else - return strrchr(p, SEPARATOR); + return StringFindLast(p, SEPARATOR); #endif } @@ -95,7 +111,12 @@ struct PathTraitsFS { gcc_pure gcc_nonnull_all static size_t GetLength(const_pointer p) { - return strlen(p); + return StringLength(p); + } + + gcc_pure gcc_nonnull_all + static const_pointer Find(const_pointer p, value_type ch) { + return StringFind(p, ch); } /** @@ -143,12 +164,15 @@ struct PathTraitsFS { */ struct PathTraitsUTF8 { typedef std::string string; - typedef char value_type; + typedef string::traits_type char_traits; + typedef char_traits::char_type value_type; typedef value_type *pointer; typedef const value_type *const_pointer; static constexpr value_type SEPARATOR = '/'; + static constexpr const_pointer CURRENT_DIRECTORY = "."; + static constexpr bool IsSeparator(value_type ch) { return ch == SEPARATOR; } @@ -186,7 +210,12 @@ struct PathTraitsUTF8 { gcc_pure gcc_nonnull_all static size_t GetLength(const_pointer p) { - return strlen(p); + return StringLength(p); + } + + gcc_pure gcc_nonnull_all + static const_pointer Find(const_pointer p, value_type ch) { + return StringFind(p, ch); } /** |