aboutsummaryrefslogtreecommitdiff
path: root/libcxx/src/filesystem/path.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/src/filesystem/path.cpp')
-rw-r--r--libcxx/src/filesystem/path.cpp79
1 files changed, 30 insertions, 49 deletions
diff --git a/libcxx/src/filesystem/path.cpp b/libcxx/src/filesystem/path.cpp
index 82f1ba7..c89346a 100644
--- a/libcxx/src/filesystem/path.cpp
+++ b/libcxx/src/filesystem/path.cpp
@@ -74,19 +74,16 @@ string_view_t path::__root_path_raw() const {
return {};
}
-static bool ConsumeRootName(PathParser *PP) {
- static_assert(PathParser::PS_BeforeBegin == 1 &&
- PathParser::PS_InRootName == 2,
- "Values for enums are incorrect");
+static bool ConsumeRootName(PathParser* PP) {
+ static_assert(PathParser::PS_BeforeBegin == 1 && PathParser::PS_InRootName == 2, "Values for enums are incorrect");
while (PP->State <= PathParser::PS_InRootName)
++(*PP);
return PP->State == PathParser::PS_AtEnd;
}
static bool ConsumeRootDir(PathParser* PP) {
- static_assert(PathParser::PS_BeforeBegin == 1 &&
- PathParser::PS_InRootName == 2 &&
- PathParser::PS_InRootDir == 3, "Values for enums are incorrect");
+ static_assert(PathParser::PS_BeforeBegin == 1 && PathParser::PS_InRootName == 2 && PathParser::PS_InRootDir == 3,
+ "Values for enums are incorrect");
while (PP->State <= PathParser::PS_InRootDir)
++(*PP);
return PP->State == PathParser::PS_AtEnd;
@@ -132,25 +129,14 @@ string_view_t path::__filename() const {
return *(--PathParser::CreateEnd(__pn_));
}
-string_view_t path::__stem() const {
- return parser::separate_filename(__filename()).first;
-}
+string_view_t path::__stem() const { return parser::separate_filename(__filename()).first; }
-string_view_t path::__extension() const {
- return parser::separate_filename(__filename()).second;
-}
+string_view_t path::__extension() const { return parser::separate_filename(__filename()).second; }
////////////////////////////////////////////////////////////////////////////
// path.gen
-enum PathPartKind : unsigned char {
- PK_None,
- PK_RootSep,
- PK_Filename,
- PK_Dot,
- PK_DotDot,
- PK_TrailingSep
-};
+enum PathPartKind : unsigned char { PK_None, PK_RootSep, PK_Filename, PK_Dot, PK_DotDot, PK_TrailingSep };
static PathPartKind ClassifyPathPart(string_view_t Part) {
if (Part.empty())
@@ -180,7 +166,7 @@ path path::lexically_normal() const {
// Track the total size of the parts as we collect them. This allows the
// resulting path to reserve the correct amount of memory.
size_t NewPathSize = 0;
- auto AddPart = [&](PathPartKind K, string_view_t P) {
+ auto AddPart = [&](PathPartKind K, string_view_t P) {
NewPathSize += P.size();
Parts.emplace_back(P, K);
};
@@ -194,7 +180,7 @@ path path::lexically_normal() const {
// Build a stack containing the remaining elements of the path, popping off
// elements which occur before a '..' entry.
for (auto PP = PathParser::CreateBegin(__pn_); PP; ++PP) {
- auto Part = *PP;
+ auto Part = *PP;
PathPartKind Kind = ClassifyPathPart(Part);
switch (Kind) {
case PK_Filename:
@@ -259,11 +245,10 @@ static int DetermineLexicalElementCount(PathParser PP) {
path path::lexically_relative(const path& base) const {
{ // perform root-name/root-directory mismatch checks
- auto PP = PathParser::CreateBegin(__pn_);
- auto PPBase = PathParser::CreateBegin(base.__pn_);
+ auto PP = PathParser::CreateBegin(__pn_);
+ auto PPBase = PathParser::CreateBegin(base.__pn_);
auto CheckIterMismatchAtBase = [&]() {
- return PP.State != PPBase.State &&
- (PP.inRootPath() || PPBase.inRootPath());
+ return PP.State != PPBase.State && (PP.inRootPath() || PPBase.inRootPath());
};
if (PP.inRootName() && PPBase.inRootName()) {
if (*PP != *PPBase)
@@ -280,7 +265,7 @@ path path::lexically_relative(const path& base) const {
}
// Find the first mismatching element
- auto PP = PathParser::CreateBegin(__pn_);
+ auto PP = PathParser::CreateBegin(__pn_);
auto PPBase = PathParser::CreateBegin(base.__pn_);
while (PP && PPBase && PP.State == PPBase.State && *PP == *PPBase) {
++PP;
@@ -314,20 +299,18 @@ path path::lexically_relative(const path& base) const {
////////////////////////////////////////////////////////////////////////////
// path.comparisons
-static int CompareRootName(PathParser *LHS, PathParser *RHS) {
+static int CompareRootName(PathParser* LHS, PathParser* RHS) {
if (!LHS->inRootName() && !RHS->inRootName())
return 0;
- auto GetRootName = [](PathParser *Parser) -> string_view_t {
- return Parser->inRootName() ? **Parser : PATHSTR("");
- };
- int res = GetRootName(LHS).compare(GetRootName(RHS));
+ auto GetRootName = [](PathParser* Parser) -> string_view_t { return Parser->inRootName() ? **Parser : PATHSTR(""); };
+ int res = GetRootName(LHS).compare(GetRootName(RHS));
ConsumeRootName(LHS);
ConsumeRootName(RHS);
return res;
}
-static int CompareRootDir(PathParser *LHS, PathParser *RHS) {
+static int CompareRootDir(PathParser* LHS, PathParser* RHS) {
if (!LHS->inRootDir() && RHS->inRootDir())
return -1;
else if (LHS->inRootDir() && !RHS->inRootDir())
@@ -339,9 +322,9 @@ static int CompareRootDir(PathParser *LHS, PathParser *RHS) {
}
}
-static int CompareRelative(PathParser *LHSPtr, PathParser *RHSPtr) {
- auto &LHS = *LHSPtr;
- auto &RHS = *RHSPtr;
+static int CompareRelative(PathParser* LHSPtr, PathParser* RHSPtr) {
+ auto& LHS = *LHSPtr;
+ auto& RHS = *RHSPtr;
int res;
while (LHS && RHS) {
@@ -353,7 +336,7 @@ static int CompareRelative(PathParser *LHSPtr, PathParser *RHSPtr) {
return 0;
}
-static int CompareEndState(PathParser *LHS, PathParser *RHS) {
+static int CompareEndState(PathParser* LHS, PathParser* RHS) {
if (LHS->atEnd() && !RHS->atEnd())
return -1;
else if (!LHS->atEnd() && RHS->atEnd())
@@ -381,7 +364,7 @@ int path::__compare(string_view_t __s) const {
////////////////////////////////////////////////////////////////////////////
// path.nonmembers
size_t hash_value(const path& __p) noexcept {
- auto PP = PathParser::CreateBegin(__p.native());
+ auto PP = PathParser::CreateBegin(__p.native());
size_t hash_value = 0;
hash<string_view_t> hasher;
while (PP) {
@@ -397,15 +380,15 @@ path::iterator path::begin() const {
auto PP = PathParser::CreateBegin(__pn_);
iterator it;
it.__path_ptr_ = this;
- it.__state_ = static_cast<path::iterator::_ParserState>(PP.State);
- it.__entry_ = PP.RawEntry;
+ it.__state_ = static_cast<path::iterator::_ParserState>(PP.State);
+ it.__entry_ = PP.RawEntry;
it.__stashed_elem_.__assign_view(*PP);
return it;
}
path::iterator path::end() const {
iterator it{};
- it.__state_ = path::iterator::_AtEnd;
+ it.__state_ = path::iterator::_AtEnd;
it.__path_ptr_ = this;
return it;
}
@@ -431,26 +414,24 @@ path::iterator& path::iterator::__decrement() {
#if defined(_LIBCPP_WIN32API)
////////////////////////////////////////////////////////////////////////////
// Windows path conversions
-size_t __wide_to_char(const wstring &str, char *out, size_t outlen) {
+size_t __wide_to_char(const wstring& str, char* out, size_t outlen) {
if (str.empty())
return 0;
ErrorHandler<size_t> err("__wide_to_char", nullptr);
- UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
+ UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
BOOL used_default = FALSE;
- int ret = WideCharToMultiByte(codepage, 0, str.data(), str.size(), out,
- outlen, nullptr, &used_default);
+ int ret = WideCharToMultiByte(codepage, 0, str.data(), str.size(), out, outlen, nullptr, &used_default);
if (ret <= 0 || used_default)
return err.report(errc::illegal_byte_sequence);
return ret;
}
-size_t __char_to_wide(const string &str, wchar_t *out, size_t outlen) {
+size_t __char_to_wide(const string& str, wchar_t* out, size_t outlen) {
if (str.empty())
return 0;
ErrorHandler<size_t> err("__char_to_wide", nullptr);
UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
- int ret = MultiByteToWideChar(codepage, MB_ERR_INVALID_CHARS, str.data(),
- str.size(), out, outlen);
+ int ret = MultiByteToWideChar(codepage, MB_ERR_INVALID_CHARS, str.data(), str.size(), out, outlen);
if (ret <= 0)
return err.report(errc::illegal_byte_sequence);
return ret;