| 862 | } |
| 863 | |
| 864 | string StringUtil::GetFileName(const string &file_path) { |
| 865 | idx_t pos = file_path.find_last_of("/\\"); |
| 866 | if (pos == string::npos) { |
| 867 | return file_path; |
| 868 | } |
| 869 | auto end = file_path.size() - 1; |
| 870 | |
| 871 | // If the rest of the string is just slashes or dots, trim them |
| 872 | if (file_path.find_first_not_of("/\\.", pos) == string::npos) { |
| 873 | // Trim the trailing slashes and dots |
| 874 | while (end > 0 && (file_path[end] == '/' || file_path[end] == '.' || file_path[end] == '\\')) { |
| 875 | end--; |
| 876 | } |
| 877 | |
| 878 | // Now find the next slash |
| 879 | pos = file_path.find_last_of("/\\", end); |
| 880 | if (pos == string::npos) { |
| 881 | return file_path.substr(0, end + 1); |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | return file_path.substr(pos + 1, end - pos); |
| 886 | } |
| 887 | |
| 888 | string StringUtil::GetFileExtension(const string &file_name) { |
| 889 | auto name = GetFileName(file_name); |
no test coverage detected