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).
| 349 | // redundancies that might be in a pathname involving "." or "..". |
| 350 | // TODO(wan@google.com): handle Windows network shares (e.g. \\server\share). |
| 351 | void FilePath::Normalize() { |
| 352 | if (pathname_.c_str() == NULL) { |
| 353 | pathname_ = ""; |
| 354 | return; |
| 355 | } |
| 356 | const char* src = pathname_.c_str(); |
| 357 | char* const dest = new char[pathname_.length() + 1]; |
| 358 | char* dest_ptr = dest; |
| 359 | memset(dest_ptr, 0, pathname_.length() + 1); |
| 360 | |
| 361 | while (*src != '\0') { |
| 362 | *dest_ptr = *src; |
| 363 | if (!IsPathSeparator(*src)) { |
| 364 | src++; |
| 365 | } else { |
| 366 | #if GTEST_HAS_ALT_PATH_SEP_ |
| 367 | if (*dest_ptr == kAlternatePathSeparator) { |
| 368 | *dest_ptr = kPathSeparator; |
| 369 | } |
| 370 | #endif |
| 371 | while (IsPathSeparator(*src)) |
| 372 | src++; |
| 373 | } |
| 374 | dest_ptr++; |
| 375 | } |
| 376 | *dest_ptr = '\0'; |
| 377 | pathname_ = dest; |
| 378 | delete[] dest; |
| 379 | } |
| 380 | |
| 381 | } // namespace internal |
| 382 | } // namespace testing |
nothing calls this directly
no test coverage detected