Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(msg.startsWith("s/"))
- {
- qDebug() << this << "[SED]";
- // Regexp!
- QString buff = msg;
- QStringList args; args << "" << "" << "";
- int mode = -1;
- while(mode < 3 && buff.size())
- {
- if(buff.startsWith("\\/"))
- {
- if(mode >= 0)
- {
- args[mode].append("/");
- }
- buff.remove(0,2);
- }
- else if(buff.startsWith("/"))
- {
- mode ++;
- buff.remove(0,1);
- }
- else
- {
- if(mode >= 0)
- {
- args[mode].append(buff.left(1));
- }
- buff.remove(0,1);
- }
- }
- qDebug() << "[Sed] Args:" << args;
- QList<Message> log = m_history[target];
- QRegularExpression re(args[0]);
- int counter = 50;
- bool hasmatch = false;
- while(!hasmatch && log.size() && counter --)
- {
- Message subject = log.takeLast();
- QString history_msg = subject.getMsg();
- QString history_nick = subject.getNick()->name();
- if(args[2].contains("g"))
- {
- QRegularExpressionMatchIterator it = re.globalMatch(history_msg);
- int offset = 0;
- while(it.hasNext())
- {
- hasmatch = true;
- QString rplc = args[1];
- QRegularExpressionMatch ma = it.next();
- for(int II = ma.lastCapturedIndex(); II >= 0; II --)
- {
- QString m = ma.captured(II);
- rplc.replace(QString("\\%1").arg(II),m);
- }
- history_msg.replace(ma.capturedStart()+offset,ma.capturedLength(),rplc);
- offset += rplc.length() - ma.capturedLength();
- }
- }
- else
- {
- QRegularExpressionMatch ma = re.match(history_msg);
- QString rplc = args[1];
- if((hasmatch = ma.hasMatch()))
- {
- for(int II = ma.lastCapturedIndex(); II >= 0; II --)
- {
- QString m = ma.captured(II);
- rplc.replace(QString("\\%1").arg(II),m);
- }
- history_msg.replace(ma.capturedStart(),ma.capturedLength(),rplc);
- }
- }
- if(hasmatch)
- {
- say(target,QString("<%1> %2").arg(history_nick,history_msg));
- m_history[target] << Message(subject.getNick(),history_msg);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement