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 <QRegularExpression>
10
11#include "Method.h"
12
13Method::Method()
14{
15}
16
17bool Method::finalize()
18{
19 for (const auto &tag : m_stringTags) {
20 m_tags.isOptional |= tag.contains(s: QLatin1String("optional"), cs: Qt::CaseInsensitive);
21 m_tags.isDeprecated |= tag.contains(s: QLatin1String("deprecated"), cs: Qt::CaseInsensitive);
22 m_tags.isExperimental |= tag.contains(s: QLatin1String("experimental"), cs: Qt::CaseInsensitive);
23 }
24
25 bool success = true;
26 success &= m_comment.finalize();
27
28 for (const auto &inParam : m_inParameterStrings) {
29 m_inParameters.push_back(t: Parameter::fromString(string: inParam));
30 }
31
32 m_outParameterStrings.removeOne(QStringLiteral("void"));
33 if (m_outParameterStrings.isEmpty()) {
34 m_outParameter = Parameter::fromString(QStringLiteral("void unnamend"));
35 return true;
36 }
37
38 // Guess out parameter name from method name
39 QString paramName = guessOutParameterName();
40 if (!paramName.isEmpty()) {
41 m_outParameterStrings.front() += QLatin1Char(' ') + paramName;
42 m_outParameter = Parameter::fromString(string: m_outParameterStrings.front());
43 } else {
44 for (int i = 0; i < m_outParameterStrings.size(); ++i) {
45 m_outParameterStrings[i] += QLatin1String(" value") + QString::number(i);
46 }
47 }
48
49 for (const auto &outParam : m_outParameterStrings) {
50 m_outParameters.push_back(t: Parameter::fromString(string: outParam));
51 }
52
53 return success;
54}
55
56QString Method::name() const
57{
58 return m_name;
59}
60
61QList<Parameter> Method::inParameters() const
62{
63 return m_inParameters;
64}
65
66QList<Parameter> Method::outParameters() const
67{
68 return m_outParameters;
69}
70
71Parameter Method::outParameter() const
72{
73 return m_outParameter;
74}
75
76Method::Tags Method::tags() const
77{
78 return m_tags;
79}
80
81QStringList Method::comment() const
82{
83 return m_comment;
84}
85
86QString Method::guessOutParameterName() const
87{
88 if (m_outParameterStrings.size() != 1) {
89 return QString();
90 }
91
92 const QRegularExpression rx(QStringLiteral("([A-Z][a-z0-9]+)+"));
93 QRegularExpressionMatch match = rx.match(subject: m_name, offset: 1);
94 if (!match.hasMatch()) {
95 return QStringLiteral("value");
96 }
97
98 return match.captured(nth: 1).toLower();
99}
100

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