Created by Przemysław 'Trol' Maciąg Just truncating a popup message text can cause situations like this: * text will be trancated 'inside' icon tag * text will be trancated 'inside' a tag both situations will give a bad string to show. Patch add a simple function to correct this situations (and similar ones). diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/common.cpp psi-0.10-test3/src/common.cpp --- psi-0.10-test3-orig/src/common.cpp 2005-11-01 18:10:29.000000000 +0100 +++ psi-0.10-test3/src/common.cpp 2005-12-23 12:11:08.000000000 +0100 @@ -314,6 +314,83 @@ return out; } +QString truncateRichText (const QString & intext, int textlen) +{ + QString outtext; + + int i, j, k; + int tag; + int opentags; + char c; + bool atag; + + k = intext.length (); + // do we have to truncate it at all? + if (k <= textlen) + return intext; + + tag = -1; + atag = false; + j = 0; + opentags = 0; + + for (i = 0; i < k; i++) + { + c = intext.at(i); + // opening tag + if (c == QChar ('<')) + { + if (opentags == 0) + { + tag = i; + if (atag) + atag = false; + } + opentags++; + } + // closing tag + else if (c == QChar ('>')) + { + if (opentags == 1) + { + if (atag) + // don't count a tag - only letters 'inside' + j--; + else + j++; + tag = -1; + } + opentags--; + } + // normal character? + else if (opentags == 0) + { + j++; + } + // a tag? + else if (i == (tag + 1) && c == QChar ( 'a' ) && k > (i + 1)) + { + c = intext.at((i + 1)); + // next character has to be a whitespace + if (c == QChar ( (char)32 ) || c == QChar ( '\t' )) + { + atag = true; + // we don't need to check this character ones more + i++; + } + } + + if (opentags == 0 && j >= textlen) + break; + } + + outtext = intext.left (i); + // unclosed 'a' tag? + if (atag) + outtext += ""; + + return outtext; +} // clips plain text QString clipStatus(const QString &str, int width, int height) diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/common.h psi-0.10-test3/src/common.h --- psi-0.10-test3-orig/src/common.h 2005-10-06 15:50:35.000000000 +0200 +++ psi-0.10-test3/src/common.h 2005-12-23 12:11:08.000000000 +0100 @@ -238,6 +238,7 @@ QString qstrquote(const QString &, int width=60, bool quoteEmpty=FALSE); QString plain2rich(const QString &); QString rich2plain(const QString &); +QString truncateRichText (const QString & intext, int textlen); QString clipStatus(const QString &str, int width, int height); QString expandEntities(const QString &in); QString resolveEntities(const QString &); diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/psipopup.cpp psi-0.10-test3/src/psipopup.cpp --- psi-0.10-test3-orig/src/psipopup.cpp 2005-10-14 02:36:14.000000000 +0200 +++ psi-0.10-test3/src/psipopup.cpp 2005-12-23 12:17:56.000000000 +0100 @@ -207,17 +207,9 @@ { if ( option.ppTextClip > 0 ) { // richtext will give us trouble here - if ( ((int)text.length()) > option.ppTextClip ) { - text = text.left( option.ppTextClip ); - - // delete last unclosed tag - /*if ( text.find(" text.find(">") ) { - - text = text.left( text.find("