#include "pqassicbrhelp.h"

namespace PQ {

AssicBrHelp::AssicBrHelp()
{

}

AssicBrHelp::~AssicBrHelp()
{
}

void AssicBrHelp::readed(const QByteArray &data)
{
    int newstart = 0;
    int scan = m_inbuffer.size();

    m_inbuffer.append(data);

    while (newstart < m_inbuffer.size()) {
        int start = newstart;
        int end = m_inbuffer.indexOf('\n', scan);
        if (end < 0) {
            m_inbuffer.remove(0, start);
            return;
        }
        newstart = end + 1;
        scan = newstart;
        if (end == start)
            continue;
        if (m_inbuffer.at(end - 1) == '\r') {
            --end;
            if (end == start)
                continue;
        }
        QByteArray line(m_inbuffer.constData() + start, end - start);
        doHandle(line);
    }
    m_inbuffer.clear();
}

}
