| 294 | } |
| 295 | |
| 296 | string |
| 297 | TfGetBaseName(const string& fileName) |
| 298 | { |
| 299 | if (fileName.empty()) |
| 300 | return fileName; |
| 301 | #if defined(ARCH_OS_WINDOWS) |
| 302 | const string::size_type i = fileName.find_last_of("\\/"); |
| 303 | #else |
| 304 | const string::size_type i = fileName.rfind("/"); |
| 305 | #endif |
| 306 | if (i == fileName.size() - 1) // ends in directory delimiter |
| 307 | return TfGetBaseName(fileName.substr(0, i)); |
| 308 | #if defined(ARCH_OS_WINDOWS) |
| 309 | const std::wstring wfileName{ ArchWindowsUtf8ToUtf16(fileName) }; |
| 310 | LPWSTR result = PathFindFileNameW(wfileName.c_str()); |
| 311 | |
| 312 | // If PathFindFilename returns the same string back, that means it didn't |
| 313 | // do anything. That could mean that the patch has no basename, in which |
| 314 | // case we want to return the empty string, or it could mean that the |
| 315 | // fileName was already basename, in which case we want to return the |
| 316 | // string back. |
| 317 | if (result == wfileName.c_str()) { |
| 318 | const bool hasDriveLetter = fileName.find(":") != string::npos; |
| 319 | const bool hasPathSeparator = i != string::npos; |
| 320 | if (hasDriveLetter || hasPathSeparator) { |
| 321 | return std::string(); |
| 322 | } |
| 323 | } |
| 324 | return ArchWindowsUtf16ToUtf8(result); |
| 325 | |
| 326 | #else |
| 327 | if (i == string::npos) // no / in name |
| 328 | return fileName; |
| 329 | else |
| 330 | return fileName.substr(i+1); |
| 331 | #endif |
| 332 | } |
| 333 | |
| 334 | string |
| 335 | TfGetPathName(const string& fileName) |