Commit c09fbb23 by Hosein Ghahramanzadeh

Fix always false condition and clean function body

An always false condition was remove from Normalize member function of FilePath and the body of the function which was poorly writen is improved.
parent 8b4817e3
...@@ -349,33 +349,19 @@ FilePath FilePath::RemoveTrailingPathSeparator() const { ...@@ -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;
} for (const auto character : pathname_)
const char* src = pathname_.c_str(); if (!IsPathSeparator(character))
char* const dest = new char[pathname_.length() + 1]; normalized_pathname.push_back(character);
char* dest_ptr = dest; else if (normalized_pathname.empty() ||
memset(dest_ptr, 0, pathname_.length() + 1); normalized_pathname.back() != kPathSeparator)
normalized_pathname.push_back(kPathSeparator);
while (*src != '\0') { else
*dest_ptr = *src; continue;
if (!IsPathSeparator(*src)) {
src++; pathname_ = normalized_pathname;
} else {
#if GTEST_HAS_ALT_PATH_SEP_
if (*dest_ptr == kAlternatePathSeparator) {
*dest_ptr = kPathSeparator;
}
#endif
while (IsPathSeparator(*src))
src++;
}
dest_ptr++;
}
*dest_ptr = '\0';
pathname_ = dest;
delete[] dest;
} }
} // namespace internal } // namespace internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment