File: Properties.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 (62 lines) | stat: -rw-r--r-- 1,832 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
/*
 * 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 "Properties.h"

#include <QRegularExpression>
#include <QStringList>

Properties::Properties()
{
}

void Properties::parse(const QString &line)
{
    const QRegularExpression rx(
        QStringLiteral("(?:Properties|^)" // Properties keyword or start of line
                       "\\t{1,2}" // preceding tabs (max 2)
                       "([a-z1-6{}_]+)" // type name
                       " " // space
                       "([A-Z]\\w+)" // method name
                       "(?: \\[(.*)\\])?" // tags
                       "(?: \\((.*)\\))?" // limitations
                       ));

    QRegularExpressionMatch match = rx.match(line);
    // Check if we match a property
    if (match.hasMatch()) {
        m_properties.emplace_back(Property());
        m_currentProperty = &m_properties.back();
        m_currentProperty->m_type = match.captured(1).toLower();
        m_currentProperty->m_name = match.captured(2);
        m_currentProperty->m_stringTags = match.captured(3).toLower().split(QStringLiteral(", "), Qt::SkipEmptyParts);
        m_currentProperty->m_limitation = match.captured(4).toLower();
    } else if (m_currentProperty) {
        // Skip first empty line
        if (line.isEmpty() && m_currentProperty->m_comment.isEmpty()) {
            return;
        }
        m_currentProperty->m_comment.append(line);
    }
}

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

    for (auto &property : m_properties) {
        success &= property.finalize();
    }

    return success;
}

std::list<Property> Properties::properties() const
{
    return m_properties;
}