| 
									
										
										
										
											2016-07-10 23:02:26 +00:00
										 |  |  | #include "CallsignValidator.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CallsignValidator::CallsignValidator (QObject * parent, bool allow_compound) | 
					
						
							|  |  |  |   : QValidator {parent} | 
					
						
							| 
									
										
										
										
											2021-05-10 13:43:06 +01:00
										 |  |  |   , re_ {allow_compound ? R"(^[A-Z0-9/]+$)" : R"(^[A-Z0-9]+$)"} | 
					
						
							| 
									
										
										
										
											2016-07-10 23:02:26 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | auto CallsignValidator::validate (QString& input, int& pos) const -> State | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   input = input.toUpper (); | 
					
						
							| 
									
										
										
										
											2021-05-10 13:43:06 +01:00
										 |  |  |   while (input.size () && input[0].isSpace ()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       input.remove (0, 1); | 
					
						
							|  |  |  |       if (pos > 0) --pos; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-06-09 13:12:25 +01:00
										 |  |  |   while (input.size () && input[input.size () - 1].isSpace ()) | 
					
						
							| 
									
										
										
										
											2021-05-10 13:43:06 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |       if (pos > input.size ()) --pos; | 
					
						
							|  |  |  |       input.chop (1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   auto match = re_.match (input, 0, QRegularExpression::PartialPreferCompleteMatch); | 
					
						
							| 
									
										
										
										
											2016-07-10 23:02:26 +00:00
										 |  |  |   if (match.hasMatch ()) return Acceptable; | 
					
						
							|  |  |  |   if (!input.size () || match.hasPartialMatch ()) return Intermediate; | 
					
						
							|  |  |  |   pos = input.size (); | 
					
						
							|  |  |  |   return Invalid; | 
					
						
							|  |  |  | } |