mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-18 01:55:46 -04:00
Common/FileSystem: Add IsAbsolutePath() and tests
This commit is contained in:
@ -230,6 +230,16 @@ void SanitizeFileName(String& Destination, bool StripSlashes /* = true */)
|
||||
return SanitizeFileName(Destination, Destination, StripSlashes);
|
||||
}
|
||||
|
||||
bool IsAbsolutePath(const std::string_view& path)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return (path.length() >= 3 && ((path[0] >= 'A' && path[0] <= 'Z') || (path[0] >= 'a' && path[0] <= 'z')) &&
|
||||
path[1] == ':' && (path[2] == '/' || path[2] == '\\'));
|
||||
#else
|
||||
return (path.length() >= 1 && path[0] == '/');
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string ReplaceExtension(std::string_view path, std::string_view new_extension)
|
||||
{
|
||||
std::string_view::size_type pos = path.rfind('.');
|
||||
|
@ -137,6 +137,9 @@ void SanitizeFileName(char* Destination, u32 cbDestination, const char* FileName
|
||||
void SanitizeFileName(String& Destination, const char* FileName, bool StripSlashes = true);
|
||||
void SanitizeFileName(String& Destination, bool StripSlashes = true);
|
||||
|
||||
/// Returns true if the specified path is an absolute path (C:\Path on Windows or /path on Unix).
|
||||
bool IsAbsolutePath(const std::string_view& path);
|
||||
|
||||
/// Replaces the extension of a filename with another.
|
||||
std::string ReplaceExtension(std::string_view path, std::string_view new_extension);
|
||||
|
||||
|
Reference in New Issue
Block a user