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

0001 /*
0002     SPDX-FileCopyrightText: 2008 Rolf Eike Beer <kde@opensource.sf-tec.de>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "klinebufferedprocess.h"
0007 
0008 KLineBufferedProcess::KLineBufferedProcess(QObject *parent)
0009  : KProcess(parent),
0010    d(new KLineBufferedProcessPrivate(this))
0011 {
0012     connect(this, &KLineBufferedProcess::readyReadStandardOutput, d, &KLineBufferedProcessPrivate::_k_receivedStdout);
0013     connect(this, &KLineBufferedProcess::readyReadStandardError, d, &KLineBufferedProcessPrivate::_k_receivedStderr);
0014 }
0015 
0016 KLineBufferedProcess::~KLineBufferedProcess()
0017 {
0018 }
0019 
0020 bool KLineBufferedProcess::readLineStandardOutput(QByteArray *line)
0021 {
0022     if (d->m_newlineInStdout < 0) {
0023         return false;
0024     }
0025 
0026     // don't copy '\n'
0027     *line = d->m_stdoutBuffer.left(d->m_newlineInStdout);
0028     d->m_stdoutBuffer.remove(0, d->m_newlineInStdout + d->m_lineEnd.length());
0029 
0030     d->m_newlineInStdout = d->m_stdoutBuffer.indexOf(d->m_lineEnd);
0031 
0032     return true;
0033 }
0034 
0035 bool KLineBufferedProcess::readLineStandardError(QByteArray *line)
0036 {
0037     if (d->m_newlineInStderr < 0) {
0038         return false;
0039     }
0040 
0041     // don't copy '\n'
0042     *line = d->m_stderrBuffer.left(d->m_newlineInStderr);
0043     d->m_stderrBuffer.remove(0, d->m_newlineInStderr + d->m_lineEnd.length());
0044 
0045     d->m_newlineInStderr = d->m_stderrBuffer.indexOf(d->m_lineEnd);
0046 
0047     return true;
0048 }
0049 
0050 bool KLineBufferedProcess::hasLineStandardOutput() const
0051 {
0052     return d->m_newlineInStdout >= 0;
0053 }
0054 
0055 bool KLineBufferedProcess::hasLineStandardError() const
0056 {
0057     return d->m_newlineInStderr >= 0;
0058 }