Debian Codegraph @

Source/Parser/FunctionalJAVACC/CQtIODeviceStreamReader.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CQtIODeviceStreamReader.h"
22
23
24 namespace Konclude {
25
26 namespace Parser {
27
28 namespace FunctionalJAVACC {
29
30 CQtIODeviceStreamReader::CQtIODeviceStreamReader(QIODevice* device) : mDevice(device) {
31 }
32
33 size_t CQtIODeviceStreamReader::read(JAVACC_CHAR_TYPE *bufptr, int offset, size_t len) {
34 int remainingLength = len;
35 size_t readSize = 0;
36 if (!mConvBuffer.isEmpty()) {
37 int length = mConvBuffer.length();
38 int copyLength = qMin(remainingLength,length);
39 for (int i = 0; i < copyLength; ++i) {
40 bufptr[offset+i] = mConvBuffer[i].unicode();
41 }
42 remainingLength = remainingLength - copyLength;
43 offset += copyLength;
44 if (copyLength == length) {
45 mConvBuffer.clear();
46 } else {
47 mConvBuffer = mConvBuffer.mid(copyLength);
48 }
49 readSize += copyLength;
50 }
51 if (!mDevice->atEnd() && remainingLength > 0 && mConvBuffer.isEmpty()) {
52 QByteArray lineByteData(mDevice->readLine());
53 mConvBuffer = QString::fromUtf8(lineByteData.constData(),lineByteData.length());
54
55 if (!mConvBuffer.isEmpty()) {
56 int length = mConvBuffer.length();
57 int copyLength = qMin(remainingLength,length);
58 for (int i = 0; i < copyLength; ++i) {
59 bufptr[offset+i] = mConvBuffer[i].unicode();
60 }
61 remainingLength = remainingLength - copyLength;
62 offset += copyLength;
63 if (copyLength == length) {
64 mConvBuffer.clear();
65 } else {
66 mConvBuffer = mConvBuffer.mid(copyLength);
67 }
68 readSize += copyLength;
69 }
70
71 }
72 return readSize;
73 }
74
75 bool CQtIODeviceStreamReader::endOfInput() {
76 return mConvBuffer.isEmpty() && mDevice->atEnd();
77 }
78
79
80 }; // end namespace FunctionalJAVACC
81
82 }; // end namespace Parser
83
84 }; // end namespace Konclude