Replace path_set_extension with Path::WithExtension()

This commit is contained in:
Gymnasiast 2022-02-26 17:33:12 +01:00
parent 49b414a40e
commit 376c79408a
No known key found for this signature in database
GPG key ID: DBFFF47AB2CA3EDD
5 changed files with 8 additions and 11 deletions

View file

@ -1087,7 +1087,8 @@ static void WindowLoadsaveSelect(rct_window* w, const char* path)
{
SetAndSaveConfigPath(gConfigGeneral.last_save_track_directory, pathBuffer);
path_set_extension(pathBuffer, "td6", sizeof(pathBuffer));
const auto withExtension = Path::WithExtension(pathBuffer, "td6");
String::Set(pathBuffer, sizeof(pathBuffer), withExtension.c_str());
RCT2::T6Exporter t6Export{ _trackDesign };

View file

@ -80,6 +80,11 @@ namespace Path
return u8path(path).extension().u8string();
}
u8string WithExtension(u8string_view path, u8string_view newExtension)
{
return u8path(path).replace_extension(u8path(newExtension)).u8string();
}
u8string GetAbsolute(u8string_view relative)
{
std::error_code ec;

View file

@ -30,6 +30,7 @@ namespace Path
u8string GetFileName(u8string_view origPath);
u8string GetFileNameWithoutExtension(u8string_view path);
u8string GetExtension(u8string_view path);
u8string WithExtension(u8string_view path, u8string_view newExtension);
u8string GetAbsolute(u8string_view relative);
bool Equals(u8string_view a, u8string_view b);

View file

@ -101,15 +101,6 @@ static const char* path_get_filename(const utf8* path)
return filename;
}
void path_set_extension(utf8* path, const utf8* newExtension, size_t size)
{
// Remove existing extension (check first if there is one)
if (!Path::GetExtension(path).empty())
path_remove_extension(path);
// Append new extension
path_append_extension(path, newExtension, size);
}
void path_append_extension(utf8* path, const utf8* newExtension, size_t size)
{
// Skip to the dot if the extension starts with a pattern (starts with "*.")

View file

@ -26,7 +26,6 @@ int32_t mph_to_dmps(int32_t mph);
bool filename_valid_characters(const utf8* filename);
char* path_get_directory(const utf8* path);
void path_set_extension(utf8* path, const utf8* newExtension, size_t size);
void path_append_extension(utf8* path, const utf8* newExtension, size_t size);
void path_remove_extension(utf8* path);
void path_end_with_separator(utf8* path, size_t size);