Changeset View
Changeset View
Standalone View
Standalone View
src/catalog/gettext/gettextexport.cpp
Context not available. | |||||
253 | return; | 253 | return; | ||
---|---|---|---|---|---|
254 | } | 254 | } | ||
255 | 255 | | |||
256 | // lazy wrapping | 256 | // Remove newlines and re-add them where they needed | ||
257 | QStringList list = text.split( '\n', QString::SkipEmptyParts ); | 257 | text.remove("\n"); | ||
258 | 258 | text.replace("\\n","\\n\n"); | |||
259 | if ( text.startsWith( '\n' ) ) | 259 | QStringList list = text.split( "\n", QString::KeepEmptyParts ); | ||
260 | list.prepend( QString() ); | 260 | | ||
261 | 261 | // Remove last entry if it's empty | |||
262 | if(list.isEmpty()) | 262 | if (list.last() == "") { | ||
263 | list.append( QString() ); | 263 | list.removeLast(); | ||
264 | } | ||||
264 | 265 | | |||
265 | //static QRegExp breakStopReForHtml("[ >.%/:,]", Qt::CaseSensitive, QRegExp::Wildcard); | 266 | //static QRegExp breakStopReForHtml("[ >.%/:,]", Qt::CaseSensitive, QRegExp::Wildcard); | ||
266 | //static QRegExp breakStopReForText("[ .%/:,]", Qt::CaseSensitive, QRegExp::Wildcard); | 267 | //static QRegExp breakStopReForText("[ .%/:,]", Qt::CaseSensitive, QRegExp::Wildcard); | ||
Context not available. | |||||
269 | QRegExp breakStopRe=containsHtml?breakStopReForHtml:breakStopReForText; | 270 | QRegExp breakStopRe=containsHtml?breakStopReForHtml:breakStopReForText; | ||
270 | 271 | | |||
271 | int max=m_wrapWidth-2; | 272 | int max=m_wrapWidth-2; | ||
272 | bool prependedEmptyLine=false; | | |||
273 | QStringList::iterator itm; | 273 | QStringList::iterator itm; | ||
274 | for( itm = list.begin(); itm != list.end(); ++itm ) | 274 | for( itm = list.begin(); itm != list.end(); ++itm ) | ||
275 | { | 275 | { | ||
276 | if (list.count()==1 && keyword.length()+1+itm->length()>=max) | 276 | if (itm->length() > max-1) | ||
277 | { | | |||
278 | prependedEmptyLine=true; | | |||
279 | itm=list.insert(itm,QString()); | | |||
280 | } | | |||
281 | | ||||
282 | if (itm->length()>max) | | |||
283 | { | 277 | { | ||
284 | int pos = itm->lastIndexOf(breakStopRe,max-1); | 278 | int pos = itm->lastIndexOf(breakStopRe, max-2); | ||
285 | if (pos>(max/2)) | 279 | if (pos>(max/2)) | ||
286 | { | 280 | { | ||
287 | int pos2 = itm->indexOf(QLatin1Char('<'),pos); | 281 | int pos2 = itm->indexOf(QLatin1Char('<'), pos); | ||
288 | if (pos2>0&&pos2<max-1) | 282 | if (pos2 > 0 && pos2 < max-1) | ||
289 | { | 283 | { | ||
290 | pos=itm->indexOf(QLatin1Char('<'),pos); | 284 | pos=itm->indexOf(QLatin1Char('<'), pos); | ||
291 | ++pos; | 285 | ++pos; | ||
292 | } | 286 | } | ||
293 | } | 287 | } | ||
294 | else | 288 | else | ||
295 | { | 289 | { | ||
296 | if (itm->at(max-1)==QLatin1Char('\\')) | 290 | if (itm->at(max-1) == QLatin1Char('\\')) | ||
297 | { | 291 | { | ||
298 | do {--max;} | 292 | do {--max;} | ||
299 | while (max>=2 && itm->at(max-1)==QLatin1Char('\\')); | 293 | while (max >= 2 && itm->at(max-1) == QLatin1Char('\\')); | ||
300 | } | 294 | } | ||
301 | pos=max; | 295 | pos=max; | ||
302 | } | 296 | } | ||
303 | //itm=list.insert(itm,itm->left(pos)); | 297 | //itm=list.insert(itm,itm->left(pos)); | ||
304 | QString t=*itm; | 298 | QString t = *itm; | ||
305 | itm=list.insert(itm,t); | 299 | itm = list.insert(itm, t); | ||
306 | ++itm; | 300 | ++itm; | ||
307 | if (itm != list.end()) | 301 | if (itm != list.end()) | ||
308 | { | 302 | { | ||
309 | (*itm)=itm->remove(0,pos); | 303 | (*itm) = itm->remove(0, pos+1); | ||
310 | --itm; | 304 | --itm; | ||
311 | if (itm != list.end()) | 305 | if (itm != list.end()) | ||
312 | itm->truncate(pos); | 306 | itm->truncate(pos+1); | ||
313 | } | 307 | } | ||
314 | } | 308 | } | ||
315 | } | 309 | } | ||
316 | 310 | | |||
317 | if( !prependedEmptyLine && list.count() > 1 ) | 311 | // Add prepended empty line for multilined messages or | ||
312 | // for those that with keyword exceed limit | ||||
313 | if (list.count() > 1 || list.first().length() + keyword.length() > max-2) | ||||
318 | list.prepend( QString() ); | 314 | list.prepend( QString() ); | ||
319 | 315 | | |||
320 | stream << keyword << QStringLiteral(" "); | 316 | stream << keyword << QStringLiteral(" "); | ||
Context not available. |