Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mircparser.h"
- #include <KDebug>
- #include <QTextStream>
- using namespace Aki;
- namespace Aki
- {
- class MIrcParserPrivate
- {
- public:
- MIrcParserPrivate(Aki::MIrcParser *qq)
- : q(qq)
- {
- }
- void readServerLine(const QString &str)
- {
- QString line = str;
- Aki::ServerPointer server(new Aki::Server);
- QStringList addresses;
- // Remove the nXX= part from the beginning of the string since
- // it is useless.
- QString tmp = line.left(line.indexOf('='));
- line.remove(0, tmp.length() + 1);
- QStringList serversSplit = line.split("SERVER:", QString::SkipEmptyParts, Qt::CaseInsensitive);
- QString serverName = serversSplit[0];
- QString addressGroup = serversSplit[1];
- server->setName(serverName);
- QStringList groupSplit = addressGroup.split("GROUP:", QString::SkipEmptyParts, Qt::CaseInsensitive);
- QString addressPort = groupSplit[0];
- QStringList addressPortSplit = addressPort.split(':');
- QString address = addressPortSplit[0];
- QStringList portSplit = addressPortSplit[1].split('.');
- QStringListIterator portIter(portSplit);
- while (portIter.hasNext()) {
- QString ports = portIter.next().trimmed();
- if (ports.contains('-')) {
- QStringList lowHighSplit = ports.split('-');
- int low = lowHighSplit[0].toInt();
- int high = lowHighSplit[1].toInt();
- for (int i = low; i < high + 1; ++i) {
- addresses << address + '/' + QString::number(i);
- }
- } else {
- addresses << address + '/' + ports;
- }
- }
- if (!addresses.isEmpty()) {
- server->setAddressList(addresses);
- servers << server;
- }
- }
- Aki::MIrcParser *q;
- Aki::ServerList servers;
- }; // End of class MIrcParserPrivate.
- } // End of namespace Aki.
- MIrcParser::MIrcParser(QObject *parent)
- : QObject(parent)
- {
- d.reset(new Aki::MIrcParserPrivate(this));
- }
- MIrcParser::~MIrcParser()
- {
- }
- bool
- MIrcParser::read(QIODevice *device)
- {
- if (!device) {
- return false;
- }
- QString line;
- QTextStream in(device);
- while (!in.atEnd()) {
- line = in.readLine().trimmed();
- if (line[0] == 'n') {
- d->readServerLine(line);
- }
- }
- device->close();
- return true;
- }
- Aki::ServerList
- MIrcParser::servers() const
- {
- return d->servers;
- }
Add Comment
Please, Sign In to add comment