File indexing completed on 2024-04-21 03:52:04

0001 /*
0002  * BluezQt - Asynchronous BlueZ wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #include "Properties.h"
0010 
0011 #include <QRegularExpression>
0012 #include <QStringList>
0013 
0014 Properties::Properties()
0015 {
0016 }
0017 
0018 void Properties::parse(const QString &line)
0019 {
0020     const QRegularExpression rx(
0021         QStringLiteral("(?:Properties|^)" // Properties keyword or start of line
0022                        "\\t{1,2}" // preceding tabs (max 2)
0023                        "([a-z1-6{}_]+)" // type name
0024                        " " // space
0025                        "([A-Z]\\w+)" // method name
0026                        "(?: \\[(.*)\\])?" // tags
0027                        "(?: \\((.*)\\))?" // limitations
0028                        ));
0029 
0030     QRegularExpressionMatch match = rx.match(line);
0031     // Check if we match a property
0032     if (match.hasMatch()) {
0033         m_properties.emplace_back(Property());
0034         m_currentProperty = &m_properties.back();
0035         m_currentProperty->m_type = match.captured(1).toLower();
0036         m_currentProperty->m_name = match.captured(2);
0037         m_currentProperty->m_stringTags = match.captured(3).toLower().split(QStringLiteral(", "), Qt::SkipEmptyParts);
0038         m_currentProperty->m_limitation = match.captured(4).toLower();
0039     } else if (m_currentProperty) {
0040         // Skip first empty line
0041         if (line.isEmpty() && m_currentProperty->m_comment.isEmpty()) {
0042             return;
0043         }
0044         m_currentProperty->m_comment.append(line);
0045     }
0046 }
0047 
0048 bool Properties::finalize()
0049 {
0050     bool success = true;
0051 
0052     for (auto &property : m_properties) {
0053         success &= property.finalize();
0054     }
0055 
0056     return success;
0057 }
0058 
0059 std::list<Property> Properties::properties() const
0060 {
0061     return m_properties;
0062 }