libyui-ncurses  2.55.0
NCWordWrapper Class Reference

Helper class to word-wrap text into a specified maximum line width. More...

#include <NCWordWrapper.h>

Collaboration diagram for NCWordWrapper:

Public Member Functions

 NCWordWrapper ()
 Constructor.
 
void setText (const std::wstring &origText)
 Set the original text to wrap.
 
void setLineWidth (int width)
 Set the maximum line width to wrap into.
 
int lines ()
 Return the number of lines after wrapping the original text.
 
const std::wstring & wrappedText ()
 Wrap the original text and return the wrapped text.
 
const std::wstring & origText () const
 Return the original unwrapped text.
 
int lineWidth () const
 Return the last used maximum line width.
 
void wrap ()
 Do the wrapping. More...
 
void clear ()
 Clear the old content.
 

Static Public Member Functions

static std::wstring normalizeWhitespace (const std::wstring &orig)
 Return a string where any sequence of whitespace in the original text is replaced with a single blank and without leading or trailing whitespace.
 

Protected Member Functions

void ensureWrapped ()
 Do the wrapping if necessary.
 
std::wstring nextLine (std::wstring &unwrapped)
 Return the next line that fits into the line width and removed it from 'unwrapped'.
 

Protected Attributes

std::wstring _origText
 
std::wstring _wrappedText
 
int _lineWidth
 
int _lines
 
bool _dirty
 

Detailed Description

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.

Definition at line 38 of file NCWordWrapper.h.

Member Function Documentation

◆ 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.

Definition at line 145 of file NCWordWrapper.cc.

Here is the call graph for this function:

The documentation for this class was generated from the following files: