mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 19:13:07 +01:00
Merge pull request #16503 from Gymnasiast/refactor/replace-path-get-extension
Replace path_get_extension() with Path::GetExtension()
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include "actions/LandBuyRightsAction.h"
|
||||
#include "actions/LandSetRightsAction.h"
|
||||
#include "audio/audio.h"
|
||||
#include "core/Path.hpp"
|
||||
#include "entity/EntityList.h"
|
||||
#include "entity/EntityRegistry.h"
|
||||
#include "entity/Guest.h"
|
||||
@@ -282,7 +283,8 @@ namespace Editor
|
||||
*/
|
||||
static bool ReadS6(const char* path)
|
||||
{
|
||||
auto extension = path_get_extension(path);
|
||||
auto extensionS = Path::GetExtension(path);
|
||||
const char* extension = extensionS.c_str();
|
||||
auto loadedFromSave = false;
|
||||
if (_stricmp(extension, ".sc6") == 0)
|
||||
{
|
||||
|
||||
@@ -178,8 +178,8 @@ namespace RCT2
|
||||
|
||||
if (path)
|
||||
{
|
||||
auto extension = path_get_extension(path);
|
||||
_isSV7 = _stricmp(extension, ".sv7") == 0;
|
||||
auto extension = Path::GetExtension(path);
|
||||
_isSV7 = _stricmp(extension.c_str(), ".sv7") == 0;
|
||||
}
|
||||
|
||||
chunkReader.ReadChunk(&_s6.Objects, sizeof(_s6.Objects));
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "../common.h"
|
||||
#include "../core/Guard.hpp"
|
||||
#include "../core/Path.hpp"
|
||||
#include "../interface/Window.h"
|
||||
#include "../localisation/Localisation.h"
|
||||
#include "../platform/platform.h"
|
||||
@@ -100,27 +101,10 @@ const char* path_get_filename(const utf8* path)
|
||||
return filename;
|
||||
}
|
||||
|
||||
// Returns the extension (dot inclusive) from the given path, or the end of the
|
||||
// string when no extension was found.
|
||||
const char* path_get_extension(const utf8* path)
|
||||
{
|
||||
// Get the filename from the path
|
||||
const char* filename = path_get_filename(path);
|
||||
|
||||
// Try to find the most-right dot in the filename
|
||||
char* extension = const_cast<char*>(strrchr(filename, '.'));
|
||||
|
||||
// When no dot was found, return a pointer to the null-terminator
|
||||
if (extension == nullptr)
|
||||
extension = const_cast<char*>(strrchr(filename, '\0'));
|
||||
|
||||
return extension;
|
||||
}
|
||||
|
||||
void path_set_extension(utf8* path, const utf8* newExtension, size_t size)
|
||||
{
|
||||
// Remove existing extension (check first if there is one)
|
||||
if (path_get_extension(path) < strrchr(path, '\0'))
|
||||
if (!Path::GetExtension(path).empty())
|
||||
path_remove_extension(path);
|
||||
// Append new extension
|
||||
path_append_extension(path, newExtension, size);
|
||||
|
||||
@@ -26,7 +26,6 @@ bool filename_valid_characters(const utf8* filename);
|
||||
|
||||
char* path_get_directory(const utf8* path);
|
||||
const char* path_get_filename(const utf8* path);
|
||||
const char* path_get_extension(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);
|
||||
|
||||
Reference in New Issue
Block a user