WSF
RegexValidator.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2019 Infoscitex, a DCS Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef REGEXVALIDATOR_HPP
13#define REGEXVALIDATOR_HPP
14
15#include <iostream>
16#include <regex>
17#include <sstream>
18#include <string>
19
20#include <QRegularExpression>
21#include <QRegularExpressionMatch>
22#include <QString>
23
24#include "FFIRN_Validator.hpp"
25
26namespace usmtf
27{
28
35
39class USMTF_EXPORT RegexValidator : public FFIRN_Validator
40{
41public:
42 // It would be nice to have better names and some convenience functions for building regex ranges.
43 // However, ranges are pretty difficulty in regex, I highly suggest using RangedValidator if the
44 // field is just the range value. That is much easier. Regex is easier when values have complicated
45 // sub components in one value.
46 static const std::string cAny;
47 static const std::string c00to90;
48 static const std::string c00to59;
49 static const std::string c00to59dec000to999;
50 static const std::string c00to59dec0to9;
51 static const std::string c01to60;
52 static const std::string cNorS;
53 static const std::string cAtoZ;
54 static const std::string c0to9;
55 static const std::string cHyphenDelimeter;
56 static const std::string c000to180;
57 static const std::string c000to359;
58 static const std::string c0to999;
59 static const std::string c1to999;
60 static const std::string c000to99999;
61 static const std::string cEorW;
62 static const std::string cStart;
63 static const std::string cEnd;
64 static const std::string cSpace;
65
66 RegexValidator() = default;
70 bool ParseAndValidate(const usmtf::Field& aField) override;
72 void SetRegexExpression(const std::string& aExpression);
73
76 void SetErrorMessage(const std::string& aMessage);
77
78protected:
79 QRegularExpressionMatch mMatchResults;
80 QRegularExpression mRegexExpression;
81 std::string mRegexString{"No Regex Provided"};
82 std::string mErrorMessage{"Failed Regex Validation for: " + mRegexString};
83};
84} // namespace usmtf
85
86#endif
Definition Field.hpp:48
static const std::string cNorS
Definition RegexValidator.hpp:52
std::string mErrorMessage
Definition RegexValidator.hpp:82
static const std::string c1to999
Definition RegexValidator.hpp:59
static const std::string c00to59
Definition RegexValidator.hpp:48
bool ParseAndValidate(const usmtf::Field &aField) override
Definition RegexValidator.cpp:17
static const std::string cAny
Definition RegexValidator.hpp:46
static const std::string c00to59dec0to9
Definition RegexValidator.hpp:50
static const std::string c00to90
Definition RegexValidator.hpp:47
static const std::string c01to60
Definition RegexValidator.hpp:51
static const std::string cAtoZ
Definition RegexValidator.hpp:53
static const std::string c00to59dec000to999
Definition RegexValidator.hpp:49
static const std::string cEnd
Definition RegexValidator.hpp:63
static const std::string c000to359
Definition RegexValidator.hpp:57
static const std::string cSpace
Definition RegexValidator.hpp:64
static const std::string c000to99999
Definition RegexValidator.hpp:60
QRegularExpressionMatch mMatchResults
Definition RegexValidator.hpp:79
static const std::string c0to999
Definition RegexValidator.hpp:58
QRegularExpression mRegexExpression
Definition RegexValidator.hpp:80
static const std::string c0to9
Definition RegexValidator.hpp:54
static const std::string cHyphenDelimeter
Definition RegexValidator.hpp:55
void SetRegexExpression(const std::string &aExpression)
Configure to run against regex needs.
Definition RegexValidator.cpp:41
void SetErrorMessage(const std::string &aMessage)
Definition RegexValidator.cpp:48
static const std::string cEorW
Definition RegexValidator.hpp:61
static const std::string c000to180
Definition RegexValidator.hpp:56
static const std::string cStart
Definition RegexValidator.hpp:62
std::string mRegexString
Definition RegexValidator.hpp:81
Definition Acmid.cpp:17
Copyrights Multiple, All Rights Reserved