#include <NCWordWrapper.h>
Public Member Functions | |
NCWordWrapper () | |
void | setText (const std::wstring &origText) |
void | setLineWidth (int width) |
int | lines () |
const std::wstring & | wrappedText () |
const std::wstring & | origText () const |
int | lineWidth () const |
void | wrap () |
void | clear () |
Static Public Member Functions | |
static std::wstring | normalizeWhitespace (const std::wstring &orig) |
Protected Member Functions | |
void | ensureWrapped () |
std::wstring | nextLine (std::wstring &unwrapped) |
Protected Attributes | |
std::wstring | _origText |
std::wstring | _wrappedText |
int | _lineWidth |
int | _lines |
bool | _dirty |
Helper class to word-wrap text into a specified maximum line width. Whitespace is normalized in the process, i.e. any sequence of whitespace (blanks, newlines, tabs, ...) is replaced by a single blank. All lines end with a single newline character except the last one which has no newline.
NCWordWrapper::NCWordWrapper | ( | ) |
Constructor.
void NCWordWrapper::clear | ( | ) |
Clear the old content.
|
protected |
Do the wrapping if necessary.
int NCWordWrapper::lines | ( | ) |
Return the number of lines after wrapping the original text.
|
inline |
Return the last used maximum line width.
|
protected |
Return the next line that fits into the line width and removed it from 'unwrapped'.
|
static |
Return a string where any sequence of whitespace in the original text is replaced with a single blank and without leading or trailing whitespace.
|
inline |
Return the original unwrapped text.
void NCWordWrapper::setLineWidth | ( | int | width | ) |
Set the maximum line width to wrap into.
void NCWordWrapper::setText | ( | const std::wstring & | origText | ) |
Set the original text to wrap.
void NCWordWrapper::wrap | ( | ) |
Do the wrapping.
This normally doesn't need to be called manually; it is done automatically when retrieving the wrapped text or the number of wrapped lines (and when the internal 'dirty' flag is set).
But it can be useful to call it manually for debugging and testing.
const wstring & NCWordWrapper::wrappedText | ( | ) |
Wrap the original text and return the wrapped text.