ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
Paragraphs Class Reference

Description:

This class is used to format textual output, like console output.

One central static method is Format, which formats a "paragraph" that starts at a certain index of the managed AString buffer and reaches to its end.

When an instance of the class is created, the members of the class provide the text buffer as well as the other parameters which are needed for the static method. With methods Add, member Formatter is used to append the given parameters and then the new paragraph is formatted using the static method Format.
This way, a longer text might be built by repetitive calls.

Definition at line 32 of file paragraphs.hpp.

#include <paragraphs.hpp>

Collaboration diagram for Paragraphs:
[legend]

Public Static Method Index:

static ALIB_API void Format (AString &text, integer startIdx, integer lineWidth, character justifyChar, integer &maxLineWidth, const String &indentFirstLine=nullptr, const String &indentOtherLines=nullptr)
 

Public Field Index:

AStringBuffer
 
integer DetectedMaxLineWidth =0
 
SPFormatter Formatter
 
AStringMA IndentFirstLine
 
AStringMA IndentOtherLines
 
std::stack< integer, StdDequeMono< integer > > IndentSizesFirstLine
 
std::stack< integer, StdDequeMono< integer > > IndentSizesOtherLines
 
character JustifyChar = '\0'
 
integer LineWidth = 0
 Used as parameter lineWidth of static method invocations.
 
StdVectorMono< characterMarkerBullets
 
character MarkerChar = '@'
 

Public Method Index:

ALIB_API Paragraphs ()
 
ALIB_API Paragraphs (AString &externalBuffer)
 
template<typename TAllocatorArgs >
void Add (boxing::TBoxes< TAllocatorArgs > &args)
 
template<typename... BoxedObjects>
ParagraphsAdd (const BoxedObjects &... args)
 
template<typename TAllocatorArgs >
void AddMarked (boxing::TBoxes< TAllocatorArgs > &args)
 
template<typename... BoxedObjects>
ParagraphsAddMarked (const BoxedObjects &... args)
 
ALIB_API ParagraphsClear ()
 
ALIB_API ParagraphsPopIndent ()
 
ALIB_API ParagraphsPushIndent (const String &indentFirstLine, const String &indentOtherLines=nullptr)
 
ALIB_API ParagraphsPushIndent (uinteger qty, character fillChar=' ')
 
AStringRemoveLastNewLine ()
 

Protected Field Index:

MonoAllocator allocator
 Allocator used for internal container types.
 
BoxesMA boxes
 Internally reused list of boxes.
 
AString markedBuffer
 Buffer for processing marked text.
 
size_t markerBulletLevel =0
 Buffer for processing marked text.
 
AString text
 Internal buffer, used for field Paragraphs, if no external string object was given.
 

Field Details:

◆ allocator

MonoAllocator allocator
protected

Allocator used for internal container types.

Definition at line 39 of file paragraphs.hpp.

◆ boxes

BoxesMA boxes
protected

Internally reused list of boxes.

Definition at line 106 of file paragraphs.hpp.

◆ Buffer

AString& Buffer

A reference to the text buffer. Either refers to otherwise protected field text or to what was given in alternative construction.

Definition at line 47 of file paragraphs.hpp.

◆ DetectedMaxLineWidth

integer DetectedMaxLineWidth =0

This field is increased whenever a line of text added is longer than its current value. Might be used by to detect the maximum line width when field LineWidth is set to 0 and hence no auto wrap is done.

Definition at line 101 of file paragraphs.hpp.

◆ Formatter

The formatter to use. In the constructor, this shared pointer is initialized with the

  • ALib Default Formatter, in the case that this object's template character type equals alib::character, or
  • A shared pointer to a newly created formatter object of a corresponding character type otherwise.

Definition at line 55 of file paragraphs.hpp.

◆ IndentFirstLine

AStringMA IndentFirstLine

Used as parameter indent of static method invocations.
The indent string of the first line.

This field can either be manipulated by direct access or preferably with overloaded methods PushIndent and PopIndent.

Definition at line 80 of file paragraphs.hpp.

◆ IndentOtherLines

AStringMA IndentOtherLines

Used as parameter indent of static method invocations.
The indent string of text lines, excluding the first line.

