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).
| 7774 | // redundancies that might be in a pathname involving "." or "..". |
| 7775 | // TODO(wan@google.com): handle Windows network shares (e.g. \\server\share). |
| 7776 | void FilePath::Normalize() { |
| 7777 | if (pathname_.c_str() == NULL) { |
| 7778 | pathname_ = ""; |
| 7779 | return; |
| 7780 | } |
| 7781 | const char* src = pathname_.c_str(); |
| 7782 | char* const dest = new char[pathname_.length() + 1]; |
| 7783 | char* dest_ptr = dest; |
| 7784 | memset(dest_ptr, 0, pathname_.length() + 1); |
| 7785 | |
| 7786 | while (*src != '\0') { |
| 7787 | *dest_ptr = *src; |
| 7788 | if (!IsPathSeparator(*src)) { |
| 7789 | src++; |
| 7790 | } else { |
| 7791 | #if GTEST_HAS_ALT_PATH_SEP_ |
| 7792 | if (*dest_ptr == kAlternatePathSeparator) { |
| 7793 | *dest_ptr = kPathSeparator; |
| 7794 | } |
| 7795 | #endif |
| 7796 | while (IsPathSeparator(*src)) |
| 7797 | src++; |
| 7798 | } |
| 7799 | dest_ptr++; |
| 7800 | } |
| 7801 | *dest_ptr = '\0'; |
| 7802 | pathname_ = dest; |
| 7803 | delete[] dest; |
| 7804 | } |
| 7805 | |
| 7806 | } // namespace internal |
| 7807 | } // namespace testing |
nothing calls this directly
no test coverage detected