Debian Codegraph @

tools/bluezapi2qt/Methods.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 "Methods.h"
10
11 #include <QRegularExpression>
12 #include <QStringList>
13
14 static const QRegularExpression rx(QStringLiteral("\\t+" // preceding tabs
15 "(?:(.+) )?" // return types - Argh! LE Advertising Manager does not specify return type
16 "([A-Z]\\w+)" // method name
17 "\\(([^\\)]*)\\)" // parameters
18 "(?: \\[(.*)\\])?" // tags
19 "(?: \\((.*)\\))?" // limitations
20 ),
21 QRegularExpression::CaseInsensitiveOption);
22
23 Methods::Methods()
24 {
25 }
26
27 bool Methods::isMethod(const QString &line)
28 {
29 // Check if we match a method
30 return (rx.match(line).hasMatch());
31 }
32
33 void Methods::parse(const QString &line)
34 {
35 // Check if we match a method
36 QRegularExpressionMatch match = rx.match(line);
37 if (match.hasMatch()) {
38 m_methods.emplace_back(Method());
39 m_currentMethod = &m_methods.back();
40 m_currentMethod->m_outParameterStrings = match.captured(1).toLower().split(QStringLiteral(", "), Qt::SkipEmptyParts);
41 m_currentMethod->m_name = match.captured(2);
42 m_currentMethod->m_inParameterStrings = match.captured(3).split(QStringLiteral(", "), Qt::SkipEmptyParts);
43 m_currentMethod->m_stringTags = match.captured(4).toLower().split(QStringLiteral(", "), Qt::SkipEmptyParts);
44 m_currentMethod->m_limitation = match.captured(5).toLower();
45 } else if (m_currentMethod) {
46 // Skip first empty line
47 if (line.isEmpty() && m_currentMethod->m_comment.isEmpty()) {
48 return;
49 }
50 m_currentMethod->m_comment.append(line);
51 }
52 }
53
54 bool Methods::finalize()
55 {
56 bool success = true;
57
58 for (auto &method : m_methods) {
59 success &= method.finalize();
60 }
61
62 return success;
63 }
64
65 std::list<Method> Methods::methods() const
66 {
67 return m_methods;
68 }