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

Function FiosMakeFilename

src/fios.cpp:194–209  ·  view source on GitHub ↗

* Construct a filename from its components in destination buffer \a buf. * @param path Directory path, may be \c nullptr. * @param name Filename. * @param ext Filename extension (use \c "" for no extension). * @return The completed filename. */

Source from the content-addressed store, hash-verified

192 * @return The completed filename.
193 */
194static std::string FiosMakeFilename(const std::string *path, std::string_view name, std::string_view ext)
195{
196 std::string_view base_path;
197
198 if (path != nullptr) {
199 base_path = *path;
200 /* Remove trailing path separator, if present */
201 if (!base_path.empty() && base_path.back() == PATHSEPCHAR) base_path.remove_suffix(1);
202 }
203
204 /* Don't append the extension if it is already there */
205 auto period = name.find_last_of('.');
206 if (period != std::string_view::npos && StrEqualsIgnoreCase(name.substr(period), ext)) ext = "";
207
208 return fmt::format("{}{}{}{}", base_path, PATHSEP, name, ext);
209}
210
211/**
212 * Make a save game or scenario filename from a name.

Callers 2

FiosMakeSavegameNameFunction · 0.85
FiosMakeHeightmapNameFunction · 0.85

Calls 4

StrEqualsIgnoreCaseFunction · 0.85
substrMethod · 0.80
formatFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected