#include<QtCore>#include<iostream>#include<IrcCommand>#include<IrcMessage>namespaceCommuniBackport{boolparseColors(constQString&message,intpos,int*len,int*fg=0,int*bg=0){// fg(,bg)*len=0;if(fg)*fg=-1;if(bg)*bg=-1;QRegExprx(QLatin1String("(\\d{1,2})(?:,(\\d{1,2}))?"));intidx=rx.indexIn(message,pos);if(idx==pos){*len=rx.matchedLength();if(fg)*fg=rx.cap(1).toInt();if(bg){boolok=false;inttmp=rx.cap(2).toInt(&ok);if(ok)*bg=tmp;}}return*len>0;}/*!Converts \a text to plain text. This function parses the text andstrips away IRC-style formatting like colors, bold and underline.\sa toHtml()*/voidtoPlainText(QString&processed){intpos=0;intlen=0;while(pos<processed.size()){switch(processed.at(pos).unicode()){case'\x02':// boldcase'\x0f':// nonecase'\x13':// strike-throughcase'\x15':// underlinecase'\x16':// inversecase'\x1d':// italiccase'\x1f':// underlineprocessed.remove(pos,1);break;case'\x03':// colorif(parseColors(processed,pos+1,&len))processed.remove(pos,len+1);elseprocessed.remove(pos,1);break;default:++pos;break;}}}}