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 "Methods.h"
0010 
0011 #include <QRegularExpression>
0012 #include <QStringList>
0013 
0014 static const QRegularExpression rx(QStringLiteral("\\t+" // preceding tabs
0015                                                   "(?:(.+) )?" // return types - Argh! LE Advertising Manager does not specify return type
0016                                                   "([A-Z]\\w+)" // method name
0017                                                   "\\(([^\\)]*)\\)" // parameters
0018                                                   "(?: \\[(.*)\\])?" // tags
0019                                                   "(?: \\((.*)\\))?" // limitations
0020                                                   ),
0021                                    QRegularExpression::CaseInsensitiveOption);
0022 
0023 Methods::Methods()
0024 {
0025 }
0026 
0027 bool Methods::isMethod(const QString &line)
0028 {
0029     // Check if we match a method
0030     return (rx.match(line).hasMatch());
0031 }
0032 
0033 void Methods::parse(const QString &line)
0034 {
0035     // Check if we match a method
0036     QRegularExpressionMatch match = rx.match(line);
0037     if (match.hasMatch()) {
0038         m_methods.emplace_back(Method());
0039         m_currentMethod = &m_methods.back();
0040         m_currentMethod->m_outParameterStrings = match.captured(1).toLower().split(QStringLiteral(", "), Qt::SkipEmptyParts);
0041         m_currentMethod->m_name = match.captured(2);
0042         m_currentMethod->m_inParameterStrings = match.captured(3).split(QStringLiteral(", "), Qt::SkipEmptyParts);
0043         m_currentMethod->m_stringTags = match.captured(4).toLower().split(QStringLiteral(", "), Qt::SkipEmptyParts);
0044         m_currentMethod->m_limitation = match.captured(5).toLower();
0045     } else if (m_currentMethod) {
0046         // Skip first empty line
0047         if (line.isEmpty() && m_currentMethod->m_comment.isEmpty()) {
0048             return;
0049         }
0050         m_currentMethod->m_comment.append(line);
0051     }
0052 }
0053 
0054 bool Methods::finalize()
0055 {
0056     bool success = true;
0057 
0058     for (auto &method : m_methods) {
0059         success &= method.finalize();
0060     }
0061 
0062     return success;
0063 }
0064 
0065 std::list<Method> Methods::methods() const
0066 {
0067     return m_methods;
0068 }