MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / GetFileName

Method GetFileName

Sources/Shared/IO/FileSystem.cpp:1050–1069  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1048 }
1049
1050 StringView FileSystem::GetFileName(StringView path)
1051 {
1052 if (path.empty()) return {};
1053
1054 std::size_t pathRootLength = GetPathRootLength(path);
1055 std::size_t pathLength = path.size();
1056 // Strip any trailing path separators
1057 while (pathLength > pathRootLength && (path[pathLength - 1] == '/' || path[pathLength - 1] == '\\')) {
1058 pathLength--;
1059 }
1060 if (pathLength <= pathRootLength) return {};
1061 std::size_t i = pathLength;
1062 // Try to get the last path separator
1063 while (i > pathRootLength && path[--i] != '/' && path[i] != '\\');
1064
1065 if (path[i] == '/' || path[i] == '\\') {
1066 i++;
1067 }
1068 return path.slice(i, pathLength);
1069 }
1070
1071 StringView FileSystem::GetFileNameWithoutExtension(StringView path)
1072 {

Callers

nothing calls this directly

Calls 4

GetPathRootLengthFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected