KPublicTransport

lineutil.cpp
1/*
2 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "lineutil_p.h"
8#include "linecompare_p.h"
9
10#include <knowledgedb/linemetadata.h>
11
12#include <KPublicTransport/Location>
13
14#include <QColor>
15#include <QDebug>
16#include <QString>
17#include <QUrl>
18
19using namespace KPublicTransport;
20
21bool LineUtil::isSameLineNameStrict(const QString &lhs, const QString &rhs)
22{
23 return Internal::isSameLineName(lhs, rhs, Internal::StrictCompare);
24}
25
26bool LineUtil::isSameLineNameFuzzy(const QString &lhs, const QString &rhs)
27{
28 return Internal::isSameLineName(lhs, rhs, Internal::FuzzyCompare);
29}
30
31bool LineUtil::isHighlyIdentifyingName(QStringView s)
32{
33 return s.size() >= 2
34 && std::any_of(s.begin(), s.end(), [](QChar c) { return c.isDigit(); })
35 && std::any_of(s.begin(), s.end(), [](QChar c) { return c.isLetter(); });
36}
37
38bool LineUtil::isCompatibleMode(Line::Mode lhs, Line::Mode rhs)
39{
40 if (lhs == rhs || lhs == Line::Unknown || rhs == Line::Unknown) {
41 return true;
42 }
43
44 if (lhs == Line::Train) {
45 return rhs == Line::LocalTrain || rhs == Line::LongDistanceTrain || rhs == Line::RapidTransit;
46 }
47 if (rhs == Line::Train) {
48 return lhs == Line::LocalTrain || lhs == Line::LongDistanceTrain || lhs == Line::RapidTransit;
49 }
50
51 if (lhs == Line::Bus) {
52 return rhs == Line::Coach || rhs == Line::Shuttle;
53 }
54 if (rhs == Line::Bus) {
55 return lhs == Line::Coach || lhs == Line::Shuttle;
56 }
57
58 if (lhs == Line::Boat) {
59 return rhs == Line::Ferry;
60 }
61 if (rhs == Line::Boat) {
62 return lhs == Line::Ferry;
63 }
64
65 return false;
66}
67
68bool LineUtil::isCompatibleBaseMode(Line::Mode lhs, Line::Mode rhs)
69{
70 if ((lhs == Line::RapidTransit || lhs == Line::Metro || lhs == Line::Tramway)
71 && (rhs == Line::RapidTransit || rhs == Line::Metro || rhs == Line::Tramway)) {
72 return true;
73 }
74
75 return isCompatibleMode(lhs, rhs);
76}
Mode
Mode of transportation.
Definition line.h:27
@ Shuttle
shuttle bus/coach services, e.g. to/from an airport
Definition line.h:40
Query operations and data types for accessing realtime public transport information from online servi...
const_iterator begin() const const
const_iterator end() const const
qsizetype size() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 11:53:27 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.