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

Improve interaction of path utility with strings.

This commit is contained in:
Sandu Liviu Catalin 2021-07-04 20:21:47 +03:00
parent 722c7c8515
commit a4f1e0d19d
2 changed files with 74 additions and 38 deletions

View File

@ -1680,14 +1680,14 @@ void Register_SysPath(HSQUIRRELVM vm)
Class< SysPath >(vm, Typename::Str)
// Constructors
.Ctor()
.Ctor< const SQChar * >()
.Ctor< const SQChar *, int32_t >()
.Ctor< StackStrF & >()
.Ctor< StackStrF &, int32_t >()
// Meta-methods
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
.Func(_SC("_tostring"), &SysPath::ToString)
.Func(_SC("cmp"), &SysPath::Cmp)
// Properties
.Prop(_SC("String"), &SysPath::ToString, &SysPath::FromString)
.Prop(_SC("String"), &SysPath::ToString, &SysPath::FromStringSq)
.Prop(_SC("IsAbs"), &SysPath::IsAbsolute)
.Prop(_SC("IsAbsolute"), &SysPath::IsAbsolute)
.Prop(_SC("IsRel"), &SysPath::IsRelative)
@ -1698,15 +1698,15 @@ void Register_SysPath(HSQUIRRELVM vm)
.Prop(_SC("IsEmpty"), &SysPath::Empty)
.Prop(_SC("Drive"), &SysPath::GetDrive, &SysPath::SetDrive)
.Prop(_SC("Depth"), &SysPath::Depth)
.Prop(_SC("Filename"), &SysPath::GetFilename, &SysPath::SqSetFilename)
.Prop(_SC("Basename"), &SysPath::GetBasename, &SysPath::SqSetBasename)
.Prop(_SC("Extension"), &SysPath::GetExtensionC, &SysPath::SqSetExtension)
.Prop(_SC("Filename"), &SysPath::GetFilename, &SysPath::SetFilenameSq)
.Prop(_SC("Basename"), &SysPath::GetBasename, &SysPath::SetBasenameSq)
.Prop(_SC("Extension"), &SysPath::GetExtensionC, &SysPath::SetExtensionSq)
.Prop(_SC("Parent"), &SysPath::Parent)
// Member Methods
.Func(_SC("Swap"), &SysPath::Swap)
.Func(_SC("Clear"), &SysPath::Clear)
.Func< SysPath & (SysPath::*)(const SysPath &) >(_SC("AssignPath"), &SysPath::Assign)
.Func< SysPath & (SysPath::*)(const SysPath &) >(_SC("AppendPath"), &SysPath::Append)
.Func(_SC("AssignPath"), &SysPath::AssignPath)
.Func(_SC("AppendPath"), &SysPath::AppendPath)
.Func(_SC("Build"), &SysPath::ToStr)
.Func(_SC("ToStr"), &SysPath::ToStr)
.Func(_SC("MakeDir"), &SysPath::MakeDirectory)
@ -1715,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::*)(const SQChar *) >(_SC("Push"), &SysPath::Push)
.FmtFunc(_SC("Push"), &SysPath::PushSq)
.Func(_SC("PopBack"), &SysPath::PopBack)
.Func(_SC("PopFront"), &SysPath::PopFront)
.Func< SysPath & (SysPath::*)(const SQChar *) >(_SC("SetFilename"), &SysPath::SetFilename)
.Func(_SC("SetFilename"), &SysPath::SetFilenameSq)
.Func(_SC("GetFilename"), &SysPath::GetFilename)
.Func< SysPath & (SysPath::*)(const SQChar *) >(_SC("SetBasename"), &SysPath::SetBasename)
.Func(_SC("SetBasename"), &SysPath::SetBasenameSq)
.Func(_SC("GetBasename"), &SysPath::GetBasename)
.Func< SysPath & (SysPath::*)(const SQChar *) >(_SC("SetExtension"), &SysPath::SetExtension)
.Func(_SC("SetExtension"), &SysPath::SetExtensionSq)
.Func(_SC("GetExtension"), &SysPath::GetExtension)
.Func(_SC("Resolve"), &SysPath::Resolve)
.FmtFunc(_SC("Append"), &SysPath::AppendSq)
.FmtFunc(_SC("AppendAs"), &SysPath::AppendAs)
.FmtFunc(_SC("Assign"), &SysPath::AssignSq)
.FmtFunc(_SC("AssignAs"), &SysPath::AssignAs)
.FmtFunc(_SC("AssignDir"), &SysPath::AssignDirSq)
.FmtFunc(_SC("AssignDirAs"), &SysPath::AssignDirAs)
// Member Overloads
.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)
.Overload(_SC("MakeAbsolute"), &SysPath::MakeAbsolute0)
.Overload(_SC("MakeAbsolute"), &SysPath::MakeAbsolute1)
// Static Functions
.StaticFunc(_SC("Separator"), &SysPath::Separator)
.StaticFunc(_SC("PathSeparator"), &SysPath::PathSeparator)
.StaticFunc< SysPath (*)(const SQChar *) >(_SC("Expand"), &SysPath::Expand)
.StaticFunc(_SC("Expand"), &SysPath::ExpandSq)
.StaticFunc(_SC("Home"), &SysPath::Home)
.StaticFunc(_SC("ConfigHome"), &SysPath::ConfigHome)
.StaticFunc(_SC("DataHome"), &SysPath::DataHome)
@ -1749,19 +1749,19 @@ void Register_SysPath(HSQUIRRELVM vm)
.StaticFunc(_SC("Config"), &SysPath::Config)
.StaticFunc(_SC("System"), &SysPath::System)
.StaticFunc(_SC("Null"), &SysPath::Null)
.StaticFunc(_SC("Real"), &SysPath::Real)
.StaticFunc(_SC("With"), &SysPath::With)
.StaticFunc(_SC("Unix"), &SysPath::MakeUnix)
.StaticFunc(_SC("Windows"), &SysPath::MakeWindows)
.StaticFunc(_SC("Native"), &SysPath::MakeNative)
.StaticFunc(_SC("Guess"), &SysPath::MakeGuess)
.StaticFunc(_SC("Dynamic"), &SysPath::MakeDynamic)
.StaticFmtFunc(_SC("Real"), &SysPath::RealSq)
.StaticFmtFunc(_SC("With"), &SysPath::WithSq)
.StaticFmtFunc(_SC("Unix"), &SysPath::MakeUnixSq)
.StaticFmtFunc(_SC("Windows"), &SysPath::MakeWindowsSq)
.StaticFmtFunc(_SC("Native"), &SysPath::MakeNativeSq)
.StaticFmtFunc(_SC("Guess"), &SysPath::MakeGuessSq)
.StaticFmtFunc(_SC("Dynamic"), &SysPath::MakeDynamicSq)
.StaticFmtFunc(_SC("Normalize"), &SysPath::NormalizePath)
// Static Overloads
.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)
.StaticFmtFunc(_SC("ForDir"), &SysPath::ForDirectorySq)
.StaticFmtFunc(_SC("ForDirAs"), &SysPath::ForDirectoryAs)
.StaticFmtFunc(_SC("ForDirectory"), &SysPath::ForDirectorySq)
.StaticFmtFunc(_SC("ForDirectoryAs"), &SysPath::ForDirectoryAs)
);
ConstTable(vm).Enum(_SC("SqSysPathStyle"), Enumeration(vm)

View File

@ -61,6 +61,20 @@ public:
*/
SysPath(const SQChar * path, Style style);
/* --------------------------------------------------------------------------------------------
* Creates a path in native format from a string.
*/
explicit SysPath(StackStrF & path)
: SysPath(path.mPtr)
{ }
/* --------------------------------------------------------------------------------------------
* Creates a path from a string.
*/
SysPath(StackStrF & path, int32_t style)
: SysPath(path.mPtr, style)
{ }
/* --------------------------------------------------------------------------------------------
* Creates a path in native format from a string.
*/
@ -178,11 +192,13 @@ public:
* Assigns a string containing a path in native format.
*/
SysPath & Assign(const SQChar * path);
SysPath & AssignSq(StackStrF & path) { return Assign(path.mPtr); }
/* --------------------------------------------------------------------------------------------
* Assigns a string containing a path.
*/
SysPath & Assign(const SQChar * path, int32_t style);
SysPath & AssignAs(int32_t style, StackStrF & path) { return Assign(path.mPtr, style); }
/* --------------------------------------------------------------------------------------------
* Assigns a string containing a path.
@ -231,6 +247,7 @@ public:
* Copy the components from another path.
*/
SysPath & Assign(const SysPath & path);
SysPath & AssignPath(const SysPath & path) { return Assign(path); }
/* --------------------------------------------------------------------------------------------
* Move the components of another path into this instance.
@ -241,11 +258,13 @@ public:
* The resulting path always refers to a directory and the filename part is empty.
*/
SysPath & AssignDir(const SQChar * path);
SysPath & AssignDirSq(StackStrF & path) { return AssignDir(path.mPtr); }
/* --------------------------------------------------------------------------------------------
* The resulting path always refers to a directory and the filename part is empty.
*/
SysPath & AssignDir(const SQChar * path, int32_t style);
SysPath & AssignDirAs(int32_t style, StackStrF & path) { return AssignDir(path.mPtr, style); }
/* --------------------------------------------------------------------------------------------
* The resulting path always refers to a directory and the filename part is empty.
@ -291,6 +310,7 @@ public:
* Assigns a string containing a path.
*/
void FromString(const SQChar * path);
void FromStringSq(StackStrF & path) { FromString(path.mPtr); }
/* --------------------------------------------------------------------------------------------
* See whether the path is absolute.
@ -352,11 +372,13 @@ public:
* as base directory.
*/
SysPath & MakeAbsolute();
SysPath & MakeAbsolute0() { return MakeAbsolute(); }
/* --------------------------------------------------------------------------------------------
* Makes the path absolute if it is relative. The given path is taken as base.
*/
SysPath & MakeAbsolute(const SysPath & base);
SysPath & MakeAbsolute1(const SysPath & base) { return MakeAbsolute(base); }
/* --------------------------------------------------------------------------------------------
* Makes the path absolute if it is relative. The given path is taken as base.
@ -367,6 +389,7 @@ public:
* Appends the given path.
*/
SysPath & Append(const SysPath & path);
SysPath & AppendPath(const SysPath & path) { return Append(path); }
/* --------------------------------------------------------------------------------------------
* Appends the given path.
@ -377,11 +400,13 @@ public:
* Parse the given string and append the resulted path.
*/
SysPath & Append(const SQChar * path);
SysPath & AppendSq(StackStrF & path) { return Append(path.mPtr); }
/* --------------------------------------------------------------------------------------------
* Parse the given string and append the resulted path.
*/
SysPath & Append(const SQChar * path, int32_t style);
SysPath & AppendAs(int32_t style, StackStrF & path) { return Append(path.mPtr, style); }
/* --------------------------------------------------------------------------------------------
* Parse the given string and append the resulted path.
@ -441,6 +466,7 @@ public:
* Adds a directory to the directory list.
*/
SysPath & Push(const SQChar * dir);
SysPath & PushSq(StackStrF & dir) { return Push(dir.mPtr); }
/* --------------------------------------------------------------------------------------------
* Adds a directory to the directory list.
@ -488,9 +514,9 @@ public:
/* --------------------------------------------------------------------------------------------
* Set the specified file name.
*/
void SqSetFilename(const SQChar * name)
SysPath & SetFilenameSq(StackStrF & name)
{
SetFilename(name);
return SetFilename(name.mPtr);
}
/* --------------------------------------------------------------------------------------------
@ -516,9 +542,9 @@ public:
/* --------------------------------------------------------------------------------------------
* Sets the basename part of the file name and does not change the extension.
*/
void SqSetBasename(const SQChar * name)
SysPath & SetBasenameSq(StackStrF & name)
{
SetBasename(name);
return SetBasename(name.mPtr);
}
/* --------------------------------------------------------------------------------------------
@ -539,9 +565,9 @@ public:
/* --------------------------------------------------------------------------------------------
* Sets the file name extension.
*/
void SqSetExtension(const SQChar * ext)
SysPath & SetExtensionSq(StackStrF & ext)
{
SetExtension(ext);
return SetExtension(ext.mPtr);
}
/* --------------------------------------------------------------------------------------------
@ -630,11 +656,13 @@ public:
* Creates a path referring to a directory.
*/
static SysPath ForDirectory(const SQChar * path);
static SysPath ForDirectorySq(StackStrF & path) { return ForDirectory(path.mPtr); }
/* --------------------------------------------------------------------------------------------
* Creates a path referring to a directory.
*/
static SysPath ForDirectory(const SQChar * path, int32_t style);
static SysPath ForDirectoryAs(int32_t style, StackStrF & path) { return ForDirectory(path.mPtr, style); }
/* --------------------------------------------------------------------------------------------
* Creates a path referring to a directory.
@ -656,6 +684,7 @@ public:
* in the path is replaced with the path to user's home directory.
*/
static SysPath Expand(const SQChar * path);
static SysPath ExpandSq(StackStrF & path) { return Expand(path.mPtr); }
/* --------------------------------------------------------------------------------------------
* Expands all environment variables contained in the path.
@ -719,37 +748,44 @@ public:
* Returns the real path to the specified file or directory.
*/
static SysPath Real(const SQChar * path);
static SysPath RealSq(StackStrF & path) { return Real(path.mPtr); }
/* --------------------------------------------------------------------------------------------
* 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, const SQChar * name);
static SysPath WithSq(const SysPath & parent, StackStrF & name) { return With(parent, name.mPtr); }
/* --------------------------------------------------------------------------------------------
* Creates a path in unix format from a string.
*/
static SysPath MakeUnix(const SQChar * path);
static SysPath MakeUnixSq(StackStrF & path) { return MakeUnix(path.mPtr); }
/* --------------------------------------------------------------------------------------------
* Creates a path in windows format from a string.
*/
static SysPath MakeWindows(const SQChar * path);
static SysPath MakeWindowsSq(StackStrF & path) { return MakeWindows(path.mPtr); }
/* --------------------------------------------------------------------------------------------
* Creates a path in native format from a string.
*/
static SysPath MakeNative(const SQChar * path);
static SysPath MakeNativeSq(StackStrF & path) { return MakeNative(path.mPtr); }
/* --------------------------------------------------------------------------------------------
* Creates a path in and guess the format from a string.
*/
static SysPath MakeGuess(const SQChar * path);
static SysPath MakeGuessSq(StackStrF & path) { return MakeGuess(path.mPtr); }
/* --------------------------------------------------------------------------------------------
* Creates a path in dynamic format from a string.
*/
static SysPath MakeDynamic(const SQChar * path);
static SysPath MakeDynamicSq(StackStrF & path) { return MakeDynamic(path.mPtr); }
/* --------------------------------------------------------------------------------------------
* Makes sure all separators from a path are the same.