MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / MatchesExtension

Function MatchesExtension

src/fileio.cpp:1051–1058  ·  view source on GitHub ↗

* Helper to see whether a given filename matches the extension. * @param extension The extension to look for. * @param filename The filename to look in for the extension. * @return True iff the extension is nullptr, or the filename ends with it. */

Source from the content-addressed store, hash-verified

1049 * @return True iff the extension is nullptr, or the filename ends with it.
1050 */
1051static bool MatchesExtension(std::string_view extension, const std::string &filename)
1052{
1053 if (extension.empty()) return true;
1054 if (filename.length() < extension.length()) return false;
1055
1056 std::string_view filename_sv = filename; // String view to avoid making another copy of the substring.
1057 return StrCompareIgnoreCase(extension, filename_sv.substr(filename_sv.length() - extension.length())) == 0;
1058}
1059
1060/**
1061 * Scan a single directory (and recursively its children) and add

Callers 2

ScanPathFunction · 0.85
ScanTarFunction · 0.85

Calls 3

StrCompareIgnoreCaseFunction · 0.85
substrMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected