16#include <miktex/Util/config.h>
22#include <miktex/Util/CharBuffer>
23#include <miktex/Util/PathNameUtil>
27MIKTEX_UTIL_BEGIN_NAMESPACE;
40#if defined(MIKTEX_WINDOWS)
55enum class DisplayPathNameOption
59typedef OptionSet<DisplayPathNameOption> DisplayPathNameOptions;
68 typedef CharBuffer<char, MIKTEX_UTIL_PATHNAME_SIZE> Base;
73 PathName(
const PathName& other) =
default;
74 PathName& operator=(
const PathName& other) =
default;
75 PathName(PathName&& other)
noexcept =
default;
76 PathName& operator=(PathName&& other)
noexcept =
default;
77 virtual ~PathName()
noexcept =
default;
109 PathName& operator=(
const char* path)
111 Base::operator=(path);
115 PathName& operator=(
const wchar_t* path)
117 Base::operator=(path);
121 PathName& operator=(
const std::string& path)
123 Base::operator=(path);
127 PathName& operator=(
const std::wstring& path)
129 Base::operator=(path);
137 static MIKTEXUTILCEEAPI(std::vector<std::string>) Split(
const PathName& path);
140 PathName GetDirectoryName()
const
142 std::string directoryName;
143 std::string fileNameWithoutExtension;
144 std::string extension;
145 Split(*
this, directoryName, fileNameWithoutExtension, extension);
146 return PathName(directoryName);
151 std::string directoryName;
152 std::string fileNameWithoutExtension;
153 std::string extension;
154 Split(*
this, directoryName, fileNameWithoutExtension, extension);
155 return PathName(fileNameWithoutExtension + extension);
158 PathName GetFileNameWithoutExtension()
const
160 std::string directoryName;
161 std::string fileNameWithoutExtension;
162 std::string extension;
163 Split(*
this, directoryName, fileNameWithoutExtension, extension);
164 return PathName(fileNameWithoutExtension);
178 Base::Set(GetFileName());
182 MIKTEXUTILTHISAPI(
PathName&) SetToHomeDirectory();
184 MIKTEXUTILTHISAPI(
PathName&) SetToLockDirectory();
244#if defined(MIKTEX_WINDOWS)
245 PathName ToExtendedLengthPathName()
const
247 PathName result = *
this;
248 result.Convert({ ConvertPathNameOption::ToExtendedLengthPathName });
253 std::wstring ToWideCharString()
const
255 return MiKTeX::Util::StringUtil::UTF8ToWideChar(ToString());
258#if defined(MIKTEX_WINDOWS)
259 std::wstring ToNativeString()
const
264 std::string ToNativeString()
const
270 MIKTEXUTILTHISAPI(std::string) ToDisplayString(DisplayPathNameOptions options = {})
const;
276#if defined(MIKTEX_WINDOWS)
283 bool IsFullyQualified()
const
285 return MiKTeX::Util::PathNameUtil::IsFullyQualifiedPath(ToString());
288 bool IsAbsolute()
const
290 return MiKTeX::Util::PathNameUtil::IsAbsolutePath(ToString());
293 PathName& Canonicalize()
295 return Convert({ ConvertPathNameOption::Canonicalize });
305 bool HasExtension()
const
307 return !GetExtension().empty();
315 if (extension_.empty())
319 std::string currentExtension = GetExtension();
320 if (currentExtension.empty())
324 auto extension = extension_;
325 if (extension[0] ==
'.')
327 extension.erase(0, 1);
329 if (currentExtension[0] ==
'.')
331 currentExtension.erase(0, 1);
333 return PathName::Equals(PathName(currentExtension), PathName(extension));
357 PathName& AppendExtension(
const std::string& extension)
359 if (!HasExtension(extension))
361 if (!extension.empty() && extension[0] !=
'.')
365 Base::Append(extension);
374 std::size_t l = GetLength();
383 PathName&
Append(
const std::string& s,
bool appendDirectoryDelimiter)
387 AppendDirectoryDelimiter();
398 return Append(component,
true);
424#if defined(MIKTEX_WINDOWS)
428 bool IsExplicitlyRelative()
const
430 return MiKTeX::Util::PathNameUtil::IsExplicitlyRelative(
ToString());
440 static MIKTEXUTILCEEAPI(
int)
ComparePrefixes(
const PathName& path1,
const PathName& path2, std::size_t count);
449 static MIKTEXUTILCEEAPI(
int)
Compare(
const PathName& path1,
const PathName& path2);
451 static bool Equals(
const PathName& path1,
const PathName& path2)
453 return Compare(path1, path2) == 0;
460 static MIKTEXUTILCEEAPI(
bool)
Match(
const std::string& pattern,
const PathName& path);
464 static MIKTEXUTILCEEAPI(
void) Split(
const PathName& path, std::string& directoryName, std::string& fileNameWithoutExtension, std::string& extension);
479 return PathName::Equals(lhs, rhs);
488 return !PathName::Equals(lhs, rhs);
491inline PathName operator/(
const PathName& lhs,
const std::string& rhs)
493 PathName result = lhs;
498inline std::ostream& operator<<(std::ostream& os,
const PathName& path)
500 return os << path.ToDisplayString();
503MIKTEX_UTIL_END_NAMESPACE;
507 template<>
struct hash<MiKTeX::Util::PathName>
511 return path.GetHash();
Instances of this class store characters.
Definition CharBuffer.h:30
bool Empty() const
Definition CharBuffer.h:209
std::basic_string< char > ToString() const
Definition CharBuffer.h:242
Definition OptionSet.h:26
Instances of this class can be used to store path names.
Definition PathName.h:64
PathName & MakeFullyQualified()
Definition PathName.h:300
bool EndsWithDirectoryDelimiter() const
Definition PathName.h:372
PathName & operator/=(const std::string &component)
Definition PathName.h:404
static int ComparePrefixes(const PathName &path1, const PathName &path2, std::size_t count)
PathName & AppendComponent(const std::string &component)
Definition PathName.h:396
bool HasExtension(const std::string &extension_) const
Definition PathName.h:313
MIKTEXUTILTHISAPI(PathName &) CutOffLastComponent(bool allowSelfCutting)
MIKTEXUTILTHISAPI(PathName &) SetToTempDirectory()
MIKTEXUTILTHISAPI(PathName &) SetExtension(const std PathName SetExtension)(const std::string &extension)
Definition PathName.h:352
MIKTEXUTILTHISAPI(std::string) GetExtension() const
PathName(const std::wstring &path)
Definition PathName.h:102
PathName & CutOffLastComponent()
Definition PathName.h:415
static int Compare(const PathName &path1, const PathName &path2)
MIKTEXUTILTHISAPI(PathName &) AppendDirectoryDelimiter()
PathName(const wchar_t *path)
Definition PathName.h:88
MIKTEXUTILTHISAPI(std::size_t) GetHash() const
PathName & ConvertToUnix()
Definition PathName.h:218
MIKTEXUTILTHISAPI(PathName &) SetToTempFile(const PathName &directory)
PathName & RemoveFileSpec()
Definition PathName.h:169
PathName(const std::string &path)
Definition PathName.h:95
MIKTEXUTILTHISAPI(PathName &) SetToCurrentDirectory()
static bool Match(const std::string &pattern, const PathName &path)
MIKTEXUTILTHISAPI(PathName &) SetToTempFile()
MIKTEXUTILTHISAPI(PathName) GetMountPoint() const
PathName & TransformForComparison()
Definition PathName.h:274
PathName & Append(const std::string &s, bool appendDirectoryDelimiter)
Definition PathName.h:383
PathName & Clean()
Definition PathName.h:211
PathName & ConvertToDos()
Definition PathName.h:232
PathName(const char *path)
Definition PathName.h:81
PathName & RemoveDirectorySpec()
Definition PathName.h:176
static bool IsDirectoryDelimiter(int ch)
Definition PathNameUtil.h:73
ConvertPathNameOption
Path name conversion option enum class.
Definition PathName.h:31
@ MakeUpper
Replaces small letters with their capital letter counterpart.
Definition PathName.h:39
@ CleanUp
Clean up the path name.
Definition PathName.h:49
@ Canonicalize
Resolve symbolic links.
Definition PathName.h:47
@ MakeFullyQualified
Makes the path name fully qualified.
Definition PathName.h:45
@ ToDos
Replaces slashes with backslashes.
Definition PathName.h:35
@ ToUnix
Replaces backslashes with slashes.
Definition PathName.h:33
@ MakeLower
Replaces capital letters with their small letter counterpart.
Definition PathName.h:37
@ ToExtendedLengthPathName
Prefix with \?\ to create an extended-length path name.
Definition PathName.h:42
OptionSet< ConvertPathNameOption > ConvertPathNameOptions
Path name conversion options.
Definition PathName.h:53
bool operator==(const PathName &lhs, const PathName &rhs)
Definition PathName.h:477
bool operator!=(const PathName &lhs, const PathName &rhs)
Definition PathName.h:486