1/*
2 * BluezQt - Asynchronous BlueZ wrapper library
3 *
4 * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de>
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
14static 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
23Methods::Methods()
24{
25}
26
27bool Methods::isMethod(const QString &line)
28{
29 // Check if we match a method
30 return (rx.match(subject: line).hasMatch());
31}
32
33void Methods::parse(const QString &line)
34{
35 // Check if we match a method
36 QRegularExpressionMatch match = rx.match(subject: line);
37 if (match.hasMatch()) {
38 m_methods.emplace_back(args: Method());
39 m_currentMethod = &m_methods.back();
40 m_currentMethod->m_outParameterStrings = match.captured(nth: 1).toLower().split(QStringLiteral(", "), behavior: Qt::SkipEmptyParts);
41 m_currentMethod->m_name = match.captured(nth: 2);
42 m_currentMethod->m_inParameterStrings = match.captured(nth: 3).split(QStringLiteral(", "), behavior: Qt::SkipEmptyParts);
43 m_currentMethod->m_stringTags = match.captured(nth: 4).toLower().split(QStringLiteral(", "), behavior: Qt::SkipEmptyParts);
44 m_currentMethod->m_limitation = match.captured(nth: 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(t: line);
51 }
52}
53
54bool 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
65std::list<Method> Methods::methods() const
66{
67 return m_methods;
68}
69

source code of bluez-qt/tools/bluezapi2qt/Methods.cpp