1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-11-01 06:47:17 +01:00

Major plugin refactor and cleanup.

Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
This commit is contained in:
Sandu Liviu Catalin
2021-01-30 08:51:39 +02:00
parent e0e34b4030
commit 4a6bfc086c
6219 changed files with 1209835 additions and 454916 deletions

View File

@@ -5,8 +5,8 @@
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(TypenameD, _SC("SqSysDir"))
SQMODE_DECL_TYPENAME(TypenameF, _SC("SqSysFile"))
SQMOD_DECL_TYPENAME(TypenameD, _SC("SqSysDir"))
SQMOD_DECL_TYPENAME(TypenameF, _SC("SqSysFile"))
// ------------------------------------------------------------------------------------------------
LightObj SysDir::ReadFile() const
@@ -68,7 +68,7 @@ LightObj SysDir::ReadFileAt(SQInteger i) const
// The file handle where it will be opened
tinydir_file * handle = ptr->GetOrMake();
// Attempt to read the current file
if (tinydir_readfile_n(mHandle.get(), handle, i) == -1)
if (tinydir_readfile_n(mHandle.get(), handle, static_cast< size_t >(i)) == -1)
{
STHROWF("Failed to read file at index (" PRINT_INT_FMT ")", i);
}

View File

@@ -1,9 +1,10 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
#include <cwchar>
#include <memory>
// ------------------------------------------------------------------------------------------------
@@ -22,7 +23,7 @@ typedef std::unique_ptr< tinydir_file > TinyFile;
class SysDir
{
// --------------------------------------------------------------------------------------------
TinyDir mHandle; /* Handle to the managed directory. */
TinyDir mHandle{}; /* Handle to the managed directory. */
public:
@@ -40,7 +41,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Make sure a valid handle is being managed before attempting to use it.
*/
void Validate(CSStr action) const
void Validate(const SQChar * action) const
{
if (!mHandle)
{
@@ -51,16 +52,11 @@ public:
/* --------------------------------------------------------------------------------------------
* Defaults to a null handle.
*/
SysDir()
: mHandle()
{
/*...*/
}
SysDir() = default;
/* --------------------------------------------------------------------------------------------
* Opens the directory at the specified path.
*/
SysDir(StackStrF & path)
explicit SysDir(StackStrF & path)
: SysDir(false, path)
{
/*...*/
@@ -100,11 +96,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
SysDir(SysDir && o)
: mHandle(std::forward< TinyDir >(o.mHandle))
{
/*...*/
}
SysDir(SysDir && o) noexcept = default;
/* --------------------------------------------------------------------------------------------
* Destructor.
@@ -126,7 +118,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
SysDir & operator = (SysDir && o)
SysDir & operator = (SysDir && o) noexcept
{
// Avoid self assignment
if (this != &o)
@@ -145,7 +137,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the raw managed handle.
*/
tinydir_dir * Get() const
SQMOD_NODISCARD tinydir_dir * Get() const
{
return mHandle.get();
}
@@ -153,7 +145,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the raw managed handle and make one if it doesn't exist already.
*/
tinydir_dir * GetOrMake()
SQMOD_NODISCARD tinydir_dir * GetOrMake()
{
// Do we have a handle already?
if (!mHandle)
@@ -167,7 +159,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Take ownership of the managed handle.
*/
tinydir_dir * Release()
SQMOD_NODISCARD tinydir_dir * Release()
{
return mHandle.release();
}
@@ -183,17 +175,21 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const
SQMOD_NODISCARD String ToString() const
{
return mHandle ? mHandle->path : _SC("");
#if defined(UNICODE) || defined(_UNICODE)
return mHandle ? String(mHandle->path, mHandle->path + std::wcslen(mHandle->path)) : _SC("");
#else
return mHandle ? String(mHandle->path) : String();
#endif
}
/* --------------------------------------------------------------------------------------------
* Check for the presence of a handle.
*/
bool IsValid() const
SQMOD_NODISCARD bool IsValid() const
{
return !!mHandle;
return static_cast< bool >(mHandle);
}
/* --------------------------------------------------------------------------------------------
@@ -215,7 +211,11 @@ public:
// If we just allocated one, we initialize it (win, either way)
tinydir_close(mHandle.get());
// Attempt to open the specified directory
#if defined(UNICODE) || defined(_UNICODE)
if (tinydir_open(mHandle.get(), std::wstring(path.mPtr, path.mPtr + path.GetSize()).c_str()) == -1)
#else
if (tinydir_open(mHandle.get(), path.mPtr) == -1)
#endif
{
// Don't keep a bad handle
mHandle.reset();
@@ -243,7 +243,11 @@ public:
// If we just allocated one, we initialize it (win, either way)
tinydir_close(mHandle.get());
// Attempt to open the specified directory
#if defined(UNICODE) || defined(_UNICODE)
if (tinydir_open_sorted(mHandle.get(), std::wstring(path.mPtr, path.mPtr + path.GetSize()).c_str()) == -1)
#else
if (tinydir_open_sorted(mHandle.get(), path.mPtr) == -1)
#endif
{
// Don't keep a bad handle
mHandle.reset();
@@ -324,17 +328,21 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the opened path.
*/
CSStr GetPath() const
SQMOD_NODISCARD String GetPath() const
{
Validate("obtain path");
// Return the requested information
return mHandle->path;
#if defined(UNICODE) || defined(_UNICODE)
return String(mHandle->path, mHandle->path + std::wcslen(mHandle->path));
#else
return String(mHandle->path);
#endif
}
/* --------------------------------------------------------------------------------------------
* See if there's a next element in the opened directory.
*/
bool HasNext() const
SQMOD_NODISCARD bool HasNext() const
{
Validate("check for next");
// Return the requested information
@@ -344,7 +352,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the number of files in the opened directory (only when opened in sorted mode).
*/
SQInteger FileCount() const
SQMOD_NODISCARD SQInteger FileCount() const
{
Validate("obtain file count");
// Return the requested information
@@ -354,11 +362,11 @@ public:
/* --------------------------------------------------------------------------------------------
* Open current file from the specified directory.
*/
LightObj ReadFile() const;
SQMOD_NODISCARD LightObj ReadFile() const;
/* --------------------------------------------------------------------------------------------
* Open current file from the specified directory.
*/
LightObj ReadFileAt(SQInteger i) const;
SQMOD_NODISCARD LightObj ReadFileAt(SQInteger i) const;
};
/* ------------------------------------------------------------------------------------------------
@@ -367,7 +375,7 @@ public:
class SysFile
{
// --------------------------------------------------------------------------------------------
TinyFile mHandle; /* Handle to the managed file. */
TinyFile mHandle{}; /* Handle to the managed file. */
public:
/* --------------------------------------------------------------------------------------------
@@ -384,7 +392,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Make sure a valid handle is being managed before attempting to use it.
*/
void Validate(CSStr action) const
void Validate(const SQChar * action) const
{
if (!mHandle)
{
@@ -395,16 +403,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Defaults to a null handle.
*/
SysFile()
: mHandle()
{
/*...*/
}
SysFile() = default;
/* --------------------------------------------------------------------------------------------
* Opens the file at the specified path.
*/
SysFile(StackStrF & path)
explicit SysFile(StackStrF & path)
: SysFile()
{
Open(path);
@@ -418,11 +422,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
SysFile(SysFile && o)
: mHandle(std::forward< TinyFile >(o.mHandle))
{
/*...*/
}
SysFile(SysFile && o) noexcept = default;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator (disabled).
@@ -432,7 +432,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
SysFile & operator = (SysFile && o)
SysFile & operator = (SysFile && o) noexcept
{
// Avoid self assignment
if (this != &o)
@@ -446,7 +446,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the raw managed handle.
*/
tinydir_file * Get() const
SQMOD_NODISCARD tinydir_file * Get() const
{
return mHandle.get();
}
@@ -454,7 +454,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the raw managed handle and make one if it doesn't exist already.
*/
tinydir_file * GetOrMake()
SQMOD_NODISCARD tinydir_file * GetOrMake()
{
// Do we have a handle already?
if (!mHandle)
@@ -468,7 +468,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Take ownership of the managed handle.
*/
tinydir_file * Release()
SQMOD_NODISCARD tinydir_file * Release()
{
return mHandle.release();
}
@@ -484,17 +484,21 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const
SQMOD_NODISCARD String ToString() const
{
return mHandle ? mHandle->path : _SC("");
#if defined(UNICODE) || defined(_UNICODE)
return mHandle ? String(mHandle->path, mHandle->path + std::wcslen(mHandle->path)) : _SC("");
#else
return mHandle ? String(mHandle->path) : String();
#endif
}
/* --------------------------------------------------------------------------------------------
* Check for the presence of a handle.
*/
bool IsValid() const
SQMOD_NODISCARD bool IsValid() const
{
return !!mHandle;
return static_cast< bool >(mHandle);
}
/* --------------------------------------------------------------------------------------------
@@ -512,7 +516,11 @@ public:
// Discard current error number
errno = 0;
// Attempt to open the specified file
#if defined(UNICODE) || defined(_UNICODE)
if (tinydir_file_open(mHandle.get(), std::wstring(path.mPtr, path.mPtr + path.GetSize()).c_str()) == -1)
#else
if (tinydir_file_open(mHandle.get(), path.mPtr) == -1)
#endif
{
// Don't keep a bad handle
mHandle.reset();
@@ -531,7 +539,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Check if the opened element is a directory.
*/
bool IsDir() const
SQMOD_NODISCARD bool IsDir() const
{
Validate("check type");
// Return the requested information
@@ -541,7 +549,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Check if the opened element is a regular file.
*/
bool IsReg() const
SQMOD_NODISCARD bool IsReg() const
{
Validate("check type");
// Return the requested information
@@ -551,31 +559,43 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieve the path of the opened file.
*/
CSStr GetPath() const
SQMOD_NODISCARD String GetPath() const
{
Validate("retrieve path");
// Return the requested information
return mHandle->path;
#if defined(UNICODE) || defined(_UNICODE)
return String(mHandle->path, mHandle->path + std::wcslen(mHandle->path));
#else
return String(mHandle->path);
#endif
}
/* --------------------------------------------------------------------------------------------
* Retrieve the name of the opened file.
*/
CSStr GetName() const
SQMOD_NODISCARD String GetName() const
{
Validate("retrieve name");
// Return the requested information
return mHandle->name;
#if defined(UNICODE) || defined(_UNICODE)
return String(mHandle->name, mHandle->name + std::wcslen(mHandle->name));
#else
return String(mHandle->name);
#endif
}
/* --------------------------------------------------------------------------------------------
* Retrieve the extension of the opened file.
*/
CSStr GetExtension() const
SQMOD_NODISCARD String GetExtension() const
{
Validate("retrieve extension");
// Return the requested information
return mHandle->extension != nullptr ? mHandle->extension : _SC("");
#if defined(UNICODE) || defined(_UNICODE)
return String(mHandle->extension, mHandle->extension + std::wcslen(mHandle->extension));
#else
return String(mHandle->name);
#endif
}
};

View File

@@ -1,11 +1,9 @@
// ------------------------------------------------------------------------------------------------
#include "Library/System/Environment.hpp"
#include "Library/System/Env.hpp"
// ------------------------------------------------------------------------------------------------
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
// ------------------------------------------------------------------------------------------------
#ifdef SQMOD_OS_WINDOWS
@@ -35,7 +33,7 @@ namespace SqMod {
#endif // SQMOD_OS_WINDOWS
// ------------------------------------------------------------------------------------------------
void SysEnv::Get(Buffer & b, CCStr name, CCStr fallback)
void SysEnv::Get(Buffer & b, const char * name, const char * fallback)
{
// Make sure the requested variable name is valid
if (name && *name != 0)
@@ -67,7 +65,7 @@ void SysEnv::Get(Buffer & b, CCStr name, CCStr fallback)
b.Advance(len);
#else
// Retrieve the pointer to the variable contents
CSStr val = getenv(name);
const SQChar * val = getenv(name);
// If the returned pointer is null then the variable doesn't exist
if (!val)
{
@@ -86,7 +84,7 @@ void SysEnv::Get(Buffer & b, CCStr name, CCStr fallback)
}
// ------------------------------------------------------------------------------------------------
bool SysEnv::Has(CCStr name)
bool SysEnv::Has(const char * name)
{
#ifdef SQMOD_OS_WINDOWS
return (GetEnvironmentVariableA(name, nullptr, 0) > 0);
@@ -106,7 +104,7 @@ bool SysEnv::Has(const String & name)
}
// ------------------------------------------------------------------------------------------------
Buffer SysEnv::Get(CCStr name, CCStr fallback)
Buffer SysEnv::Get(const char * name, const char * fallback)
{
// Allocate a moderately sized buffer
Buffer b(128);
@@ -117,7 +115,7 @@ Buffer SysEnv::Get(CCStr name, CCStr fallback)
}
// ------------------------------------------------------------------------------------------------
bool SysEnv::Set(CCStr name, CCStr value)
bool SysEnv::Set(const char * name, const char * value)
{
#ifdef SQMOD_OS_WINDOWS
// Set the specified environment variable and return the result
@@ -255,7 +253,7 @@ String SysEnv::OSVersion()
// Obtain a temporary buffer capable of holding the version string
Buffer b(128);
// The amount of data written to the buffer
Uint32 sz = 0;
uint32_t sz;
// Generate the version string with the received information
if (vi.szCSDVersion[0])
{
@@ -347,7 +345,7 @@ String SysEnv::NodeName()
}
// ------------------------------------------------------------------------------------------------
Uint32 SysEnv::ProcessorCount()
uint32_t SysEnv::ProcessorCount()
{
#ifdef SQMOD_OS_WINDOWS
// Prepare the structure in which the system information is retrieved
@@ -358,9 +356,9 @@ Uint32 SysEnv::ProcessorCount()
return si.dwNumberOfProcessors;
#elif defined(_SC_NPROCESSORS_ONLN)
// Attempt to obtain the number of processors available on the system
const Int32 count = sysconf(_SC_NPROCESSORS_ONLN);
const int32_t count = sysconf(_SC_NPROCESSORS_ONLN);
// Validate the result and return the appropriate value
return (count < 0) ? 1 : static_cast< Uint32 >(count);
return (count < 0) ? 1 : static_cast< uint32_t >(count);
#else
// Obviously at least one processor should be available
return 1;
@@ -385,7 +383,7 @@ void SysEnv::TerminatePath(Buffer & b)
}
// ------------------------------------------------------------------------------------------------
void SysEnv::ExpandVars(Buffer & b, CCStr pos, CCStr end)
void SysEnv::ExpandVars(Buffer & b, const char * pos, const char * end)
{
// Let's have a string to store the extracted variable name and value
String var;
@@ -398,7 +396,7 @@ void SysEnv::ExpandVars(Buffer & b, CCStr pos, CCStr end)
// Clear previous name, if any
var.clear();
// Where the name of the variable starts and where it ends
CCStr start = ++pos, stop = pos;
const char * start = ++pos, * stop = pos;
// Is this variable name enclosed within curly braces?
if (*start == '{')
{
@@ -463,7 +461,7 @@ void SysEnv::ExpandVars(Buffer & b, CCStr pos, CCStr end)
}
// ------------------------------------------------------------------------------------------------
void SysEnv::ExpandPath(Buffer & b, CCStr pos, CCStr end)
void SysEnv::ExpandPath(Buffer & b, const char * pos, const char * end)
{
// Does the path even contain something to be expanded?
if (pos == end || *pos == '\0')
@@ -492,7 +490,7 @@ void SysEnv::ExpandPath(Buffer & b, CCStr pos, CCStr end)
}
// ------------------------------------------------------------------------------------------------
void SysEnv::ExpandVars(Buffer & b, CCStr str)
void SysEnv::ExpandVars(Buffer & b, const char * str)
{
// Do we have anything to expand?
if (!str || *str == '\0')
@@ -506,7 +504,7 @@ void SysEnv::ExpandVars(Buffer & b, CCStr str)
return;
}
// Calculate the size of the specified string
const Uint32 len = strlen(str);
const auto len = static_cast< uint32_t >(strlen(str));
// Forward the call to the internal function
ExpandVars(b, str, str + len);
}
@@ -530,7 +528,7 @@ void SysEnv::ExpandVars(Buffer & b, const String & str)
}
// ------------------------------------------------------------------------------------------------
Buffer SysEnv::ExpandVars(CCStr str)
Buffer SysEnv::ExpandVars(const char * str)
{
// Do we have anything to expand?
if (!str || *str == '\0')
@@ -538,7 +536,7 @@ Buffer SysEnv::ExpandVars(CCStr str)
return Buffer(); // Nothing to expand!
}
// Calculate the size of the specified string
const Uint32 len = strlen(str);
const auto len = static_cast< uint32_t >(strlen(str));
// Allocate a moderately sized buffer
Buffer b(len + 128);
// Forward the call to the internal function
@@ -556,7 +554,7 @@ Buffer SysEnv::ExpandVars(const String & str)
return Buffer(); // Nothing to expand!
}
// Allocate a moderately sized buffer
Buffer b(str.size() + 128);
Buffer b(static_cast< uint32_t >(str.size() + 128));
// Forward the call to the internal function
ExpandVars(b, str.c_str(), str.c_str() + str.size());
// Return ownership of the buffer
@@ -564,7 +562,7 @@ Buffer SysEnv::ExpandVars(const String & str)
}
// ------------------------------------------------------------------------------------------------
void SysEnv::ExpandPath(Buffer & b, CCStr path)
void SysEnv::ExpandPath(Buffer & b, const char * path)
{
// Do we have anything to expand?
if (!path || *path == '\0')
@@ -578,7 +576,7 @@ void SysEnv::ExpandPath(Buffer & b, CCStr path)
return;
}
// Calculate the size of the specified string
const Uint32 len = strlen(path);
const auto len = static_cast< uint32_t >(strlen(path));
// Forward the call to the internal function
ExpandPath(b, path, path + len);
}
@@ -602,7 +600,7 @@ void SysEnv::ExpandPath(Buffer & b, const String & path)
}
// ------------------------------------------------------------------------------------------------
Buffer SysEnv::ExpandPath(CCStr path)
Buffer SysEnv::ExpandPath(const char * path)
{
// Do we have anything to expand?
if (!path || *path == '\0')
@@ -610,7 +608,7 @@ Buffer SysEnv::ExpandPath(CCStr path)
return Buffer(); // Nothing to expand!
}
// Calculate the size of the specified string
const Uint32 len = strlen(path);
const auto len = static_cast< uint32_t >(strlen(path));
// Allocate buffer capable of storing a full path
Buffer b(SQMOD_MAX_PATH);
// Forward the call to the internal function
@@ -699,7 +697,7 @@ void SysEnv::HomeDir(Buffer & b)
if (SUCCEEDED(SHGetFolderPathA(nullptr, CSIDL_PROFILE, nullptr, 0, &b.Cursor())))
{
// Move the edit cursor to the end of the appended data
b.Advance(strlen(&b.Cursor()));
b.Advance(static_cast< uint32_t >(strlen(&b.Cursor())));
}
// Try the secondary method of retrieving the home directory
else if (Has("USERPROFILE"))
@@ -821,9 +819,9 @@ void SysEnv::DataHomeDir(Buffer & b)
HomeDir(b);
// Use the home directory and append the ".local/share" sub folder
b.AppendS(".config/share");
#endif // SQMOD_OS_WINDOWS
// Make sure that the path is properly terminated
TerminatePath(b);
#endif // SQMOD_OS_WINDOWS
}
// ------------------------------------------------------------------------------------------------
@@ -914,7 +912,7 @@ void SysEnv::TempDir(Buffer & b)
// Acquire a new buffer with a more appropriate capacity this time
b.Grow(len - b.Remaining() + 2);
// Attempt to retrieve the temporary directory one more time
len = GetTempPathA(b.Remaining(), &b.Cursor());
/*len = */GetTempPathA(b.Remaining(), &b.Cursor());
// ^ On failure the null terminator is included in the length
}
// Convert the acquired path to its long form
@@ -1084,37 +1082,37 @@ Buffer SysEnv::NullDir()
}
// ------------------------------------------------------------------------------------------------
static bool SqEnv_Has(CCStr name)
static bool SqEnv_Has(const char * name)
{
return SysEnv::Has(name);
}
// ------------------------------------------------------------------------------------------------
static Object SqEnv_Get(CCStr name)
static Object SqEnv_Get(const char * name)
{
return BufferToStrObj(SysEnv::Get(name, nullptr));
}
// ------------------------------------------------------------------------------------------------
static Object SqEnv_GetOr(CCStr name, CCStr fallback)
static Object SqEnv_GetOr(const char * name, const char * fallback)
{
return BufferToStrObj(SysEnv::Get(name, fallback));
}
// ------------------------------------------------------------------------------------------------
static void SqEnv_Set(CCStr name, CCStr value)
static void SqEnv_Set(const char * name, const char * value)
{
SysEnv::Set(name, value);
}
// ------------------------------------------------------------------------------------------------
static Object SqEnv_ExpandVars(CCStr str)
static Object SqEnv_ExpandVars(const char * str)
{
return BufferToStrObj(SysEnv::ExpandVars(str));
}
// ------------------------------------------------------------------------------------------------
static Object SqEnv_ExpandPath(CCStr path)
static Object SqEnv_ExpandPath(const char * path)
{
return BufferToStrObj(SysEnv::ExpandPath(path));
}

View File

@@ -1,8 +1,8 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Base/Buffer.hpp"
#include "Core/Common.hpp"
#include "Core/Buffer.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@@ -47,7 +47,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Returns true if an environment variable with the given name is defined.
*/
static bool Has(CCStr name);
static bool Has(const char * name);
/* --------------------------------------------------------------------------------------------
* Returns true if an environment variable with the given name is defined.
@@ -58,12 +58,12 @@ public:
* Returns the value of the environment variable with the given name.
* If the environment variable is undefined, returns fallback value instead.
*/
static void Get(Buffer & b, CCStr name, CCStr fallback);
static void Get(Buffer & b, const char * name, const char * fallback);
/* --------------------------------------------------------------------------------------------
* Returns the value of the environment variable with the given name.
*/
static Buffer Get(CCStr name)
static Buffer Get(const char * name)
{
return Get(name, nullptr);
}
@@ -80,13 +80,13 @@ public:
* Returns the value of the environment variable with the given name.
* If the environment variable is undefined, returns fallback value instead.
*/
static Buffer Get(CCStr name, CCStr fallback);
static Buffer Get(const char * name, const char * fallback);
/* --------------------------------------------------------------------------------------------
* Returns the value of the environment variable with the given name.
* If the environment variable is undefined, returns fallback value instead.
*/
static Buffer Get(CCStr name, const String & fallback)
static Buffer Get(const char * name, const String & fallback)
{
return Get(name, fallback.c_str());
}
@@ -95,7 +95,7 @@ public:
* Returns the value of the environment variable with the given name.
* If the environment variable is undefined, returns fallback value instead.
*/
static Buffer Get(const String & name, CCStr fallback)
static Buffer Get(const String & name, const char * fallback)
{
return Get(name.c_str(), fallback);
}
@@ -112,7 +112,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Sets the environment variable with the given name to the given value.
*/
static bool Set(CCStr name, CCStr value);
static bool Set(const char * name, const char * value);
/* --------------------------------------------------------------------------------------------
* Sets the environment variable with the given name to the given value.
@@ -148,7 +148,7 @@ public:
* Returns the number of processors installed in the system. If the number of processors
* cannot be determined, returns 1.
*/
static Uint32 ProcessorCount();
static uint32_t ProcessorCount();
protected:
@@ -160,19 +160,19 @@ protected:
/* --------------------------------------------------------------------------------------------
* Expands all environment variables contained in the string.
*/
static void ExpandVars(Buffer & b, CCStr pos, CCStr end);
static void ExpandVars(Buffer & b, const char * pos, const char * end);
/* --------------------------------------------------------------------------------------------
* Expands all environment variables contained in the path. Uses the Unix variable style.
*/
static void ExpandPath(Buffer & b, CCStr pos, CCStr end);
static void ExpandPath(Buffer & b, const char * pos, const char * end);
public:
/* --------------------------------------------------------------------------------------------
* Expands all environment variables contained in the string.
*/
static void ExpandVars(Buffer & b, CCStr str);
static void ExpandVars(Buffer & b, const char * str);
/* --------------------------------------------------------------------------------------------
* Expands all environment variables contained in the string.
@@ -182,7 +182,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Expands all environment variables contained in the string.
*/
static Buffer ExpandVars(CCStr str);
static Buffer ExpandVars(const char * str);
/* --------------------------------------------------------------------------------------------
* Expands all environment variables contained in the string.
@@ -192,7 +192,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Expands all environment variables contained in the path. Uses the Unix variable style.
*/
static void ExpandPath(Buffer & b, CCStr path);
static void ExpandPath(Buffer & b, const char * path);
/* --------------------------------------------------------------------------------------------
* Expands all environment variables contained in the path. Uses the Unix variable style.
@@ -202,7 +202,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Expands all environment variables contained in the path. Uses the Unix variable style.
*/
static Buffer ExpandPath(CCStr path);
static Buffer ExpandPath(const char * path);
/* --------------------------------------------------------------------------------------------
* Expands all environment variables contained in the path. Uses the Unix variable style.

View File

@@ -1,13 +1,13 @@
// ------------------------------------------------------------------------------------------------
#include "Library/System/Path.hpp"
#include "Library/System/Environment.hpp"
#include "Library/System/Env.hpp"
// ------------------------------------------------------------------------------------------------
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <limits>
#include <utility>
// ------------------------------------------------------------------------------------------------
#include <sqratConst.h>
// ------------------------------------------------------------------------------------------------
#ifdef SQMOD_OS_WINDOWS
@@ -34,10 +34,10 @@ namespace SqMod {
#endif // SQMOD_OS_WINDOWS
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqSysPath"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqSysPath"))
// ------------------------------------------------------------------------------------------------
Buffer GetRealFilePath(CSStr path)
Buffer GetRealFilePath(const SQChar * path)
{
// Make sure the specified path is valid
if (!path || *path == '\0')
@@ -49,14 +49,14 @@ Buffer GetRealFilePath(CSStr path)
#ifdef SQMOD_OS_WINDOWS
// Attempt to obtain the full path to the file
DWORD ret = ::GetFullPathName(path, b.Size< PChar >(), b.Get< PChar >(), nullptr);
DWORD ret = ::GetFullPathNameA(path, b.Size< char >(), b.Get< char >(), nullptr);
// Should we allocate a bigger buffer?
if (ret > b.Size< PChar >())
{
// Grab a bigger buffer
b.Adjust(ret);
// Grab the path again
ret = GetFullPathName(path, b.Size< PChar >(), b.Get< PChar >(), nullptr);
ret = GetFullPathNameA(path, b.Size< char >(), b.Get< char >(), nullptr);
}
// Did we fail to obtain a path?
if (ret == 0 && ::GetLastError() != 0)
@@ -100,7 +100,7 @@ SysPath::SysPath(bool absolute)
}
// ------------------------------------------------------------------------------------------------
SysPath::SysPath(CSStr path)
SysPath::SysPath(const SQChar * path)
: m_Dirs()
, m_Name()
, m_Drive(0)
@@ -110,7 +110,7 @@ SysPath::SysPath(CSStr path)
}
// ------------------------------------------------------------------------------------------------
SysPath::SysPath(CSStr path, Int32 style)
SysPath::SysPath(const SQChar * path, int32_t style)
: m_Dirs()
, m_Name()
, m_Drive(0)
@@ -120,7 +120,7 @@ SysPath::SysPath(CSStr path, Int32 style)
}
// ------------------------------------------------------------------------------------------------
SysPath::SysPath(CSStr path, Style style)
SysPath::SysPath(const SQChar * path, Style style)
: m_Dirs()
, m_Name()
, m_Drive(0)
@@ -130,7 +130,7 @@ SysPath::SysPath(CSStr path, Style style)
}
// ------------------------------------------------------------------------------------------------
SysPath::SysPath(const Buffer & path, Int32 size)
SysPath::SysPath(const Buffer & path, int32_t size)
: m_Dirs()
, m_Name()
, m_Drive(0)
@@ -140,7 +140,7 @@ SysPath::SysPath(const Buffer & path, Int32 size)
}
// ------------------------------------------------------------------------------------------------
SysPath::SysPath(const Buffer & path, Style style, Int32 size)
SysPath::SysPath(const Buffer & path, Style style, int32_t size)
: m_Dirs()
, m_Name()
, m_Drive(0)
@@ -170,7 +170,7 @@ SysPath::SysPath(const String & path, Style style)
}
// ------------------------------------------------------------------------------------------------
SysPath::SysPath(const SysPath & parent, CSStr name)
SysPath::SysPath(const SysPath & parent, const SQChar * name)
: m_Dirs(parent.m_Dirs)
, m_Name(name ? name : "")
, m_Drive(parent.m_Drive)
@@ -180,7 +180,7 @@ SysPath::SysPath(const SysPath & parent, CSStr name)
}
// ------------------------------------------------------------------------------------------------
SysPath::SysPath(const SysPath & parent, const String & name)
SysPath::SysPath(const SysPath & parent, const String & name) // NOLINT(modernize-pass-by-value)
: m_Dirs(parent.m_Dirs)
, m_Name(name)
, m_Drive(parent.m_Drive)
@@ -201,63 +201,7 @@ SysPath::SysPath(const SysPath & parent, const SysPath & relative)
}
// ------------------------------------------------------------------------------------------------
SysPath::SysPath(const SysPath & o)
: m_Dirs(o.m_Dirs)
, m_Name(o.m_Name)
, m_Drive(o.m_Drive)
, m_Absolute(o.m_Absolute)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
SysPath::SysPath(SysPath && o)
: m_Dirs(std::move(o.m_Dirs))
, m_Name(std::move(o.m_Name))
, m_Drive(o.m_Drive)
, m_Absolute(o.m_Absolute)
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
SysPath::~SysPath()
{
/* ... */
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::operator = (const SysPath & o)
{
// Prevent self assignment
if (this != &o)
{
m_Dirs = o.m_Dirs;
m_Name = o.m_Name;
m_Drive = o.m_Drive;
m_Absolute = o.m_Absolute;
}
return *this;
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::operator = (SysPath && o)
{
// Prevent self assignment
if (this != &o)
{
m_Dirs = std::move(o.m_Dirs);
m_Name = std::move(o.m_Name);
m_Drive = o.m_Drive;
m_Absolute = o.m_Absolute;
}
return *this;
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::operator = (CSStr path)
SysPath & SysPath::operator = (const SQChar * path)
{
Assign(path);
return *this;
@@ -290,7 +234,7 @@ SysPath::operator bool () const
}
// ------------------------------------------------------------------------------------------------
const String & SysPath::operator [] (Uint32 n) const
const String & SysPath::operator [] (uint32_t n) const
{
// Is this within the bounds of the directory list?
if (n < m_Dirs.size())
@@ -305,7 +249,7 @@ const String & SysPath::operator [] (Uint32 n) const
}
// ------------------------------------------------------------------------------------------------
Int32 SysPath::Cmp(const SysPath & o) const
int32_t SysPath::Cmp(const SysPath & o) const
{
if (*this == o)
return 0;
@@ -340,7 +284,7 @@ void SysPath::Clear()
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::Assign(CSStr path)
SysPath & SysPath::Assign(const SQChar * path)
{
// Is the specified path valid?
if (!path || *path == '\0')
@@ -361,13 +305,13 @@ SysPath & SysPath::Assign(CSStr path)
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::Assign(CSStr path, Int32 style)
SysPath & SysPath::Assign(const SQChar * path, int32_t style)
{
return Assign(path, static_cast< Style >(style));
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::Assign(CSStr path, Style style)
SysPath & SysPath::Assign(const SQChar * path, Style style)
{
// Is the specified path valid?
if (!path || *path == '\0')
@@ -383,7 +327,7 @@ SysPath & SysPath::Assign(CSStr path, Style style)
case Style::Unix:
ParseUnix(path, path + strlen(path));
break;
case Style::Windows:
case Style::Windows: // NOLINT(bugprone-branch-clone)
ParseWindows(path, path + strlen(path));
break;
case Style::Native:
@@ -399,8 +343,6 @@ SysPath & SysPath::Assign(CSStr path, Style style)
case Style::Dynamic:
ParseDynamic(path, path + strlen(path));
break;
default:
STHROWF("Unknown system path style");
}
}
// Allow chaining
@@ -408,7 +350,7 @@ SysPath & SysPath::Assign(CSStr path, Style style)
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::Assign(const Buffer & path, Int32 size)
SysPath & SysPath::Assign(const Buffer & path, int32_t size)
{
// Is the specified path valid?
if (!path)
@@ -424,7 +366,7 @@ SysPath & SysPath::Assign(const Buffer & path, Int32 size)
ParseUnix(path.Data(), &path.Cursor());
#endif // SQMOD_OS_WINDOWS
}
else if (static_cast< Uint32 >(size) < path.Capacity())
else if (static_cast< uint32_t >(size) < path.Capacity())
{
#ifdef SQMOD_OS_WINDOWS
ParseWindows(path.Data(), path.Data() + size);
@@ -441,7 +383,7 @@ SysPath & SysPath::Assign(const Buffer & path, Int32 size)
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::Assign(const Buffer & path, Style style, Int32 size)
SysPath & SysPath::Assign(const Buffer & path, Style style, int32_t size)
{
// Is the specified path valid?
if (!path)
@@ -457,7 +399,7 @@ SysPath & SysPath::Assign(const Buffer & path, Style style, Int32 size)
case Style::Unix:
ParseUnix(path.Data(), &path.Cursor());
break;
case Style::Windows:
case Style::Windows: // NOLINT(bugprone-branch-clone)
ParseWindows(path.Data(), &path.Cursor());
break;
case Style::Native:
@@ -473,11 +415,9 @@ SysPath & SysPath::Assign(const Buffer & path, Style style, Int32 size)
case Style::Dynamic:
ParseDynamic(path.Data(), &path.Cursor());
break;
default:
STHROWF("Unknown system path style");
}
}
else if (static_cast< Uint32 >(size) < path.Capacity())
else if (static_cast< uint32_t >(size) < path.Capacity())
{
// Identify which style was requested
switch (style)
@@ -485,7 +425,7 @@ SysPath & SysPath::Assign(const Buffer & path, Style style, Int32 size)
case Style::Unix:
ParseUnix(path.Data(), path.Data() + size);
break;
case Style::Windows:
case Style::Windows: // NOLINT(bugprone-branch-clone)
ParseWindows(path.Data(), path.Data() + size);
break;
case Style::Native:
@@ -501,8 +441,6 @@ SysPath & SysPath::Assign(const Buffer & path, Style style, Int32 size)
case Style::Dynamic:
ParseDynamic(path.Data(), path.Data() + size);
break;
default:
STHROWF("Unknown system path style");
}
}
else
@@ -551,7 +489,7 @@ SysPath & SysPath::Assign(const String & path, Style style)
case Style::Unix:
ParseUnix(path.data(), path.data() + path.size());
break;
case Style::Windows:
case Style::Windows: // NOLINT(bugprone-branch-clone)
ParseWindows(path.data(), path.data() + path.size());
break;
case Style::Native:
@@ -567,8 +505,6 @@ SysPath & SysPath::Assign(const String & path, Style style)
case Style::Dynamic:
ParseDynamic(path.data(), path.data() + path.size());
break;
default:
STHROWF("Unknown system path style");
}
}
// Allow chaining
@@ -576,7 +512,7 @@ SysPath & SysPath::Assign(const String & path, Style style)
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::Assign(const SysPath & parent, CSStr name)
SysPath & SysPath::Assign(const SysPath & parent, const SQChar * name)
{
// Copy the parent values
*this = parent;
@@ -627,7 +563,7 @@ SysPath & SysPath::Assign(SysPath && path)
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::AssignDir(CSStr path)
SysPath & SysPath::AssignDir(const SQChar * path)
{
// Assign the specified path
Assign(path);
@@ -636,7 +572,7 @@ SysPath & SysPath::AssignDir(CSStr path)
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::AssignDir(CSStr path, Int32 style)
SysPath & SysPath::AssignDir(const SQChar * path, int32_t style)
{
// Assign the specified path
Assign(path, style);
@@ -645,7 +581,7 @@ SysPath & SysPath::AssignDir(CSStr path, Int32 style)
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::AssignDir(CSStr path, Style style)
SysPath & SysPath::AssignDir(const SQChar * path, Style style)
{
// Assign the specified path
Assign(path, style);
@@ -654,7 +590,7 @@ SysPath & SysPath::AssignDir(CSStr path, Style style)
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::AssignDir(const Buffer & path, Int32 size)
SysPath & SysPath::AssignDir(const Buffer & path, int32_t size)
{
// Assign the specified path
Assign(path, size);
@@ -663,7 +599,7 @@ SysPath & SysPath::AssignDir(const Buffer & path, Int32 size)
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::AssignDir(const Buffer & path, Style style, Int32 size)
SysPath & SysPath::AssignDir(const Buffer & path, Style style, int32_t size)
{
// Assign the specified path
Assign(path, style, size);
@@ -718,13 +654,13 @@ Buffer SysPath::ToBuffer(Style style) const
}
// ------------------------------------------------------------------------------------------------
Object SysPath::ToStr(Int32 style) const
Object SysPath::ToStr(int32_t style) const
{
return BufferToStrObj(ToBuffer(static_cast< Style >(style)));
}
// ------------------------------------------------------------------------------------------------
void SysPath::FromString(CSStr path)
void SysPath::FromString(const SQChar * path)
{
Assign(path);
}
@@ -776,7 +712,7 @@ SysPath & SysPath::MakeParent()
else
{
// Are we already referencing a parent?
if (m_Dirs.back().compare("..") == 0)
if (m_Dirs.back().compare("..") == 0) // NOLINT(readability-string-compare)
{
// Then reference the parent of that parent
m_Dirs.emplace_back("..");
@@ -885,31 +821,31 @@ SysPath & SysPath::Append(SysPath && path)
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::Append(CSStr path)
SysPath & SysPath::Append(const SQChar * path)
{
return Append(SysPath(path));
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::Append(CSStr path, Int32 style)
SysPath & SysPath::Append(const SQChar * path, int32_t style)
{
return Append(SysPath(path, style));
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::Append(CSStr path, Style style)
SysPath & SysPath::Append(const SQChar * path, Style style)
{
return Append(SysPath(path, style));
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::Append(const Buffer & path, Int32 size)
SysPath & SysPath::Append(const Buffer & path, int32_t size)
{
return Append(SysPath(path, size));
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::Append(const Buffer & path, Style style, Int32 size)
SysPath & SysPath::Append(const Buffer & path, Style style, int32_t size)
{
return Append(SysPath(path, style, size));
}
@@ -927,7 +863,7 @@ SysPath & SysPath::Append(const String & path, Style style)
}
// ------------------------------------------------------------------------------------------------
const String & SysPath::Directory(Uint32 n) const
const String & SysPath::Directory(uint32_t n) const
{
// Is this within the bounds of the directory list?
if (n < m_Dirs.size())
@@ -942,7 +878,7 @@ const String & SysPath::Directory(Uint32 n) const
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::Push(CSStr dir)
SysPath & SysPath::Push(const SQChar * dir)
{
// Is the specified directory valid?
if (dir && *dir != 0)
@@ -957,7 +893,7 @@ SysPath & SysPath::Push(CSStr dir)
SysPath & SysPath::Push(const String & dir)
{
// Is the specified directory valid?
if (!dir.empty() && dir.compare(".") != 0)
if (!dir.empty() && dir.compare(".") != 0) // NOLINT(readability-string-compare)
{
Push(String(dir));
}
@@ -969,13 +905,13 @@ SysPath & SysPath::Push(const String & dir)
SysPath & SysPath::Push(String && dir)
{
// Is the specified directory valid?
if (!dir.empty() && dir.compare(".") != 0)
if (!dir.empty() && dir.compare(".") != 0) // NOLINT(readability-string-compare)
{
// Does it refer to a parent directory?
if (dir.compare("..") == 0)
if (dir.compare("..") == 0) // NOLINT(readability-string-compare)
{
// Is our last directory already a reference to a parent?
if (!m_Dirs.empty() && m_Dirs.back().compare("..") != 0)
if (!m_Dirs.empty() && m_Dirs.back().compare("..") != 0) // NOLINT(readability-string-compare)
{
m_Dirs.pop_back();
}
@@ -1022,7 +958,7 @@ SysPath & SysPath::PopFront()
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::SetFilename(CSStr name)
SysPath & SysPath::SetFilename(const SQChar * name)
{
// Is the file name even valid?
if (name)
@@ -1052,7 +988,7 @@ SysPath & SysPath::SetFilename(String && name)
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::SetBasename(CSStr name)
SysPath & SysPath::SetBasename(const SQChar * name)
{
// Is the file name even valid?
if (name)
@@ -1128,7 +1064,7 @@ String SysPath::GetBasename() const
}
// ------------------------------------------------------------------------------------------------
SysPath & SysPath::SetExtension(CSStr ext)
SysPath & SysPath::SetExtension(const SQChar * ext)
{
// Attempt to find the last dot in the file name
const String::size_type pos = m_Name.rfind('.');
@@ -1185,7 +1121,7 @@ String SysPath::GetExtension() const
}
// ------------------------------------------------------------------------------------------------
CSStr SysPath::GetExtensionC() const
const SQChar * SysPath::GetExtensionC() const
{
// Attempt to find the last dot in the file name
const String::size_type pos = m_Name.rfind('.');
@@ -1234,7 +1170,7 @@ SysPath & SysPath::Resolve(const SysPath & path)
}
// ------------------------------------------------------------------------------------------------
void SysPath::ParseUnix(CSStr pos, CSStr end)
void SysPath::ParseUnix(const SQChar * pos, const SQChar * end)
{
// Clear previous path information
Clear();
@@ -1271,7 +1207,7 @@ void SysPath::ParseUnix(CSStr pos, CSStr end)
}
}
// Make another iterator to slice directory names in one go
CSStr itr = pos;
const SQChar * itr = pos;
// Extract the remaining directories from the specified path
while (itr != end)
{
@@ -1299,7 +1235,7 @@ void SysPath::ParseUnix(CSStr pos, CSStr end)
}
// ------------------------------------------------------------------------------------------------
void SysPath::ParseWindows(CSStr pos, CSStr end)
void SysPath::ParseWindows(const SQChar * pos, const SQChar * end)
{
// Clear previous path information
Clear();
@@ -1354,7 +1290,7 @@ void SysPath::ParseWindows(CSStr pos, CSStr end)
return;
}
// Make another iterator to slice directory names in one go
CSStr itr = pos;
const SQChar * itr = pos;
// Extract the remaining directories from the specified path
while (itr != end)
{
@@ -1382,7 +1318,7 @@ void SysPath::ParseWindows(CSStr pos, CSStr end)
}
// ------------------------------------------------------------------------------------------------
void SysPath::ParseDynamic(CSStr pos, CSStr end)
void SysPath::ParseDynamic(const SQChar * pos, const SQChar * end)
{
// Clear previous path information
Clear();
@@ -1443,7 +1379,7 @@ void SysPath::ParseDynamic(CSStr pos, CSStr end)
}
#endif // SQMOD_OS_WINDOWS
// Make another iterator to slice directory names in one go
CSStr itr = pos;
const SQChar * itr = pos;
// Extract the remaining directories from the specified path
while (itr != end)
{
@@ -1471,14 +1407,14 @@ void SysPath::ParseDynamic(CSStr pos, CSStr end)
}
// ------------------------------------------------------------------------------------------------
void SysPath::ParseGuess(CSStr pos, CSStr end)
void SysPath::ParseGuess(const SQChar * pos, const SQChar * end)
{
// Scan for forward slash
const bool has_fwslash = (strchr(pos, '/') != NULL);
const bool has_bwslash = (strchr(pos, '\\') != NULL);
const bool has_fwslash = (strchr(pos, '/') != nullptr);
const bool has_bwslash = (strchr(pos, '\\') != nullptr);
// Does it contain both forward and backward slashes?
if (has_fwslash && has_bwslash)
{
{ // NOLINT(bugprone-branch-clone)
ParseDynamic(pos, end);
}
// Does it contain the forward slash?
@@ -1488,7 +1424,7 @@ void SysPath::ParseGuess(CSStr pos, CSStr end)
}
// Does it contain the backward slash?
else if (has_bwslash)
{
{ // NOLINT(bugprone-branch-clone)
ParseWindows(pos, end);
}
// Does it contain a drive letter?
@@ -1518,14 +1454,14 @@ Buffer SysPath::BuildUnix() const
for (const auto & dir : m_Dirs)
{
// Append the name
b.AppendS(dir.c_str(), dir.size());
b.AppendS(dir.c_str(), static_cast< uint32_t >(dir.size()));
// Separate from next
b.Push('/');
}
// Is there a file name to add?
if (!m_Name.empty())
{
b.AppendS(m_Name.c_str(), m_Name.size());
b.AppendS(m_Name.c_str(), static_cast< uint32_t >(m_Name.size()));
}
// Make sure the string is null terminated
b.Cursor() = '\0';
@@ -1558,14 +1494,14 @@ Buffer SysPath::BuildWindows() const
for (const auto & dir : m_Dirs)
{
// Append the name
b.AppendS(dir.c_str(), dir.size());
b.AppendS(dir.c_str(), static_cast< uint32_t >(dir.size()));
// Separate from next
b.Push('\\');
}
// Is there a file name to add?
if (!m_Name.empty())
{
b.AppendS(m_Name.c_str(), m_Name.size());
b.AppendS(m_Name.c_str(), static_cast< uint32_t >(m_Name.size()));
}
// Make sure the string is null terminated
b.Cursor() = '\0';
@@ -1574,19 +1510,19 @@ Buffer SysPath::BuildWindows() const
}
// ------------------------------------------------------------------------------------------------
SysPath SysPath::ForDirectory(CSStr path)
SysPath SysPath::ForDirectory(const SQChar * path)
{
return SysPath(path).MakeDirectory();
}
// ------------------------------------------------------------------------------------------------
SysPath SysPath::ForDirectory(CSStr path, Int32 style)
SysPath SysPath::ForDirectory(const SQChar * path, int32_t style)
{
return SysPath(path, style).MakeDirectory();
}
// ------------------------------------------------------------------------------------------------
SysPath SysPath::ForDirectory(CSStr path, Style style)
SysPath SysPath::ForDirectory(const SQChar * path, Style style)
{
return SysPath(path, style).MakeDirectory();
}
@@ -1604,7 +1540,7 @@ SysPath SysPath::ForDirectory(const String & path, Style style)
}
// ------------------------------------------------------------------------------------------------
SysPath SysPath::Expand(CSStr path)
SysPath SysPath::Expand(const SQChar * path)
{
return SysPath(SysEnv::ExpandPath(path));
}
@@ -1670,43 +1606,43 @@ SysPath SysPath::Null()
}
// ------------------------------------------------------------------------------------------------
SysPath SysPath::Real(CSStr path)
SysPath SysPath::Real(const SQChar * path)
{
return SysPath(GetRealFilePath(path));
}
// ------------------------------------------------------------------------------------------------
SysPath SysPath::With(const SysPath & parent, CSStr name)
SysPath SysPath::With(const SysPath & parent, const SQChar * name)
{
return SysPath(parent, name);
}
// ------------------------------------------------------------------------------------------------
SysPath SysPath::MakeUnix(CSStr path)
SysPath SysPath::MakeUnix(const SQChar * path)
{
return SysPath(path, Style::Unix);
}
// ------------------------------------------------------------------------------------------------
SysPath SysPath::MakeWindows(CSStr path)
SysPath SysPath::MakeWindows(const SQChar * path)
{
return SysPath(path, Style::Windows);
}
// ------------------------------------------------------------------------------------------------
SysPath SysPath::MakeNative(CSStr path)
SysPath SysPath::MakeNative(const SQChar * path)
{
return SysPath(path, Style::Native);
}
// ------------------------------------------------------------------------------------------------
SysPath SysPath::MakeGuess(CSStr path)
SysPath SysPath::MakeGuess(const SQChar * path)
{
return SysPath(path, Style::Guess);
}
// ------------------------------------------------------------------------------------------------
SysPath SysPath::MakeDynamic(CSStr path)
SysPath SysPath::MakeDynamic(const SQChar * path)
{
return SysPath(path, Style::Dynamic);
}
@@ -1725,8 +1661,8 @@ String SysPath::NormalizePath(SQInteger s, StackStrF & val)
return String();
}
// Turn it into a string that we can edit
String str(val.mPtr, val.mLen);
// Replace all occurences of the specified character
String str(val.mPtr, static_cast< size_t >(val.mLen));
// Replace all occurrences of the specified character
for (String::reference c : str)
{
if (c == '/' || c == '\\')
@@ -1744,8 +1680,8 @@ void Register_SysPath(HSQUIRRELVM vm)
Class< SysPath >(vm, Typename::Str)
// Constructors
.Ctor()
.Ctor< CSStr >()
.Ctor< CSStr, Int32 >()
.Ctor< const SQChar * >()
.Ctor< const SQChar *, int32_t >()
// Meta-methods
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
.Func(_SC("_tostring"), &SysPath::ToString)
@@ -1779,29 +1715,29 @@ void Register_SysPath(HSQUIRRELVM vm)
.Func(_SC("MakeParent"), &SysPath::MakeParent)
.Func(_SC("Dir"), &SysPath::Directory)
.Func(_SC("Directory"), &SysPath::Directory)
.Func< SysPath & (SysPath::*)(CSStr) >(_SC("Push"), &SysPath::Push)
.Func< SysPath & (SysPath::*)(const SQChar *) >(_SC("Push"), &SysPath::Push)
.Func(_SC("PopBack"), &SysPath::PopBack)
.Func(_SC("PopFront"), &SysPath::PopFront)
.Func< SysPath & (SysPath::*)(CSStr) >(_SC("SetFilename"), &SysPath::SetFilename)
.Func< SysPath & (SysPath::*)(const SQChar *) >(_SC("SetFilename"), &SysPath::SetFilename)
.Func(_SC("GetFilename"), &SysPath::GetFilename)
.Func< SysPath & (SysPath::*)(CSStr) >(_SC("SetBasename"), &SysPath::SetBasename)
.Func< SysPath & (SysPath::*)(const SQChar *) >(_SC("SetBasename"), &SysPath::SetBasename)
.Func(_SC("GetBasename"), &SysPath::GetBasename)
.Func< SysPath & (SysPath::*)(CSStr) >(_SC("SetExtension"), &SysPath::SetExtension)
.Func< SysPath & (SysPath::*)(const SQChar *) >(_SC("SetExtension"), &SysPath::SetExtension)
.Func(_SC("GetExtension"), &SysPath::GetExtension)
.Func(_SC("Resolve"), &SysPath::Resolve)
// Member Overloads
.Overload< SysPath & (SysPath::*)(CSStr) >(_SC("Assign"), &SysPath::Assign)
.Overload< SysPath & (SysPath::*)(CSStr, Int32) >(_SC("Assign"), &SysPath::Assign)
.Overload< SysPath & (SysPath::*)(CSStr) >(_SC("AssignDir"), &SysPath::AssignDir)
.Overload< SysPath & (SysPath::*)(CSStr, Int32) >(_SC("AssignDir"), &SysPath::AssignDir)
.Overload< SysPath & (SysPath::*)(CSStr) >(_SC("Append"), &SysPath::Append)
.Overload< SysPath & (SysPath::*)(CSStr, Int32) >(_SC("Append"), &SysPath::Append)
.Overload< SysPath & (SysPath::*)(const SQChar *) >(_SC("Assign"), &SysPath::Assign)
.Overload< SysPath & (SysPath::*)(const SQChar *, int32_t) >(_SC("Assign"), &SysPath::Assign)
.Overload< SysPath & (SysPath::*)(const SQChar *) >(_SC("AssignDir"), &SysPath::AssignDir)
.Overload< SysPath & (SysPath::*)(const SQChar *, int32_t) >(_SC("AssignDir"), &SysPath::AssignDir)
.Overload< SysPath & (SysPath::*)(const SQChar *) >(_SC("Append"), &SysPath::Append)
.Overload< SysPath & (SysPath::*)(const SQChar *, int32_t) >(_SC("Append"), &SysPath::Append)
.Overload< SysPath & (SysPath::*)(void) >(_SC("MakeAbsolute"), &SysPath::MakeAbsolute)
.Overload< SysPath & (SysPath::*)(const SysPath &) >(_SC("MakeAbsolute"), &SysPath::MakeAbsolute)
// Static Functions
.StaticFunc(_SC("Separator"), &SysPath::Separator)
.StaticFunc(_SC("PathSeparator"), &SysPath::PathSeparator)
.StaticFunc< SysPath (*)(CSStr) >(_SC("Expand"), &SysPath::Expand)
.StaticFunc< SysPath (*)(const SQChar *) >(_SC("Expand"), &SysPath::Expand)
.StaticFunc(_SC("Home"), &SysPath::Home)
.StaticFunc(_SC("ConfigHome"), &SysPath::ConfigHome)
.StaticFunc(_SC("DataHome"), &SysPath::DataHome)
@@ -1822,18 +1758,18 @@ void Register_SysPath(HSQUIRRELVM vm)
.StaticFunc(_SC("Dynamic"), &SysPath::MakeDynamic)
.StaticFmtFunc(_SC("Normalize"), &SysPath::NormalizePath)
// Static Overloads
.StaticOverload< SysPath (*)(CSStr) >(_SC("ForDir"), &SysPath::ForDirectory)
.StaticOverload< SysPath (*)(CSStr, Int32) >(_SC("ForDir"), &SysPath::ForDirectory)
.StaticOverload< SysPath (*)(CSStr) >(_SC("ForDirectory"), &SysPath::ForDirectory)
.StaticOverload< SysPath (*)(CSStr, Int32) >(_SC("ForDirectory"), &SysPath::ForDirectory)
.StaticOverload< SysPath (*)(const SQChar *) >(_SC("ForDir"), &SysPath::ForDirectory)
.StaticOverload< SysPath (*)(const SQChar *, int32_t) >(_SC("ForDir"), &SysPath::ForDirectory)
.StaticOverload< SysPath (*)(const SQChar *) >(_SC("ForDirectory"), &SysPath::ForDirectory)
.StaticOverload< SysPath (*)(const SQChar *, int32_t) >(_SC("ForDirectory"), &SysPath::ForDirectory)
);
ConstTable(vm).Enum(_SC("SqSysPathStyle"), Enumeration(vm)
.Const(_SC("Unix"), static_cast< Int32 >(SysPath::Style::Unix))
.Const(_SC("Windows"), static_cast< Int32 >(SysPath::Style::Windows))
.Const(_SC("Native"), static_cast< Int32 >(SysPath::Style::Native))
.Const(_SC("Guess"), static_cast< Int32 >(SysPath::Style::Guess))
.Const(_SC("Dynamic"), static_cast< Int32 >(SysPath::Style::Dynamic))
.Const(_SC("Unix"), static_cast< int32_t >(SysPath::Style::Unix))
.Const(_SC("Windows"), static_cast< int32_t >(SysPath::Style::Windows))
.Const(_SC("Native"), static_cast< int32_t >(SysPath::Style::Native))
.Const(_SC("Guess"), static_cast< int32_t >(SysPath::Style::Guess))
.Const(_SC("Dynamic"), static_cast< int32_t >(SysPath::Style::Dynamic))
);
}

View File

@@ -1,7 +1,7 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Core/Common.hpp"
// ------------------------------------------------------------------------------------------------
#include <vector>
@@ -12,7 +12,7 @@ namespace SqMod {
/* ------------------------------------------------------------------------------------------------
* Retrieve the full path of file.
*/
Buffer GetRealFilePath(CSStr path);
Buffer GetRealFilePath(const SQChar * path);
/* ------------------------------------------------------------------------------------------------
* This class represents filesystem paths in a platform-independent manner.
@@ -44,37 +44,37 @@ public:
/* --------------------------------------------------------------------------------------------
* Creates an empty absolute or relative path.
*/
SysPath(bool absolute);
explicit SysPath(bool absolute);
/* --------------------------------------------------------------------------------------------
* Creates a path in native format from a string.
*/
SysPath(CSStr path);
explicit SysPath(const SQChar * path);
/* --------------------------------------------------------------------------------------------
* Creates a path from a string.
*/
SysPath(CSStr path, Int32 style);
SysPath(const SQChar * path, int32_t style);
/* --------------------------------------------------------------------------------------------
* Creates a path from a string.
*/
SysPath(CSStr path, Style style);
SysPath(const SQChar * path, Style style);
/* --------------------------------------------------------------------------------------------
* Creates a path in native format from a string.
*/
SysPath(const Buffer & path, Int32 size = -1);
explicit SysPath(const Buffer & path, int32_t size = -1);
/* --------------------------------------------------------------------------------------------
* Creates a path from a string.
*/
SysPath(const Buffer & path, Style style, Int32 size = -1);
SysPath(const Buffer & path, Style style, int32_t size = -1);
/* --------------------------------------------------------------------------------------------
* Creates a path in native format from a string.
*/
SysPath(const String & path);
explicit SysPath(const String & path);
/* --------------------------------------------------------------------------------------------
* Creates a path from a string.
@@ -85,7 +85,7 @@ public:
* Creates a path from a parent path and a file name. The parent path is expected to reference
* a directory.
*/
SysPath(const SysPath & parent, CSStr name);
SysPath(const SysPath & parent, const SQChar * name);
/* --------------------------------------------------------------------------------------------
* Creates a path from a parent path and a file name. The parent path is expected to reference
@@ -102,32 +102,32 @@ public:
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
SysPath(const SysPath & o);
SysPath(const SysPath & o) = default;
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
SysPath(SysPath && o);
SysPath(SysPath && o) noexcept = default;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~SysPath();
~SysPath() = default;
/* --------------------------------------------------------------------------------------------
* Copy assignment operator.
*/
SysPath & operator = (const SysPath & o);
SysPath & operator = (const SysPath & o) = default;
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
SysPath & operator = (SysPath && o);
SysPath & operator = (SysPath && o) noexcept = default;
/* --------------------------------------------------------------------------------------------
* Assigns a string containing a path in native format.
*/
SysPath & operator = (CSStr path);
SysPath & operator = (const SQChar * path);
/* --------------------------------------------------------------------------------------------
* Assigns a string containing a path in native format.
@@ -147,22 +147,22 @@ public:
/* --------------------------------------------------------------------------------------------
* Implicit conversion to boolean operator.
*/
operator bool () const;
operator bool () const; // NOLINT(google-explicit-constructor)
/* --------------------------------------------------------------------------------------------
* Returns the n'th directory in the directory list. If n == depth(), returns the file name.
*/
const String & operator [] (Uint32 n) const;
const String & operator [] (uint32_t n) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const SysPath & o) const;
SQMOD_NODISCARD int32_t Cmp(const SysPath & o) const;
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
Object ToString() const;
SQMOD_NODISCARD Object ToString() const;
/* --------------------------------------------------------------------------------------------
* Swaps the path with another one.
@@ -177,27 +177,27 @@ public:
/* --------------------------------------------------------------------------------------------
* Assigns a string containing a path in native format.
*/
SysPath & Assign(CSStr path);
SysPath & Assign(const SQChar * path);
/* --------------------------------------------------------------------------------------------
* Assigns a string containing a path.
*/
SysPath & Assign(CSStr path, Int32 style);
SysPath & Assign(const SQChar * path, int32_t style);
/* --------------------------------------------------------------------------------------------
* Assigns a string containing a path.
*/
SysPath & Assign(CSStr path, Style style);
SysPath & Assign(const SQChar * path, Style style);
/* --------------------------------------------------------------------------------------------
* Assigns a string containing a path in native format.
*/
SysPath & Assign(const Buffer & path, Int32 size = -1);
SysPath & Assign(const Buffer & path, int32_t size = -1);
/* --------------------------------------------------------------------------------------------
* Assigns a string containing a path.
*/
SysPath & Assign(const Buffer & path, Style style, Int32 size = -1);
SysPath & Assign(const Buffer & path, Style style, int32_t size = -1);
/* --------------------------------------------------------------------------------------------
* Assigns a string containing a path in native format.
@@ -213,7 +213,7 @@ public:
* Creates a path from a parent path and a file name. The parent path is expected to reference
* a directory.
*/
SysPath & Assign(const SysPath & parent, CSStr name);
SysPath & Assign(const SysPath & parent, const SQChar * name);
/* --------------------------------------------------------------------------------------------
* Creates a path from a parent path and a file name. The parent path is expected to reference
@@ -240,27 +240,27 @@ public:
/* --------------------------------------------------------------------------------------------
* The resulting path always refers to a directory and the filename part is empty.
*/
SysPath & AssignDir(CSStr path);
SysPath & AssignDir(const SQChar * path);
/* --------------------------------------------------------------------------------------------
* The resulting path always refers to a directory and the filename part is empty.
*/
SysPath & AssignDir(CSStr path, Int32 style);
SysPath & AssignDir(const SQChar * path, int32_t style);
/* --------------------------------------------------------------------------------------------
* The resulting path always refers to a directory and the filename part is empty.
*/
SysPath & AssignDir(CSStr path, Style style);
SysPath & AssignDir(const SQChar * path, Style style);
/* --------------------------------------------------------------------------------------------
* The resulting path always refers to a directory and the filename part is empty.
*/
SysPath & AssignDir(const Buffer & path, Int32 size = -1);
SysPath & AssignDir(const Buffer & path, int32_t size = -1);
/* --------------------------------------------------------------------------------------------
* The resulting path always refers to a directory and the filename part is empty.
*/
SysPath & AssignDir(const Buffer & path, Style style, Int32 size = -1);
SysPath & AssignDir(const Buffer & path, Style style, int32_t size = -1);
/* --------------------------------------------------------------------------------------------
* The resulting path always refers to a directory and the filename part is empty.
@@ -275,27 +275,27 @@ public:
/* --------------------------------------------------------------------------------------------
* Returns a string containing the path in native format.
*/
Buffer ToBuffer() const;
SQMOD_NODISCARD Buffer ToBuffer() const;
/* --------------------------------------------------------------------------------------------
* Returns a string containing the path in the given format.
*/
Buffer ToBuffer(Style style) const;
SQMOD_NODISCARD Buffer ToBuffer(Style style) const;
/* --------------------------------------------------------------------------------------------
* Returns a string containing the path in the given format.
*/
Object ToStr(Int32 style) const;
SQMOD_NODISCARD Object ToStr(int32_t style) const;
/* --------------------------------------------------------------------------------------------
* Assigns a string containing a path.
*/
void FromString(CSStr path);
void FromString(const SQChar * path);
/* --------------------------------------------------------------------------------------------
* See whether the path is absolute.
*/
bool IsAbsolute() const
SQMOD_NODISCARD bool IsAbsolute() const
{
return m_Absolute;
}
@@ -303,7 +303,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the path is relative.
*/
bool IsRelative() const
SQMOD_NODISCARD bool IsRelative() const
{
return !m_Absolute;
}
@@ -311,7 +311,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the path references a directory.
*/
bool IsDirectory() const
SQMOD_NODISCARD bool IsDirectory() const
{
return m_Name.empty();
}
@@ -319,7 +319,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the path references a file.
*/
bool IsFile() const
SQMOD_NODISCARD bool IsFile() const
{
return !m_Name.empty();
}
@@ -327,7 +327,7 @@ public:
/* --------------------------------------------------------------------------------------------
* See whether the path Does not contain a drive, directories or file name.
*/
bool Empty() const
SQMOD_NODISCARD bool Empty() const
{
return (m_Dirs.empty() && m_Name.empty() && m_Drive == 0);
}
@@ -376,27 +376,27 @@ public:
/* --------------------------------------------------------------------------------------------
* Parse the given string and append the resulted path.
*/
SysPath & Append(CSStr path);
SysPath & Append(const SQChar * path);
/* --------------------------------------------------------------------------------------------
* Parse the given string and append the resulted path.
*/
SysPath & Append(CSStr path, Int32 style);
SysPath & Append(const SQChar * path, int32_t style);
/* --------------------------------------------------------------------------------------------
* Parse the given string and append the resulted path.
*/
SysPath & Append(CSStr path, Style style);
SysPath & Append(const SQChar * path, Style style);
/* --------------------------------------------------------------------------------------------
* Parse the given string and append the resulted path.
*/
SysPath & Append(const Buffer & path, Int32 size = -1);
SysPath & Append(const Buffer & path, int32_t size = -1);
/* --------------------------------------------------------------------------------------------
* Parse the given string and append the resulted path.
*/
SysPath & Append(const Buffer & path, Style style, Int32 size = -1);
SysPath & Append(const Buffer & path, Style style, int32_t size = -1);
/* --------------------------------------------------------------------------------------------
* Parse the given string and append the resulted path.
@@ -411,7 +411,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Returns the drive letter.
*/
CharT GetDrive() const
SQMOD_NODISCARD CharT GetDrive() const
{
return m_Drive;
}
@@ -427,20 +427,20 @@ public:
/* --------------------------------------------------------------------------------------------
* Returns the number of directories in the directory list.
*/
Uint32 Depth() const
SQMOD_NODISCARD uint32_t Depth() const
{
return m_Dirs.size();
return static_cast< uint32_t >(m_Dirs.size());
}
/* --------------------------------------------------------------------------------------------
* Returns the n'th directory in the directory list. If n == depth(), returns the file name.
*/
const String & Directory(Uint32 n) const;
SQMOD_NODISCARD const String & Directory(uint32_t n) const;
/* --------------------------------------------------------------------------------------------
* Adds a directory to the directory list.
*/
SysPath & Push(CSStr dir);
SysPath & Push(const SQChar * dir);
/* --------------------------------------------------------------------------------------------
* Adds a directory to the directory list.
@@ -465,7 +465,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Set the specified file name.
*/
SysPath & SetFilename(CSStr name);
SysPath & SetFilename(const SQChar * name);
/* --------------------------------------------------------------------------------------------
* Set the specified file name.
@@ -480,7 +480,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Retrieves the file name.
*/
const String & GetFilename() const
SQMOD_NODISCARD const String & GetFilename() const
{
return m_Name;
}
@@ -488,7 +488,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Set the specified file name.
*/
void SqSetFilename(CSStr name)
void SqSetFilename(const SQChar * name)
{
SetFilename(name);
}
@@ -496,7 +496,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Sets the basename part of the file name and does not change the extension.
*/
SysPath & SetBasename(CSStr name);
SysPath & SetBasename(const SQChar * name);
/* --------------------------------------------------------------------------------------------
* Sets the basename part of the file name and does not change the extension.
@@ -511,12 +511,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Returns the basename (the file name without extension) of the path.
*/
String GetBasename() const;
SQMOD_NODISCARD String GetBasename() const;
/* --------------------------------------------------------------------------------------------
* Sets the basename part of the file name and does not change the extension.
*/
void SqSetBasename(CSStr name)
void SqSetBasename(const SQChar * name)
{
SetBasename(name);
}
@@ -524,7 +524,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Sets the file name extension.
*/
SysPath & SetExtension(CSStr ext);
SysPath & SetExtension(const SQChar * ext);
/* --------------------------------------------------------------------------------------------
* Sets the file name extension.
@@ -534,12 +534,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Returns the file name extension.
*/
String GetExtension() const;
SQMOD_NODISCARD String GetExtension() const;
/* --------------------------------------------------------------------------------------------
* Sets the file name extension.
*/
void SqSetExtension(CSStr ext)
void SqSetExtension(const SQChar * ext)
{
SetExtension(ext);
}
@@ -547,12 +547,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Returns a pointer to the internal name string where the extension starts.
*/
CSStr GetExtensionC() const;
SQMOD_NODISCARD const SQChar * GetExtensionC() const;
/* --------------------------------------------------------------------------------------------
* Returns a path referring to the path's directory.
*/
SysPath Parent() const;
SQMOD_NODISCARD SysPath Parent() const;
/* --------------------------------------------------------------------------------------------
* Resolves the given path against the current one. If the given path is absolute, it replaces
@@ -565,32 +565,32 @@ protected:
/* --------------------------------------------------------------------------------------------
* Parse a path using the unix standards.
*/
void ParseUnix(CSStr pos, CSStr end);
void ParseUnix(const SQChar * pos, const SQChar * end);
/* --------------------------------------------------------------------------------------------
* Parse a path using the windows standards.
*/
void ParseWindows(CSStr pos, CSStr end);
void ParseWindows(const SQChar * pos, const SQChar * end);
/* --------------------------------------------------------------------------------------------
* Parse a path and expect combined windows and unix styles.
*/
void ParseDynamic(CSStr pos, CSStr end);
void ParseDynamic(const SQChar * pos, const SQChar * end);
/* --------------------------------------------------------------------------------------------
* Parse a path and try to detect it's type automatically.
*/
void ParseGuess(CSStr pos, CSStr end);
void ParseGuess(const SQChar * pos, const SQChar * end);
/* --------------------------------------------------------------------------------------------
* Build a path string using the Unix conventions.
*/
Buffer BuildUnix() const;
SQMOD_NODISCARD Buffer BuildUnix() const;
/* --------------------------------------------------------------------------------------------
* Build a path string using the Windows conventions.
*/
Buffer BuildWindows() const;
SQMOD_NODISCARD Buffer BuildWindows() const;
private:
@@ -629,17 +629,17 @@ public:
/* --------------------------------------------------------------------------------------------
* Creates a path referring to a directory.
*/
static SysPath ForDirectory(CSStr path);
static SysPath ForDirectory(const SQChar * path);
/* --------------------------------------------------------------------------------------------
* Creates a path referring to a directory.
*/
static SysPath ForDirectory(CSStr path, Int32 style);
static SysPath ForDirectory(const SQChar * path, int32_t style);
/* --------------------------------------------------------------------------------------------
* Creates a path referring to a directory.
*/
static SysPath ForDirectory(CSStr path, Style style);
static SysPath ForDirectory(const SQChar * path, Style style);
/* --------------------------------------------------------------------------------------------
* Creates a path referring to a directory.
@@ -655,7 +655,7 @@ public:
* Expands all environment variables contained in the path. On Unix, a tilde as first character
* in the path is replaced with the path to user's home directory.
*/
static SysPath Expand(CSStr path);
static SysPath Expand(const SQChar * path);
/* --------------------------------------------------------------------------------------------
* Expands all environment variables contained in the path.
@@ -701,7 +701,7 @@ public:
static SysPath Temp();
/* --------------------------------------------------------------------------------------------
* Returns the systemwide config directory.
* Returns the system-wide config directory.
*/
static SysPath Config();
@@ -718,38 +718,38 @@ public:
/* --------------------------------------------------------------------------------------------
* Returns the real path to the specified file or directory.
*/
static SysPath Real(CSStr path);
static SysPath Real(const SQChar * path);
/* --------------------------------------------------------------------------------------------
* Creates a path from a parent path and a file name. The parent path is expected to reference
* a directory.
*/
static SysPath With(const SysPath & parent, CSStr name);
static SysPath With(const SysPath & parent, const SQChar * name);
/* --------------------------------------------------------------------------------------------
* Creates a path in unix format from a string.
*/
static SysPath MakeUnix(CSStr path);
static SysPath MakeUnix(const SQChar * path);
/* --------------------------------------------------------------------------------------------
* Creates a path in windows format from a string.
*/
static SysPath MakeWindows(CSStr path);
static SysPath MakeWindows(const SQChar * path);
/* --------------------------------------------------------------------------------------------
* Creates a path in native format from a string.
*/
static SysPath MakeNative(CSStr path);
static SysPath MakeNative(const SQChar * path);
/* --------------------------------------------------------------------------------------------
* Creates a path in and guess the format from a string.
*/
static SysPath MakeGuess(CSStr path);
static SysPath MakeGuess(const SQChar * path);
/* --------------------------------------------------------------------------------------------
* Creates a path in dynamic format from a string.
*/
static SysPath MakeDynamic(CSStr path);
static SysPath MakeDynamic(const SQChar * path);
/* --------------------------------------------------------------------------------------------
* Makes sure all separators from a path are the same.