File: Methods.cpp

package info (click to toggle)
bluez-qt 5.116.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,932 kB
  • sloc: cpp: 16,676; xml: 554; ansic: 337; sh: 13; makefile: 8
file content (68 lines) | stat: -rw-r--r-- 2,293 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * BluezQt - Asynchronous BlueZ wrapper library
 *
 * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de>
 *
 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
 */

#include "Methods.h"

#include <QRegularExpression>
#include <QStringList>

static const QRegularExpression rx(QStringLiteral("\\t+" // preceding tabs
                                                  "(?:(.+) )?" // return types - Argh! LE Advertising Manager does not specify return type
                                                  "([A-Z]\\w+)" // method name
                                                  "\\(([^\\)]*)\\)" // parameters
                                                  "(?: \\[(.*)\\])?" // tags
                                                  "(?: \\((.*)\\))?" // limitations
                                                  ),
                                   QRegularExpression::CaseInsensitiveOption);

Methods::Methods()
{
}

bool Methods::isMethod(const QString &line)
{
    // Check if we match a method
    return (rx.match(line).hasMatch());
}

void Methods::parse(const QString &line)
{
    // Check if we match a method
    QRegularExpressionMatch match = rx.match(line);
    if (match.hasMatch()) {
        m_methods.emplace_back(Method());
        m_currentMethod = &m_methods.back();
        m_currentMethod->m_outParameterStrings = match.captured(1).toLower().split(QStringLiteral(", "), Qt::SkipEmptyParts);
        m_currentMethod->m_name = match.captured(2);
        m_currentMethod->m_inParameterStrings = match.captured(3).split(QStringLiteral(", "), Qt::SkipEmptyParts);
        m_currentMethod->m_stringTags = match.captured(4).toLower().split(QStringLiteral(", "), Qt::SkipEmptyParts);
        m_currentMethod->m_limitation = match.captured(5).toLower();
    } else if (m_currentMethod) {
        // Skip first empty line
        if (line.isEmpty() && m_currentMethod->m_comment.isEmpty()) {
            return;
        }
        m_currentMethod->m_comment.append(line);
    }
}

bool Methods::finalize()
{
    bool success = true;

    for (auto &method : m_methods) {
        success &= method.finalize();
    }

    return success;
}

std::list<Method> Methods::methods() const
{
    return m_methods;
}