1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/*
* mptPathString.h
* ---------------
* Purpose: Wrapper class around the platform-native representation of path names. Should be the only type that is used to store path names.
* Notes : Currently none.
* Authors: OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/
#pragma once
#include "openmpt/all/BuildSettings.hpp"
#include "mpt/base/detect.hpp"
#include "mpt/base/namespace.hpp"
#include "mpt/path/basic_path.hpp"
#include "mpt/path/native_path.hpp"
#include "mpt/path/os_path.hpp"
#include "mpt/string/types.hpp"
#if defined(MODPLUG_TRACKER)
#include "mpt/string_transcode/transcode.hpp"
#endif
#include "mptString.h"
#if defined(MODPLUG_TRACKER) && MPT_OS_WINDOWS
#include <windows.h>
#endif
OPENMPT_NAMESPACE_BEGIN
namespace mpt
{
#if defined(MPT_ENABLE_CHARSET_LOCALE)
using PathString = mpt::native_path;
#define MPT_PATHSTRING_LITERAL(x) MPT_OS_PATH_LITERAL( x )
#define MPT_PATHSTRING(x) mpt::PathString::FromNative(MPT_OS_PATH_LITERAL( x ))
#else // !MPT_ENABLE_CHARSET_LOCALE
using PathString = mpt::BasicPathString<mpt::Utf8PathTraits, false>;
#define MPT_PATHSTRING_LITERAL(x) ( x )
#define MPT_PATHSTRING(x) mpt::PathString::FromNative( x )
#endif // MPT_ENABLE_CHARSET_LOCALE
using RawPathString = PathString::raw_path_type;
#define PC_(x) MPT_PATHSTRING_LITERAL(x)
#define PL_(x) MPT_PATHSTRING_LITERAL(x)
#define P_(x) MPT_PATHSTRING(x)
template <typename T, typename std::enable_if<std::is_same<T, mpt::PathString>::value, bool>::type = true>
inline mpt::ustring ToUString(const T &x)
{
return x.ToUnicode();
}
#if defined(MODPLUG_TRACKER)
#if MPT_OS_WINDOWS
// Relative / absolute paths conversion
mpt::PathString AbsolutePathToRelative(const mpt::PathString &p, const mpt::PathString &relativeTo); // similar to std::fs::path::lexically_approximate
mpt::PathString RelativePathToAbsolute(const mpt::PathString &p, const mpt::PathString &relativeTo);
#if !MPT_OS_WINDOWS_WINRT
inline int PathCompareNoCase(const PathString &a, const PathString &b)
{
return lstrcmpi(a.AsNative().c_str(), b.AsNative().c_str());
}
#endif // !MPT_OS_WINDOWS_WINRT
#endif // MPT_OS_WINDOWS
template <typename Tstring>
inline Tstring SanitizePathComponent(const Tstring &str)
{
return mpt::transcode<Tstring>(mpt::native_path::FromNative(mpt::transcode<mpt::native_path::raw_path_type>(str)).AsSanitizedComponent().AsNative());
}
#endif // MODPLUG_TRACKER
} // namespace mpt
OPENMPT_NAMESPACE_END
|