File indexing completed on 2024-05-12 04:42:47

0001 /*
0002     SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "polylinedecoder_p.h"
0008 
0009 using namespace KPublicTransport;
0010 
0011 int32_t PolylineDecoderBase::readNextIntNonDifferential()
0012 {
0013     int32_t result = 0;
0014     int shift = 0;
0015     char c = 0;
0016     do {
0017         if (canReadMore()) {
0018             c = *m_it;
0019             ++m_it;
0020             c -= 63;
0021             result |= (c & 0b11111) << shift;
0022             shift += 5;
0023         } else {
0024             return std::numeric_limits<int32_t>::max();
0025         }
0026     } while (c >= 0x20);
0027 
0028     if (result & 1) {
0029         result = ~result;
0030     }
0031     result >>= 1;
0032     return result;
0033 }