Removes any redundant separators that might be in the pathname. For example, "bar///foo" becomes "bar/foo". Does not eliminate other redundancies that might be in a pathname involving "." or "..". TODO(wan@google.com): handle Windows network shares (e.g. \\server\share).
| 8626 | // redundancies that might be in a pathname involving "." or "..". |
| 8627 | // TODO(wan@google.com): handle Windows network shares (e.g. \\server\share). |
| 8628 | void FilePath::Normalize() { |
| 8629 | if (pathname_.c_str() == NULL) { |
| 8630 | pathname_ = ""; |
| 8631 | return; |
| 8632 | } |
| 8633 | const char* src = pathname_.c_str(); |
| 8634 | char* const dest = new char[pathname_.length() + 1]; |
| 8635 | char* dest_ptr = dest; |
| 8636 | memset(dest_ptr, 0, pathname_.length() + 1); |
| 8637 | |
| 8638 | while (*src != '\0') { |
| 8639 | *dest_ptr = *src; |
| 8640 | if (!IsPathSeparator(*src)) { |
| 8641 | src++; |
| 8642 | } else { |
| 8643 | #if GTEST_HAS_ALT_PATH_SEP_ |
| 8644 | if (*dest_ptr == kAlternatePathSeparator) { |
| 8645 | *dest_ptr = kPathSeparator; |
| 8646 | } |
| 8647 | #endif |
| 8648 | while (IsPathSeparator(*src)) |
| 8649 | src++; |
| 8650 | } |
| 8651 | dest_ptr++; |
| 8652 | } |
| 8653 | *dest_ptr = '\0'; |
| 8654 | pathname_ = dest; |
| 8655 | delete[] dest; |
| 8656 | } |
| 8657 | |
| 8658 | } // namespace internal |
| 8659 | } // namespace testing |
nothing calls this directly
no test coverage detected