* 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. */
| 192 | * @return The completed filename. |
| 193 | */ |
| 194 | static 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. |
no test coverage detected