Added String<T, N>.ParseArgs().
This commit is contained in:
parent
8d28f3547c
commit
c5b281d73c
@ -1110,6 +1110,54 @@ namespace ehs
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector<Str> ParseArgs() const
|
||||||
|
{
|
||||||
|
Vector<Str> args;
|
||||||
|
T *quoteStart = nullptr;
|
||||||
|
T *spaceStart = nullptr;
|
||||||
|
|
||||||
|
for (T *i = data; i <= data + size; ++i)
|
||||||
|
{
|
||||||
|
if (*i == '\"' && !spaceStart)
|
||||||
|
{
|
||||||
|
if (quoteStart)
|
||||||
|
{
|
||||||
|
args.Push(Str(quoteStart, i - quoteStart));
|
||||||
|
quoteStart = nullptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (i + 1 < &data[size - 1])
|
||||||
|
quoteStart = i + 1;
|
||||||
|
else
|
||||||
|
args.Push({});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (*i == ' ' && !quoteStart)
|
||||||
|
{
|
||||||
|
if (spaceStart)
|
||||||
|
{
|
||||||
|
args.Push(Str(spaceStart, i - spaceStart));
|
||||||
|
spaceStart = i + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (i + 1 < &data[size - 1])
|
||||||
|
spaceStart = i + 1;
|
||||||
|
else
|
||||||
|
args.Push({});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quoteStart)
|
||||||
|
args.Push(Str(quoteStart, &data[size - 1] - (quoteStart - 1)));
|
||||||
|
else if (spaceStart)
|
||||||
|
args.Push(Str(spaceStart, &data[size - 1] - (spaceStart - 1)));
|
||||||
|
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
/// Checks if the string represents a number. Must not have any alphabetical characters.
|
/// Checks if the string represents a number. Must not have any alphabetical characters.
|
||||||
/// @returns The result.
|
/// @returns The result.
|
||||||
bool IsNum() const
|
bool IsNum() const
|
||||||
|
@ -693,7 +693,7 @@ namespace ehs
|
|||||||
Vector<Str_32> Console::GetArgs_32(const UInt_64 bufferSize)
|
Vector<Str_32> Console::GetArgs_32(const UInt_64 bufferSize)
|
||||||
{
|
{
|
||||||
#if defined(EHS_OS_WINDOWS)
|
#if defined(EHS_OS_WINDOWS)
|
||||||
return UTF::To_32(GetCommandLineW()).Split(U" ");
|
return UTF::To_32(GetCommandLineW()).ParseArgs();
|
||||||
#elif defined(EHS_OS_LINUX)
|
#elif defined(EHS_OS_LINUX)
|
||||||
File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN);
|
File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN);
|
||||||
Array<Byte> data = cmdFile.ReadArray(bufferSize);
|
Array<Byte> data = cmdFile.ReadArray(bufferSize);
|
||||||
@ -725,7 +725,7 @@ namespace ehs
|
|||||||
Vector<Str_16> Console::GetArgs_16(const UInt_64 bufferSize)
|
Vector<Str_16> Console::GetArgs_16(const UInt_64 bufferSize)
|
||||||
{
|
{
|
||||||
#if defined(EHS_OS_WINDOWS)
|
#if defined(EHS_OS_WINDOWS)
|
||||||
return Str_16(GetCommandLineW()).Split(L" ");
|
return Str_16(GetCommandLineW()).ParseArgs();
|
||||||
#elif defined(EHS_OS_LINUX)
|
#elif defined(EHS_OS_LINUX)
|
||||||
File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN);
|
File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN);
|
||||||
Array<Byte> data = cmdFile.ReadArray(bufferSize);
|
Array<Byte> data = cmdFile.ReadArray(bufferSize);
|
||||||
@ -755,7 +755,7 @@ namespace ehs
|
|||||||
Vector<Str_8> Console::GetArgs_8(const UInt_64 bufferSize)
|
Vector<Str_8> Console::GetArgs_8(const UInt_64 bufferSize)
|
||||||
{
|
{
|
||||||
#if defined(EHS_OS_WINDOWS)
|
#if defined(EHS_OS_WINDOWS)
|
||||||
return UTF::To_8(GetCommandLineW()).Split(" ");
|
return UTF::To_8(GetCommandLineW()).ParseArgs();
|
||||||
#elif defined(EHS_OS_LINUX)
|
#elif defined(EHS_OS_LINUX)
|
||||||
File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN);
|
File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN);
|
||||||
Array<Byte> data = cmdFile.ReadArray(bufferSize);
|
Array<Byte> data = cmdFile.ReadArray(bufferSize);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user