KPublicTransport

jsonp.cpp
1/*
2 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "jsonp_p.h"
7
8#include <QByteArray>
9
10using namespace KPublicTransport;
11
12QByteArray JsonP::decode(const QByteArray &data)
13{
14 const auto firstBrace = data.indexOf('{');
15 const auto firstBracket = data.indexOf('[');
16
17 if (firstBrace == 0 || firstBracket == 0 || (firstBrace < 0 && firstBracket < 0)) {
18 return data;
19 }
20
21 if (firstBrace > 0 && (firstBrace < firstBracket || firstBracket < 0)) {
22 const auto lastBrace = data.lastIndexOf('}');
23 return lastBrace > firstBrace ? data.mid(firstBrace, lastBrace - firstBrace + 1) : data;
24 }
25
26 if (firstBracket > 0 && (firstBracket < firstBrace || firstBrace < 0)) {
27 const auto lastBracket = data.lastIndexOf(']');
28 return lastBracket > firstBracket ? data.mid(firstBracket, lastBracket - firstBracket +1) : data;
29 }
30
31 return data;
32}
Query operations and data types for accessing realtime public transport information from online servi...
qsizetype indexOf(QByteArrayView bv, qsizetype from) const const
qsizetype lastIndexOf(QByteArrayView bv) const const
QByteArray mid(qsizetype pos, qsizetype len) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.