This field can either be manipulated by direct access or preferably with overloaded methods PushIndent and PopIndent.

Definition at line 87 of file paragraphs.hpp.

◆ IndentSizesFirstLine

std::stack<integer, StdDequeMono<integer> > IndentSizesFirstLine

The stack of indent substring sizes in string IndentFirstLine. Used with PushIndent and PopIndent.

Definition at line 91 of file paragraphs.hpp.

◆ IndentSizesOtherLines

std::stack<integer, StdDequeMono<integer> > IndentSizesOtherLines

The stack of indent substring sizes in string IndentOtherLines. Used with PushIndent and PopIndent.

Definition at line 95 of file paragraphs.hpp.

◆ JustifyChar

character JustifyChar = '\0'

Used as parameter justifyChar of static method invocations. Usually set to ' ' to enable paragraph width justification.
Defaults to '\0' which disables it.

Definition at line 63 of file paragraphs.hpp.

◆ LineWidth

integer LineWidth = 0

Used as parameter lineWidth of static method invocations.

Definition at line 58 of file paragraphs.hpp.

◆ markedBuffer

AString markedBuffer
protected

Buffer for processing marked text.

Definition at line 109 of file paragraphs.hpp.

◆ markerBulletLevel

size_t markerBulletLevel =0
protected

Buffer for processing marked text.

Definition at line 112 of file paragraphs.hpp.

◆ MarkerBullets

StdVectorMono<character> MarkerBullets

The bullet used with increasing bullet depths. Defaults to '*', '-', '*', '-', '*', '-'.

Definition at line 73 of file paragraphs.hpp.

◆ MarkerChar

character MarkerChar = '@'

Used to detect special commands given with format strings.

See also
Method AddMarked for more information.

Defaults to '@'.

Definition at line 69 of file paragraphs.hpp.

◆ text

AString text
protected

Internal buffer, used for field Paragraphs, if no external string object was given.

Definition at line 42 of file paragraphs.hpp.

Constructor(s) / Destructor Details:

◆ Paragraphs() [1/2]

Parameterless constructor. Internal buffer text will be used with reference Buffer. For field Formatter, Formatter::Default will be used.

Definition at line 24 of file paragraphs.cpp.

Here is the call graph for this function:

◆ Paragraphs() [2/2]

Paragraphs ( AString & externalBuffer)

Alternative constructor that accepts an external buffer to use.

Parameters
externalBufferThe external buffer to use and fill.

Definition at line 41 of file paragraphs.cpp.

Here is the call graph for this function:

Method Details:

◆ Add() [1/2]

template<typename TAllocatorArgs >
void Add ( boxing::TBoxes< TAllocatorArgs > & args)

Appends the given objects args to the internal Buffer with the help of member Formatter. Then, static method Format is invoked, providing our public members as parameters. Finally, a newline sequence is added to Buffer, but only if the buffer is not empty and if it does not already end with a newline sequence.

Exceptions
<b>alib::lang::format::FMTExceptions</b><br>Rethrows exceptions from the formatter caused by errors in provided args.
Parameters
argsThe list of arguments to add.

◆ Add() [2/2]

template<typename... BoxedObjects>
Paragraphs & Add ( const BoxedObjects &... args)
inline

Variadic template argument version of Add.

Parameters
argsThe variadic list of arguments to add.
Returns
A reference to ourselves to allow concatenated calls.

Definition at line 194 of file paragraphs.hpp.

Here is the call graph for this function:

◆ AddMarked() [1/2]

template<typename TAllocatorArgs >
void AddMarked ( boxing::TBoxes< TAllocatorArgs > & args)

This method implements a pre-processing of the text before Add paragraphs found in the text.

The pre-processing is quite simple. Its purpose is to allow longer strings (e.g., loaded from a resource pool) with multiple paragraphs to be formatted by embedded escape sequences to include indents and nested bullet schemes.

The escape sequences begin with the character stored in field MarkerChar, which defaults to '@'. The following table documents the sequences:

Sequence Description
@@ Inserts the marker character itself.
@>> Indent text by two spaces
@<< Un-indent text by two spaces
@*> Increases bullet level.
@<* Decreases bullet level
@P Inserts a new line (like '
') but without ending the current and starting a new bullet point.
@HLc Inserts a horizontal line of width LineWidth using c as fill character.

The nested bullet point characters are received from vector MarkerBullets.

Exceptions
<b>alib::lang::format::FMTExceptions</b>
Parameters
argsThe list of arguments to add.

◆ AddMarked() [2/2]

template<typename... BoxedObjects>
Paragraphs & AddMarked ( const BoxedObjects &... args)
inline

Variadic template argument version of AddMarked.

Exceptions
<b>alib::lang::format::FMTExceptions</b>
Parameters
argsThe variadic list of arguments to add.
Returns
A reference to ourselves to allow concatenated calls.

Definition at line 246 of file paragraphs.hpp.

Here is the call graph for this function:

◆ Clear()

Paragraphs & Clear ( )

Clears field Buffer.

Returns
A reference to ourselves to allow concatenated calls.

Definition at line 96 of file paragraphs.cpp.

Here is the call graph for this function:

◆ Format()

void Format ( AString & text,
integer startIdx,
integer lineWidth,
character justifyChar,
integer & maxLineWidth,
const String & indentFirstLine = nullptr,
const String & indentOtherLines = nullptr )
static

Formats one or more paragraphs (separated by NewLine symbols) with three optional features:

  • Wrapping of lines longer than lineWidth (word wrap)
  • Justify the text, which here means "full justification", i.e., format the text to have lines of the exact same width.
  • Adding an indentation to each line with an optionally different indentation for the first line after a NewLine symbol and subsequent ones.

The paragraph starts at startIdx and all of the rest of the string is treated as one paragraph. New-line character sequences found within the paragraph are considered manual line ends. Hence, no block formatting for lines ending with a new line character is performed.

The method is static and hence can be used with arbitrary buffers. Non-static methods Add invoke this method after adding the given content to the internal buffer. Furthermore, convenience functions and corresponding member variables, simplify the use of this method, when indirectly used through an instance of the class.

Parameters
textThe text containing the paragraph to format.
startIdxThe start of the paragraph.
lineWidthThe width of the line. If 0 or negative, no line wrap is performed.
justifyCharIf this is unequal to '\0' it denotes the fill character used to justify the paragraph. Defaults to '\0', which disables justification.
[out]maxLineWidthProvides the maximum width of all text lines written.
indentFirstLineThe indent string of the first line. Defaults to nullptr.
indentOtherLinesThe indent string of subsequent lines. Defaults to nullptr.

Definition at line 289 of file paragraphs.cpp.

Here is the call graph for this function:

◆ PopIndent()

Paragraphs & PopIndent ( )

Removes the most recently added indent.

Returns
A reference to ourselves to allow concatenated calls.

Definition at line 83 of file paragraphs.cpp.

Here is the call graph for this function:

◆ PushIndent() [1/2]

Paragraphs & PushIndent ( const String & indentFirstLine,
const String & indentOtherLines = nullptr )

Add the given strings to members IndentFirstLine and IndentOtherLines.

Parameters
indentFirstLineThe string to add to the current indentation stored in IndentFirstLine.
indentOtherLinesThe string to add to the current indentation stored in IndentOtherLines.
Defaults to NULL_STRING, which sets it to the same value as indentFirstLine.
Returns
A reference to ourselves to allow concatenated calls.

Definition at line 59 of file paragraphs.cpp.

Here is the call graph for this function:

◆ PushIndent() [2/2]

Paragraphs & PushIndent ( uinteger qty,
character fillChar = ' ' )

Add a given number of characters (default is spaces) to the indentation strings IndentFirstLine and IndentOtherLines.

Use PopIndent to remove the indent.

Parameters
qtyThe quantity of characters to add or remove
fillCharThe character (used only if qty is positive).
Returns
A reference to ourselves to allow concatenated calls.

Definition at line 73 of file paragraphs.cpp.

Here is the call graph for this function:

◆ RemoveLastNewLine()

AString & RemoveLastNewLine ( )
inline

Removes the last new line character at the end of the Buffer.

Returns
A reference to the text object.

Definition at line 259 of file paragraphs.hpp.

Here is the call graph for this function:

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