diff --git a/src/catalog/gettext/gettextexport.cpp b/src/catalog/gettext/gettextexport.cpp --- a/src/catalog/gettext/gettextexport.cpp +++ b/src/catalog/gettext/gettextexport.cpp @@ -253,14 +253,15 @@ return; } - // lazy wrapping - QStringList list = text.split( '\n', QString::SkipEmptyParts ); - - if ( text.startsWith( '\n' ) ) - list.prepend( QString() ); - - if(list.isEmpty()) - list.append( QString() ); + // Remove newlines and re-add them where they needed + text.remove("\n"); + text.replace("\\n","\\n\n"); + QStringList list = text.split( "\n", QString::KeepEmptyParts ); + + // Remove last entry if it's empty + if (list.last() == "") { + list.removeLast(); + } //static QRegExp breakStopReForHtml("[ >.%/:,]", Qt::CaseSensitive, QRegExp::Wildcard); //static QRegExp breakStopReForText("[ .%/:,]", Qt::CaseSensitive, QRegExp::Wildcard); @@ -269,52 +270,47 @@ QRegExp breakStopRe=containsHtml?breakStopReForHtml:breakStopReForText; int max=m_wrapWidth-2; - bool prependedEmptyLine=false; QStringList::iterator itm; for( itm = list.begin(); itm != list.end(); ++itm ) { - if (list.count()==1 && keyword.length()+1+itm->length()>=max) - { - prependedEmptyLine=true; - itm=list.insert(itm,QString()); - } - - if (itm->length()>max) + if (itm->length() > max-1) { - int pos = itm->lastIndexOf(breakStopRe,max-1); + int pos = itm->lastIndexOf(breakStopRe, max-2); if (pos>(max/2)) { - int pos2 = itm->indexOf(QLatin1Char('<'),pos); - if (pos2>0&&pos2indexOf(QLatin1Char('<'), pos); + if (pos2 > 0 && pos2 < max-1) { - pos=itm->indexOf(QLatin1Char('<'),pos); + pos=itm->indexOf(QLatin1Char('<'), pos); ++pos; } } else { - if (itm->at(max-1)==QLatin1Char('\\')) + if (itm->at(max-1) == QLatin1Char('\\')) { do {--max;} - while (max>=2 && itm->at(max-1)==QLatin1Char('\\')); + while (max >= 2 && itm->at(max-1) == QLatin1Char('\\')); } pos=max; } //itm=list.insert(itm,itm->left(pos)); - QString t=*itm; - itm=list.insert(itm,t); + QString t = *itm; + itm = list.insert(itm, t); ++itm; if (itm != list.end()) { - (*itm)=itm->remove(0,pos); + (*itm) = itm->remove(0, pos+1); --itm; if (itm != list.end()) - itm->truncate(pos); + itm->truncate(pos+1); } } } - if( !prependedEmptyLine && list.count() > 1 ) + // Add prepended empty line for multilined messages or + // for those that with keyword exceed limit + if (list.count() > 1 || list.first().length() + keyword.length() > max-2) list.prepend( QString() ); stream << keyword << QStringLiteral(" ");