#include "message.h" #include #include #include Message::Message(QString str) { if(str.startsWith("PING")) { command = "PING"; nick = str.split(':')[1]; args = nick; target = nick; } else { /* Regex parsing (not working yet) *//* QRegExp commandAndTargetRegex(" ([^ ]+) "); QRegExp nameRegex(":([^ ]+)![^ ]+ "); QRegExp nameRegex2(":([^ ]+) "); QRegExp argsRegex(":[^ ]+ [^:]+:(.*)"); int pos = commandAndTargetRegex.indexIn(str); command = commandAndTargetRegex.cap(1); pos = commandAndTargetRegex.indexIn(str, pos); target = commandAndTargetRegex.cap(1); if(commandAndTargetRegex.indexIn(str, pos) != -1) target2 = commandAndTargetRegex.cap(1); if(nameRegex.indexIn(str) == -1) { nameRegex2.indexIn(str); nick = nameRegex2.cap(1); } else nick = nameRegex.cap(1); argsRegex.indexIn(str); args = argsRegex.cap(1); */ /* manual parsing */ // remove the first char, which is ':' str = str.remove(0, 1); // the interesting infos are separated by spaces QStringList list = str.split(' '); // source of the message (creates the user if he is new) QString temp = list.takeFirst(); nick = temp.left(temp.indexOf('!')); // command issued by the source command = list.takeFirst(); // target of the command target = list.takeFirst(); if(!list.empty()) target2 = list.takeFirst(); // locate the mid ':' separator int mid = str.indexOf(':', temp.length()+1); // the arguments are after the separator args = str.right(str.size()-(mid+1)); } } Message::~Message() { }