summaryrefslogtreecommitdiffstats
path: root/src/platformsupport/input/shared/qevdevutil.cpp
blob: 4557ac9deff2b61eace5a7affbcff58b133e48a9 (plain)
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
// Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qevdevutil_p.h"

QT_BEGIN_NAMESPACE

using namespace Qt::StringLiterals;

namespace QEvdevUtil {

ParsedSpecification parseSpecification(const QString &specification)
{
    ParsedSpecification result;

    result.args = QStringView{specification}.split(u':');

    for (const auto &arg : qAsConst(result.args)) {
        if (arg.startsWith("/dev/"_L1)) {
            // if device is specified try to use it
            result.devices.append(arg.toString());
        } else {
            // build new specification without /dev/ elements
            result.spec += arg + u':';
        }
    }

    if (!result.spec.isEmpty())
        result.spec.chop(1); // remove trailing ':'

    return result;
}

} // namespace QEvdevUtil

QT_END_NAMESPACE