Extract the value of a named ADIF field from a block of text. ADIF field format: value (case insensitive)
| 15 | // Extract the value of a named ADIF field from a block of text. |
| 16 | // ADIF field format: <FIELDNAME:length>value (case insensitive) |
| 17 | static QString extractField(const QString& block, const QString& fieldName) |
| 18 | { |
| 19 | // e.g. <CALL:6>G3ABC or <CALL:6:S>G3ABC |
| 20 | // NOTE: do NOT make this regex static — the pattern depends on fieldName. |
| 21 | const QRegularExpression re( |
| 22 | R"(<)" + QRegularExpression::escape(fieldName) + R"((?::\d+(?::[A-Z])?)?:(\d+)>)", |
| 23 | QRegularExpression::CaseInsensitiveOption); |
| 24 | auto m = re.match(block); |
| 25 | if (!m.hasMatch()) return {}; |
| 26 | int len = m.captured(1).toInt(); |
| 27 | int start = m.capturedEnd(0); |
| 28 | if (start + len > block.length()) return {}; |
| 29 | return block.mid(start, len); |
| 30 | } |
| 31 | |
| 32 | QString AdifParser::normaliseMode(const QString& mode, const QString& submode) |
| 33 | { |