This commit is contained in:
Hosein Ghahremanzadeh 2020-03-25 07:25:43 +04:30 committed by GitHub
commit 262be1f8cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -349,33 +349,19 @@ FilePath FilePath::RemoveTrailingPathSeparator() const {
// For example, "bar///foo" becomes "bar/foo". Does not eliminate other // For example, "bar///foo" becomes "bar/foo". Does not eliminate other
// redundancies that might be in a pathname involving "." or "..". // redundancies that might be in a pathname involving "." or "..".
void FilePath::Normalize() { void FilePath::Normalize() {
if (pathname_.c_str() == nullptr) { std::string normalized_pathname;
pathname_ = ""; normalized_pathname.reserve(pathname_.length());
return;
}
const char* src = pathname_.c_str();
char* const dest = new char[pathname_.length() + 1];
char* dest_ptr = dest;
memset(dest_ptr, 0, pathname_.length() + 1);
while (*src != '\0') { for (const auto character : pathname_)
*dest_ptr = *src; if (!IsPathSeparator(character))
if (!IsPathSeparator(*src)) { normalized_pathname.push_back(character);
src++; else if (normalized_pathname.empty() ||
} else { normalized_pathname.back() != kPathSeparator)
#if GTEST_HAS_ALT_PATH_SEP_ normalized_pathname.push_back(kPathSeparator);
if (*dest_ptr == kAlternatePathSeparator) { else
*dest_ptr = kPathSeparator; continue;
}
#endif pathname_ = normalized_pathname;
while (IsPathSeparator(*src))
src++;
}
dest_ptr++;
}
*dest_ptr = '\0';
pathname_ = dest;
delete[] dest;
} }
} // namespace internal } // namespace internal