New Parser Completed. Verification next.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#include "GameLift/GameLiftValidators_old.h"
|
||||
|
||||
namespace GameLiftValidators2
|
||||
{
|
||||
inline const FRegexPattern& GetPattern(ECliParam ParamType)
|
||||
{
|
||||
ensure(ParamType < ECliParam::Max);
|
||||
static const FRegexPattern Patterns[static_cast<int32>(ECliParam::Max)] =
|
||||
{
|
||||
FRegexPattern(TEXT("^[a-zA-Z0-9\\-]+$")), // AuthToken
|
||||
FRegexPattern(TEXT("^[a-z]*fleet-[a-zA-Z0-9\\-]+$|^arn:.*:[a-z]*fleet\\/[a-z]*fleet-[a-zA-Z0-9\\-]+$")), // FleetId
|
||||
FRegexPattern(TEXT("^[0-9A-Z]\\d+$")), // HostId
|
||||
FRegexPattern(TEXT("^wss:\\/\\/[a-zA-Z0-9.-]+(\\.amazonaws\\.com)?(\\/[^\\s]*)?$")), // WebSocketUrl
|
||||
FRegexPattern(TEXT("^[a-z]{2}-[a-z]+-[0-9]$")), // Region (ca-central-1)
|
||||
};
|
||||
return Patterns[static_cast<int32>(ParamType)];
|
||||
}
|
||||
|
||||
constexpr int32 MaxLengths[static_cast<int32>(ECliParam::Max)] =
|
||||
{
|
||||
64, //authToken
|
||||
512, //FleetId
|
||||
128, //HostId
|
||||
128, //WebSocketUrl
|
||||
16, //Region (ca-central-1)
|
||||
};
|
||||
|
||||
inline int32 GetMaxLength(ECliParam ParamType)
|
||||
{
|
||||
ensure(ParamType < ECliParam::Max);
|
||||
return MaxLengths[static_cast<int32>(ParamType)];
|
||||
}
|
||||
|
||||
constexpr int32 MinLengths[static_cast<int32>(ECliParam::Max)] =
|
||||
{
|
||||
1, //authToken
|
||||
1, //FleetId
|
||||
1, //HostId
|
||||
1, //WebSocketUrl
|
||||
3, //Region (ca-central-1)
|
||||
};
|
||||
|
||||
inline int32 GetMinLength(ECliParam ParamType)
|
||||
{
|
||||
ensure(ParamType < ECliParam::Max);
|
||||
return MinLengths[static_cast<int32>(ParamType)];
|
||||
}
|
||||
|
||||
|
||||
bool IsStringValid(const FString& Value, ECliParam ParamType)
|
||||
{
|
||||
|
||||
ensure(ParamType < ECliParam::Max);
|
||||
if (Value.IsEmpty()) return false;
|
||||
|
||||
if (const int32 Len = Value.Len(); (Len < GetMinLength(ParamType)) || (Len > GetMaxLength(ParamType)))
|
||||
return false;
|
||||
|
||||
const FRegexPattern& Pattern = GetPattern(ParamType);
|
||||
FRegexMatcher StringMatcher(Pattern, Value);
|
||||
return StringMatcher.FindNext() && StringMatcher.GetMatchEnding() == Value.Len(); // returns true on a full or partial match
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user