mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-02-07 13:27:13 +01:00
Add function to normalize path separators.
This commit is contained in:
parent
012ab7ac0a
commit
98fab7a780
@ -1711,6 +1711,32 @@ SysPath SysPath::MakeDynamic(CSStr path)
|
|||||||
return SysPath(path, Style::Dynamic);
|
return SysPath(path, Style::Dynamic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
String SysPath::NormalizePath(SQInteger s, StackStrF & val)
|
||||||
|
{
|
||||||
|
// Have we failed to retrieve the string?
|
||||||
|
if (SQ_FAILED(val.Proc(true)))
|
||||||
|
{
|
||||||
|
STHROWLASTF("Invalid string");
|
||||||
|
}
|
||||||
|
// Is the string empty?
|
||||||
|
else if (!val.mLen)
|
||||||
|
{
|
||||||
|
return String();
|
||||||
|
}
|
||||||
|
// Turn it into a string that we can edit
|
||||||
|
String str(val.mPtr, val.mLen);
|
||||||
|
// Replace all occurences of the specified character
|
||||||
|
for (String::reference c : str)
|
||||||
|
{
|
||||||
|
if (c == '/' || c == '\\')
|
||||||
|
{
|
||||||
|
c = static_cast< String::value_type >(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Return the new string
|
||||||
|
return str;
|
||||||
|
}
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
void Register_SysPath(HSQUIRRELVM vm)
|
void Register_SysPath(HSQUIRRELVM vm)
|
||||||
{
|
{
|
||||||
@ -1794,6 +1820,7 @@ void Register_SysPath(HSQUIRRELVM vm)
|
|||||||
.StaticFunc(_SC("Native"), &SysPath::MakeNative)
|
.StaticFunc(_SC("Native"), &SysPath::MakeNative)
|
||||||
.StaticFunc(_SC("Guess"), &SysPath::MakeGuess)
|
.StaticFunc(_SC("Guess"), &SysPath::MakeGuess)
|
||||||
.StaticFunc(_SC("Dynamic"), &SysPath::MakeDynamic)
|
.StaticFunc(_SC("Dynamic"), &SysPath::MakeDynamic)
|
||||||
|
.StaticFmtFunc(_SC("Normalize"), &SysPath::NormalizePath)
|
||||||
// Static Overloads
|
// Static Overloads
|
||||||
.StaticOverload< SysPath (*)(CSStr) >(_SC("ForDir"), &SysPath::ForDirectory)
|
.StaticOverload< SysPath (*)(CSStr) >(_SC("ForDir"), &SysPath::ForDirectory)
|
||||||
.StaticOverload< SysPath (*)(CSStr, Int32) >(_SC("ForDir"), &SysPath::ForDirectory)
|
.StaticOverload< SysPath (*)(CSStr, Int32) >(_SC("ForDir"), &SysPath::ForDirectory)
|
||||||
|
@ -751,6 +751,11 @@ public:
|
|||||||
* Creates a path in dynamic format from a string.
|
* Creates a path in dynamic format from a string.
|
||||||
*/
|
*/
|
||||||
static SysPath MakeDynamic(CSStr path);
|
static SysPath MakeDynamic(CSStr path);
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Makes sure all separators from a path are the same.
|
||||||
|
*/
|
||||||
|
static String NormalizePath(SQInteger s, StackStrF & val);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Namespace:: SqMod
|
} // Namespace:: SqMod
|
||||||
|
Loading…
x
Reference in New Issue
Block a user