File: CallsignValidator.cpp

package info (click to toggle)
wsjtx 3.0.0~rc1%2Brepack-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 86,956 kB
  • sloc: cpp: 105,872; f90: 60,116; python: 27,241; ansic: 13,372; fortran: 2,382; makefile: 197; sh: 135
file content (27 lines) | stat: -rwxr-xr-x 826 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "CallsignValidator.hpp"

CallsignValidator::CallsignValidator (QObject * parent, bool allow_compound)
  : QValidator {parent}
  , re_ {allow_compound ? R"(^[A-Z0-9/]+$)" : R"(^[A-Z0-9]+$)"}
{
}

auto CallsignValidator::validate (QString& input, int& pos) const -> State
{
  input = input.toUpper ();
  while (input.size () && input[0].isSpace ())
    {
      input.remove (0, 1);
      if (pos > 0) --pos;
    }
  while (input.size () && input[input.size () - 1].isSpace ())
    {
      if (pos > input.size ()) --pos;
      input.chop (1);
    }
  auto match = re_.match (input, 0, QRegularExpression::PartialPreferCompleteMatch);
  if (match.hasMatch ()) return Acceptable;
  if (!input.size () || match.hasPartialMatch ()) return Intermediate;
  pos = input.size ();
  return Invalid;
}