File indexing completed on 2021-12-21 14:36:55

0001 /*
0002     SPDX-FileCopyrightText: 2008 Rolf Eike Beer <kde@opensource.sf-tec.de>
0003     SPDX-FileCopyrightText: 2016 Andrius Štikonas <andrius@stikonas.eu>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "klinebufferedprocess.h"
0008 
0009 KLineBufferedProcessPrivate::KLineBufferedProcessPrivate(KLineBufferedProcess *parent)
0010  : QObject(parent),
0011    m_newlineInStdout(-1),
0012    m_newlineInStderr(-1),
0013    m_parent(parent),
0014 #ifdef Q_OS_WIN     //krazy:exclude=cpp
0015    m_lineEnd("\r\n")
0016 #else
0017    m_lineEnd("\n")
0018 #endif
0019 {
0020 }
0021 
0022 void KLineBufferedProcessPrivate::_k_receivedStdout()
0023 {
0024     QByteArray ndata = m_parent->readAllStandardOutput();
0025     int oldBufferSize = m_stdoutBuffer.size();
0026     m_stdoutBuffer.append(ndata);
0027 
0028     if (m_newlineInStdout < 0) {
0029         m_newlineInStdout = ndata.indexOf(m_lineEnd);
0030         if (m_newlineInStdout >= 0) {
0031             m_newlineInStdout += oldBufferSize;
0032             Q_EMIT m_parent->lineReadyStandardOutput();
0033         }
0034     }
0035 }
0036 
0037 void KLineBufferedProcessPrivate::_k_receivedStderr()
0038 {
0039     QByteArray ndata = m_parent->readAllStandardError();
0040     int oldBufferSize = m_stderrBuffer.size();
0041     m_stderrBuffer.append(ndata);
0042 
0043    if (m_newlineInStderr < 0) {
0044         m_newlineInStderr = ndata.indexOf(m_lineEnd);
0045         if (m_newlineInStderr >= 0) {
0046             m_newlineInStderr += oldBufferSize;
0047             Q_EMIT m_parent->lineReadyStandardError();
0048         }
0049     }
0050 }