24#if !defined(CF4C28E918A44B66B3B0BEF7E88AB721)
25#define CF4C28E918A44B66B3B0BEF7E88AB721
27#include <miktex/Util/config.h>
33#include <miktex/Util/CharBuffer>
34#include <miktex/Util/PathNameUtil>
38MIKTEX_UTIL_BEGIN_NAMESPACE;
51#if defined(MIKTEX_WINDOWS)
64enum class DisplayPathNameOption
68typedef OptionSet<DisplayPathNameOption> DisplayPathNameOptions;
134 PathName(
const char* component1,
const char* component2) :
137 if (component2 !=
nullptr)
139 AppendComponent(component2);
148 PathName(component1.GetData(), component2.GetData())
153 PathName& operator=(
const char* path)
155 Base::operator= (path);
160 PathName& operator=(
const wchar_t* path)
162 Base::operator= (path);
167 PathName& operator=(
const std::string& path)
169 Base::operator= (path);
174 PathName& operator=(
const std::wstring& path)
176 Base::operator= (path);
186 static MIKTEXUTILCEEAPI(std::vector<std::string>) Split(
const PathName& path);
189 static MIKTEXUTILCEEAPI(
void) Split(
const PathName& path, std::string& directoryName, std::string& fileNameWithoutExtension, std::string& extension);
194 std::string directoryName;
195 std::string fileNameWithoutExtension;
196 std::string extension;
197 Split(*
this, directoryName, fileNameWithoutExtension, extension);
204 std::string directoryName;
205 std::string fileNameWithoutExtension;
206 std::string extension;
207 Split(*
this, directoryName, fileNameWithoutExtension, extension);
208 return PathName(fileNameWithoutExtension + extension);
212 PathName GetFileNameWithoutExtension()
const
214 std::string directoryName;
215 std::string fileNameWithoutExtension;
216 std::string extension;
217 Split(*
this, directoryName, fileNameWithoutExtension, extension);
218 return PathName(fileNameWithoutExtension);
226 return CutOffLastComponent();
234 Base::Set(GetFileName());
239 MIKTEXUTILTHISAPI(
PathName&) SetToHomeDirectory();
242 MIKTEXUTILTHISAPI(
PathName&) SetToLockDirectory();
278 return Convert({ ConvertPathNameOption::ToUnix });
285 result.Convert({ ConvertPathNameOption::ToUnix });
294 return Convert({ ConvertPathNameOption::ToDos });
301 result.Convert({ ConvertPathNameOption::ToDos });
305#if defined(MIKTEX_WINDOWS)
306 PathName ToExtendedLengthPathName()
const
308 PathName result = *
this;
309 result.Convert({ ConvertPathNameOption::ToExtendedLengthPathName });
315 std::wstring ToWideCharString()
const
317 return MiKTeX::Util::StringUtil::UTF8ToWideChar(GetData());
320#if defined(MIKTEX_WINDOWS)
322 std::wstring ToNativeString()
const
328 std::string ToNativeString()
const
335 MIKTEXUTILTHISAPI(std::string) ToDisplayString(DisplayPathNameOptions options = {})
const;
342#if defined(MIKTEX_WINDOWS)
343 return Convert({ ConvertPathNameOption::ToUnix, ConvertPathNameOption::MakeLower });
350 bool IsFullyQualified()
const
352 return MiKTeX::Util::PathNameUtil::IsFullyQualifiedPath(ToString());
356 bool IsAbsolute()
const
358 return MiKTeX::Util::PathNameUtil::IsAbsolutePath(ToString());
362 bool IsComparable()
const
364#if defined(MIKTEX_WINDOWS)
365 for (
const char* lpsz = GetData(); *lpsz != 0; ++lpsz)
367 if (*lpsz == MiKTeX::Util::PathNameUtil::DosDirectoryDelimiter || (*lpsz >=
'A' && *lpsz <=
'Z'))
381 return Convert({ ConvertPathNameOption::Canonicalize });
389 return Convert({ ConvertPathNameOption::MakeFullyQualified });
393 bool HasExtension()
const
395 return !GetExtension().empty();
404 std::string currentExtension = GetExtension();
405 if (currentExtension.empty())
409 if (extension[0] ==
'.')
413 return PathName::Compare(currentExtension.substr(1), extension) == 0;
437 return SetExtension(extension,
true);
447 return SetExtension(extension.c_str(),
true);
451 PathName& AppendExtension(
const char* extension)
453 if (!HasExtension(extension))
455 if (*extension !=
'.')
459 Base::Append(extension);
465 PathName& AppendExtension(
const std::string& extension)
467 return AppendExtension(extension.c_str());
475 std::size_t l = GetLength();
489 AppendDirectoryDelimiter();
496 PathName& Append(
const std::string& str,
bool appendDirectoryDelimiter)
498 return Append(str.c_str(), appendDirectoryDelimiter);
507 return Append(component,
true);
516 return AppendComponent(component);
525 return AppendComponent(component.GetData());
534 return AppendComponent(component.c_str());
547 return CutOffLastComponent(
false);
555#if defined(MIKTEX_WINDOWS)
557 MIKTEXUTILTHISAPI(
PathName&) AppendAltDirectoryDelimiter();
561 bool IsExplicitlyRelative()
const
563 return MiKTeX::Util::PathNameUtil::IsExplicitlyRelative(ToString());
574 static MIKTEXUTILCEEAPI(
int)
Compare(
const char* lpszPath1,
const char* lpszPath2, std::size_t count);
577 static int Compare(
const PathName& path1,
const PathName& path2, std::size_t count)
579 return Compare(path1.GetData(), path2.GetData(), count);
590 static MIKTEXUTILCEEAPI(
int)
Compare(
const char* lpszPath1,
const char* lpszPath2);
602 return Compare(path1.GetData(), path2.GetData());
613 static int Compare(
const std::string& path1,
const std::string& path2)
615 return Compare(path1.c_str(), path2.c_str());
621 return Compare(path1, path2) == 0;
629 static MIKTEXUTILCEEAPI(
bool)
Match(
const char* lpszPattern,
const char* lpszPath);
632 static bool Match(
const char* lpszPattern,
const PathName& path)
634 return Match(lpszPattern, path.GetData());
638inline bool operator<(
const PathName& lhs,
const PathName& rhs)
640 return PathName::Compare(lhs, rhs) < 0;
649 return PathName::Compare(lhs, rhs) == 0;
658 return PathName::Compare(lhs, rhs) != 0;
661inline PathName operator/(
const PathName& lhs,
const PathName& rhs)
663 PathName result = lhs;
668inline std::ostream& operator<<(std::ostream& os,
const PathName& path)
670 return os << path.ToDisplayString();
673MIKTEX_UTIL_END_NAMESPACE;
677 template<>
struct hash<MiKTeX::Util::PathName>
681 return path.GetHash();
Instances of this class store characters.
Definition: CharBuffer.h:41
Definition: OptionSet.h:37
Instances of this class can be used to store path names.
Definition: PathName.h:73
PathName & SetExtension(const char *extension)
Definition: PathName.h:435
PathName & MakeFullyQualified()
Definition: PathName.h:387
bool EndsWithDirectoryDelimiter() const
Definition: PathName.h:473
PathName & operator/=(const std::string &component)
Definition: PathName.h:532
PathName & AppendComponent(const char *component)
Definition: PathName.h:505
MIKTEXUTILTHISAPI(PathName &) SetExtension(const char *extension
static int Compare(const char *lpszPath1, const char *lpszPath2)
MIKTEXUTILTHISAPI(PathName &) CutOffLastComponent(bool allowSelfCutting)
MIKTEXUTILTHISAPI(PathName &) SetToTempDirectory()
MIKTEXUTILTHISAPI(std::string) GetExtension() const
PathName(const std::wstring &path)
Definition: PathName.h:122
PathName & CutOffLastComponent()
Definition: PathName.h:545
static int Compare(const PathName &path1, const PathName &path2)
Definition: PathName.h:600
PathName & operator/=(const char *component)
Definition: PathName.h:514
MIKTEXUTILTHISAPI(PathName &) AppendDirectoryDelimiter()
PathName & SetExtension(const std::string &extension)
Definition: PathName.h:445
PathName(const wchar_t *path)
Definition: PathName.h:106
MIKTEXUTILTHISAPI(std::size_t) GetHash() const
static int Compare(const std::string &path1, const std::string &path2)
Definition: PathName.h:613
PathName & ConvertToUnix()
Definition: PathName.h:276
MIKTEXUTILTHISAPI(PathName &) SetToTempFile(const PathName &directory)
PathName & RemoveFileSpec()
Definition: PathName.h:224
static int Compare(const char *lpszPath1, const char *lpszPath2, std::size_t count)
PathName(const std::string &path)
Definition: PathName.h:114
PathName & operator/=(const PathName &component)
Definition: PathName.h:523
MIKTEXUTILTHISAPI(PathName &) SetToCurrentDirectory()
MIKTEXUTILTHISAPI(PathName &) SetToTempFile()
MIKTEXUTILTHISAPI(PathName) GetMountPoint() const
PathName & TransformForComparison()
Definition: PathName.h:340
PathName & ConvertToDos()
Definition: PathName.h:292
bool HasExtension(const char *extension) const
Definition: PathName.h:402
PathName(const char *path)
Definition: PathName.h:98
PathName & RemoveDirectorySpec()
Definition: PathName.h:232
PathName & Append(const char *lpsz, bool appendDirectoryDelimiter)
Definition: PathName.h:485
PathName(const char *component1, const char *component2)
Definition: PathName.h:134
PathName(const PathName &component1, const PathName &component2)
Definition: PathName.h:147
static bool Match(const char *lpszPattern, const char *lpszPath)
static bool IsDirectoryDelimiter(int ch)
Definition: PathNameUtil.h:108
ConvertPathNameOption
Path name conversion option enum class.
Definition: PathName.h:42
@ MakeUpper
Replaces small letters with their capital letter counterpart.
@ Canonicalize
Resolve symbolic links.
@ MakeFullyQualified
Makes the path name fully qualified.
@ ToDos
Replaces slashes with backslashes.
@ ToUnix
Replaces backslashes with slashes.
@ MakeLower
Replaces capital letters with their small letter counterpart.
@ ToExtendedLengthPathName
Prefix with \?\ to create an extended-length path name.