File indexing completed on 2024-05-05 04:39:00

0001 /*
0002     SPDX-FileCopyrightText: 2008 Cédric Pasteur <cedric.pasteur@free.fr>
0003     SPDX-FileCopyrightText: 2001 Matthias Hölzer-Klüpfel <mhk@caldera.de>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "astyle_stringiterator.h"
0009 
0010 #include <string>
0011 
0012 AStyleStringIterator::AStyleStringIterator(const QString &text)
0013     : ASSourceIterator()
0014     , m_content(text)
0015     , m_is(&m_content, QIODevice::ReadOnly)
0016     , m_peekStart(-1)
0017 {
0018 }
0019 
0020 
0021 AStyleStringIterator::~AStyleStringIterator()
0022 {
0023 }
0024 
0025 std::streamoff AStyleStringIterator::tellg()
0026 {
0027   return m_is.pos();
0028 }
0029 
0030 int AStyleStringIterator::getStreamLength() const
0031 {
0032   return m_content.size();
0033 }
0034 
0035 bool AStyleStringIterator::hasMoreLines() const
0036 {
0037   return !m_is.atEnd();
0038 }
0039 
0040 
0041 std::string AStyleStringIterator::nextLine(bool emptyLineWasDeleted)
0042 {
0043   Q_UNUSED(emptyLineWasDeleted)
0044   return m_is.readLine().toUtf8().data();
0045 }
0046 
0047 std::string AStyleStringIterator::peekNextLine()
0048 {
0049     if (m_peekStart == -1) {
0050         m_peekStart = m_is.pos();
0051     }
0052     return m_is.readLine().toUtf8().data();
0053 }
0054 
0055 void AStyleStringIterator::peekReset()
0056 {
0057     if(m_peekStart != -1)
0058         m_is.seek(m_peekStart);
0059     m_peekStart = -1; // invalid
0060 }
0061 
0062 std::streamoff AStyleStringIterator::getPeekStart() const
0063 {
0064     // NOTE: we're not entirely sure if this is the correct implementation.
0065     // we're trying to work-around https://bugs.kde.org/show_bug.cgi?id=399048
0066     return m_peekStart == -1 ? 0 : m_peekStart;
0067 }
0068 
0069