I've been trying repeatly and rewritting it over billions of times it seems.

But when I'm connecting to a irc server with my QTcpSocket. Some lines are malformed. where it is split to a new line.

So I thought I could just do it to where check if the line starts without a ':' append it to the previous line. But apparently that causes some lines to be mixed together and what not. And I can't find hardly any resources on doing it correctly.

Qt Code:
  1. void
  2. IrcSocket::readSocket() {
  3. if(!m_ircSocket->canReadLine()) {
  4. return;
  5. }
  6.  
  7. QTextStream stream(m_ircSocket);
  8. QString data;
  9.  
  10. do {
  11. data = stream.readLine();
  12.  
  13. if(data[0] != ':') {
  14. QStringList words = data.split(" ");
  15.  
  16. if(words.count() >= 2) {
  17. if(words[0] == "NOTICE" && words[1] == "AUTH") {
  18. QRegExp reg("^NOTICE AUTH :(.+)$");
  19.  
  20. if(reg.exactMatch(data)) {
  21. emit noticeAuth(reg.cap(1));
  22. }
  23. } else {
  24. data.append(stream.readLine());
  25. }
  26. } else {
  27. data.append(stream.readLine());
  28. }
  29. } else {
  30. QStringList words = data.split(" ");
  31.  
  32. switch(words[1].toUInt()) {
  33. case 001: {
  34. QRegExp reg("^[^ ]+ 001 [^ ]+ :(.+)$", Qt::CaseInsensitive);
  35.  
  36. if(reg.exactMatch(data)) {
  37. emit welcome(reg.cap(1));
  38. } else {
  39. data.append(stream.readLine());
  40. }
  41. }
  42. case ReplyCode::RPL_MOTDSTART: {
  43. QRegExp reg("^[^ ]+ 375 [^ ]+ :(.+)$", Qt::CaseInsensitive);
  44.  
  45. if(reg.exactMatch(data)) {
  46. emit motdStart(reg.cap(1));
  47. } else {
  48. data.append(stream.readLine());
  49. }
  50. break;
  51. }
  52. case ReplyCode::RPL_MOTD: {
  53. QRegExp reg("^[^ ]+ 327 [^ ]+ :(.+)$", Qt::CaseInsensitive);
  54. kDebug() << data;
  55. if(reg.exactMatch(data)) {
  56. kDebug() << "TEST: " << reg.cap(1);
  57. data.clear();
  58. } else {
  59. data.append(stream.readLine());
  60. }
  61. break;
  62. }
  63. default: {
  64. data.append(stream.readLine());
  65. break;
  66. }
  67. }
  68. }
  69.  
  70. kDebug() << data;
  71. } while(!stream.atEnd());
  72. }
To copy to clipboard, switch view to plain text mode