Debian Codegraph @

tools/bluezapi2qt/Properties.cpp

raw
1 /*
2 * BluezQt - Asynchronous BlueZ wrapper library
3 *
4 * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <[email protected]>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9 #include "Properties.h"
10
11 #include <QRegularExpression>
12 #include <QStringList>
13
14 Properties::Properties()
15 {
16 }
17
18 void Properties::parse(const QString &line)
19 {
20 const QRegularExpression rx(
21 QStringLiteral("(?:Properties|^)" // Properties keyword or start of line
22 "\\t{1,2}" // preceding tabs (max 2)
23 "([a-z1-6{}_]+)" // type name
24 " " // space
25 "([A-Z]\\w+)" // method name
26 "(?: \\[(.*)\\])?" // tags
27 "(?: \\((.*)\\))?" // limitations
28 ));
29
30 QRegularExpressionMatch match = rx.match(line);
31 // Check if we match a property
32 if (match.hasMatch()) {
33 m_properties.emplace_back(Property());
34 m_currentProperty = &m_properties.back();
35 m_currentProperty->m_type = match.captured(1).toLower();
36 m_currentProperty->m_name = match.captured(2);
37 m_currentProperty->m_stringTags = match.captured(3).toLower().split(QStringLiteral(", "), Qt::SkipEmptyParts);
38 m_currentProperty->m_limitation = match.captured(4).toLower();
39 } else if (m_currentProperty) {
40 // Skip first empty line
41 if (line.isEmpty() && m_currentProperty->m_comment.isEmpty()) {
42 return;
43 }
44 m_currentProperty->m_comment.append(line);
45 }
46 }
47
48 bool Properties::finalize()
49 {
50 bool success = true;
51
52 for (auto &property : m_properties) {
53 success &= property.finalize();
54 }
55
56 return success;
57 }
58
59 std::list<Property> Properties::properties() const
60 {
61 return m_properties;
62 }