qgis/QGIS — pull request #1181 by nirvn (2014-02-16 14:59:13+00:00)
Title: [expression] implement a wordwrap function (feature request #9412)

(See http://hub.qgis.org/issues/9412 for background information)

This is a simple implementation of a wordwrap() function, very useful string function when it comes to improving auto-generated multi-line labels. The function takes three parameters: wordwrap(string,delimiter,minimum_characters_to_wrap).

Take this simple label example: "University of Technology", where a one line label might be too wide. Currently, the user can decide to wrap label on the space character, resulting in the following 3-line label:
University
of
Technology

The wordwrap function improves things as it avoids creating lines of too few characters (think 'of', 'the', 'and', etc.). The following expression wordwrap('University of Technology',' ',3) would result in the much improved 2-line label:
University
of Technology

I realize it must be way too late to be included in 2.2, yet I'd like to point out that it'd be a very nice function to offer to users sooner than later, and that the implementation is _very_ simple and does not add any infrastructure to QGIS. It mimics the many other string functions that have been thoroughly tested.

Jury, I rest my case :)