#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_STORAGE_FILESYSTEM_WINDOWSPATHFORMAT_H #define NUCLEX_STORAGE_FILESYSTEM_WINDOWSPATHFORMAT_H #include "Nuclex/Storage/Config.h" #if defined(NUCLEX_STORAGE_WIN32) #include #include namespace Nuclex { namespace Storage { namespace FileSystem { // ------------------------------------------------------------------------------------------- // /// Defines the path format used on Windows-based systems class WindowsPathFormat { /// The preferred path separator of this platform public: static const char PathSeparator; /// Whether this platform has a current working directory public: static const bool HasCurrentWorkingDirectory; /// Determines if the specified character is a path separator /// Character that will be checked for being a path separator /// True if the specified character is a path separator public: static bool IsPathSeparator(char character) { return (character == '\\') || (character == '/'); } /// Determines whether the path contains a windows drive letter /// Path that will be checked /// True if the path contains a drive letter /// /// This is just here to support Windows' confusing drive letter and working /// directory interaction. All other systems should simply return false. /// public: static bool ContainsDriveLetter(const std::string &path) { if(path.length() > 1) { return (path[1] == ':'); } return false; } /// Returns the current working directory /// The current working directory public: static std::string GetCurrentWorkingDirectory(); /// Determines if the specified path is an absolute path /// Path that will be checked /// True if the specified path is an absolute path public: static bool IsAbsolutePath(const std::string &path) { return (GetAbsolutePathPrefixLength(path) > 0); } /// Determines the length of the absolute path prefix in the path /// /// Path in which the length of the absolute path prefix will be determined /// /// The length of the absolute path prefix in the specified path /// /// /// This returns the number of characters that qualify the specified path as /// an absolute path. The path "C:\dos\x" would for example return 3 since both /// the drive letter and the backslash are required. "\\server\\dir\\file.txt" /// would return 2 since only the double backslash is required to build /// a UNC path. "X:myfile" would also be considered absolute and return 2. /// "mooh" returns 0 since it is relative. /// /// /// We do not handle the length extender (\\?\) here because that detail should never /// bleed into the public API. Even the GetNativePath() methods should not return /// this stuff (you wouldn't expect your Explorer to show \\?\... in the address bar). /// Instead, API wrappers could be made to check the path's length and preprend /// the length extender if necessary. /// /// public: static std::size_t GetAbsolutePathPrefixLength(const std::string &path); }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Storage::FileSystem #endif // defined(NUCLEX_STORAGE_WIN32) #endif // NUCLEX_STORAGE_FILESYSTEM_WINDOWSPATHFORMAT_H