Made value object regular expressions thread safe

(note: which is important because the RegEx is static)
This commit is contained in:
Klaus Basan
2015-07-13 19:32:03 +02:00
committed by Mathew Sutcliffe
parent f8c83ce2a3
commit e3b0720295
3 changed files with 17 additions and 5 deletions

View File

@@ -168,8 +168,11 @@ namespace BlackMisc
bool CCallsign::isValidCallsign(const QString &callsign)
{
// We allow all number callsigns
static QRegularExpression regexp("^[A-Z0-9]*$");
if (callsign.length() < 2 || callsign.length() > 10) { return false; }
static QThreadStorage<QRegularExpression> tsRegex;
if (! tsRegex.hasLocalData()) { tsRegex.setLocalData(QRegularExpression("^[A-Z0-9]*$")); }
const QRegularExpression &regexp = tsRegex.localData();
return (regexp.match(callsign).hasMatch());
}