New Parser Completed. Verification next.
This commit is contained in:
78
Source/FPSTemplate/Private/GameLift/GameLiftClp.cpp
Normal file
78
Source/FPSTemplate/Private/GameLift/GameLiftClp.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "GameLift/GameLiftClp.h"
|
||||
|
||||
int32 cmdlineparser::GetConfiguredOrDefaultPort(const FString& Token)
|
||||
{
|
||||
return details::GetConfiguredOrDefaultPort(FCommandLine::Get(), Token);
|
||||
}
|
||||
|
||||
int32 cmdlineparser::GetConfiguredOrDefaultPort(const FString& CommandLine, const FString& Token)
|
||||
{
|
||||
return details::GetConfiguredOrDefaultPort(CommandLine, Token);
|
||||
}
|
||||
|
||||
cmdlineparser::details::FParseResult cmdlineparser::GetValueOfToken(const FString& CommandLine, const details::EAvailableTokens Token)
|
||||
{
|
||||
details::FParseResult Result;
|
||||
FString ValueOfToken;
|
||||
Result.Token = Token;
|
||||
|
||||
ensure(Token < details::EAvailableTokens::MaxToken);
|
||||
const bool bTokenFound = FParse::Value(
|
||||
*CommandLine,
|
||||
*details::EnsureEndsWith(details::CLI_TOKENS[static_cast<int32>(Token)],
|
||||
TEXT("=")),
|
||||
ValueOfToken
|
||||
);
|
||||
|
||||
if (!bTokenFound)
|
||||
{
|
||||
Result.Value = FString();
|
||||
Result.ErrorCode = details::EErrorCodes::TokenNotFound;
|
||||
Result.bIsValid = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ValueOfToken.IsEmpty())
|
||||
{
|
||||
Result.Value = FString();
|
||||
Result.ErrorCode = details::EErrorCodes::ValueEmpty;
|
||||
Result.bIsValid = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Validation of inputs
|
||||
Result.Value = ValueOfToken;
|
||||
Result.ErrorCode = details::EErrorCodes::NoError;
|
||||
Result.bIsValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
ensure(Result.ErrorCode < details::EErrorCodes::MaxCode);
|
||||
FString ErrorMessage = details::ERROR_MESSAGES[static_cast<int32>(Result.ErrorCode)];
|
||||
FString TokenName = details::CLI_TOKENS[static_cast<int32>(Result.Token)];
|
||||
FString Value = Result.Value;
|
||||
Result.ErrorMessage = FString::Format(*ErrorMessage, {FStringFormatArg(TokenName), FStringFormatArg(Value)});
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
||||
// cmdlineparser::Details namespace
|
||||
|
||||
FString cmdlineparser::details::EnsureEndsWith(const FString& Token, const TCHAR* Suffix)
|
||||
{
|
||||
return Token.EndsWith(Suffix) ? Token : Token + Suffix;
|
||||
}
|
||||
|
||||
int32 cmdlineparser::details::GetConfiguredOrDefaultPort(const FString& CommandLine, const FString& Token)
|
||||
{
|
||||
const int32 Port = FURL::UrlConfig.DefaultPort;
|
||||
|
||||
if (int32 CliPort; FParse::Value(*CommandLine, *EnsureEndsWith(Token, TEXT("=")), CliPort))
|
||||
{
|
||||
if (CliPort >= details::MIN_PORT && CliPort <= details::MAX_PORT)
|
||||
{
|
||||
return CliPort;
|
||||
}
|
||||
}
|
||||
return Port;
|
||||
}
|
||||
Reference in New Issue
Block a user