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 "..".
| 9583 | // For example, "bar///foo" becomes "bar/foo". Does not eliminate other |
| 9584 | // redundancies that might be in a pathname involving "." or "..". |
| 9585 | void FilePath::Normalize() { |
| 9586 | if (pathname_.c_str() == nullptr) { |
| 9587 | pathname_ = ""; |
| 9588 | return; |
| 9589 | } |
| 9590 | const char* src = pathname_.c_str(); |
| 9591 | char* const dest = new char[pathname_.length() + 1]; |
| 9592 | char* dest_ptr = dest; |
| 9593 | memset(dest_ptr, 0, pathname_.length() + 1); |
| 9594 | |
| 9595 | while (*src != '\0') { |
| 9596 | *dest_ptr = *src; |
| 9597 | if (!IsPathSeparator(*src)) { |
| 9598 | src++; |
| 9599 | } else { |
| 9600 | #if GTEST_HAS_ALT_PATH_SEP_ |
| 9601 | if (*dest_ptr == kAlternatePathSeparator) { |
| 9602 | *dest_ptr = kPathSeparator; |
| 9603 | } |
| 9604 | #endif |
| 9605 | while (IsPathSeparator(*src)) |
| 9606 | src++; |
| 9607 | } |
| 9608 | dest_ptr++; |
| 9609 | } |
| 9610 | *dest_ptr = '\0'; |
| 9611 | pathname_ = dest; |
| 9612 | delete[] dest; |
| 9613 | } |
| 9614 | |
| 9615 | } // namespace internal |
| 9616 | } // namespace testing |
nothing calls this directly
no test coverage detected