QtNovelUI/DesParser/WordsPeak.cpp

50 lines
1004 B
C++
Raw Normal View History

2022-11-06 00:37:50 +00:00
#include "WordsPeak.h"
#include <QDebug>
2022-11-06 11:40:11 +00:00
using namespace Lex;
2022-11-06 00:37:50 +00:00
2022-11-06 11:40:11 +00:00
ExStream::ExStream() :file_target(nullptr), text_input(nullptr),
2022-11-06 00:37:50 +00:00
current_line(""), current_row(-1), current_col(0) {}
2022-11-06 11:40:11 +00:00
ExStream::~ExStream() {
2022-11-06 00:37:50 +00:00
if (file_target)
delete file_target;
if (text_input)
delete text_input;
}
2022-11-06 11:40:11 +00:00
int ExStream::initSource(const QString & path)
2022-11-06 00:37:50 +00:00
{
if (file_target)
delete file_target;
if (text_input)
delete text_input;
if (!QFile(path).exists())
return -1;
file_target = new QFile(path);
if (!file_target->open(QIODevice::ReadOnly | QIODevice::Text))
return -2;
text_input = new QTextStream(file_target);
return 0;
}
2022-11-06 11:40:11 +00:00
std::tuple<ExStream::n_row, ExStream::n_col, QChar> ExStream::read()
2022-11-06 00:37:50 +00:00
{
if (current_col >= current_line.length()) {
if (!text_input->atEnd()) {
current_row++;
current_col = 0;
current_line = text_input->readLine() + '\n';
}
else {
return std::make_tuple(-1, -1, EOF);
}
}
return std::make_tuple(current_row, current_col, current_line[current_col++]);
}