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>
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: | |
AString & | Buffer |
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< character > | MarkerBullets |
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> | |
Paragraphs & | Add (const BoxedObjects &... args) |
template<typename TAllocatorArgs > | |
void | AddMarked (boxing::TBoxes< TAllocatorArgs > &args) |
template<typename... BoxedObjects> | |
Paragraphs & | AddMarked (const BoxedObjects &... args) |
ALIB_API Paragraphs & | Clear () |
ALIB_API Paragraphs & | PopIndent () |
ALIB_API Paragraphs & | PushIndent (const String &indentFirstLine, const String &indentOtherLines=nullptr) |
ALIB_API Paragraphs & | PushIndent (uinteger qty, character fillChar=' ') |
AString & | RemoveLastNewLine () |
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. | |
|
protected |
Allocator used for internal container types.
Definition at line 39 of file paragraphs.hpp.
|
protected |
Internally reused list of boxes.
Definition at line 106 of file paragraphs.hpp.
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.
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.
The formatter to use. In the constructor, this shared pointer is initialized with the
Definition at line 55 of file paragraphs.hpp.
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.
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.
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.
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.
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.
integer LineWidth = 0 |
Used as parameter lineWidth of static method invocations.
Definition at line 58 of file paragraphs.hpp.
|
protected |
Buffer for processing marked text.
Definition at line 109 of file paragraphs.hpp.
|
protected |
Buffer for processing marked text.
Definition at line 112 of file paragraphs.hpp.
StdVectorMono<character> MarkerBullets |
The bullet used with increasing bullet depths. Defaults to '*'
, '-'
, '*'
, '-'
, '*'
, '-'
.
Definition at line 73 of file paragraphs.hpp.
character MarkerChar = '@' |
Used to detect special commands given with format strings.
Defaults to '@'
.
Definition at line 69 of file paragraphs.hpp.
|
protected |
Internal buffer, used for field Paragraphs, if no external string object was given.
Definition at line 42 of file paragraphs.hpp.
Paragraphs | ( | ) |
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.
Paragraphs | ( | AString & | externalBuffer | ) |
Alternative constructor that accepts an external buffer to use.
externalBuffer | The external buffer to use and fill. |
Definition at line 41 of file paragraphs.cpp.
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.
<b>alib::lang::format::FMTExceptions</b><br> | Rethrows exceptions from the formatter caused by errors in provided args. |
args | The list of arguments to add. |
|
inline |
Variadic template argument version of Add.
args | The variadic list of arguments to add. |
Definition at line 194 of file paragraphs.hpp.
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.
<b>alib::lang::format::FMTExceptions</b> |
|
args | The list of arguments to add. |
|
inline |
Variadic template argument version of AddMarked.
args | The variadic list of arguments to add. |
Definition at line 246 of file paragraphs.hpp.
Paragraphs & Clear | ( | ) |
Clears field Buffer.
Definition at line 96 of file paragraphs.cpp.
|
static |
Formats one or more paragraphs (separated by NewLine symbols) with three optional features:
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.
text | The text containing the paragraph to format. | |
startIdx | The start of the paragraph. | |
lineWidth | The width of the line. If 0 or negative, no line wrap is performed. | |
justifyChar | If this is unequal to '\0' it denotes the fill character used to justify the paragraph. Defaults to '\0' , which disables justification. | |
[out] | maxLineWidth | Provides the maximum width of all text lines written. |
indentFirstLine | The indent string of the first line. Defaults to nullptr . | |
indentOtherLines | The indent string of subsequent lines. Defaults to nullptr . |
Definition at line 289 of file paragraphs.cpp.
Paragraphs & PopIndent | ( | ) |
Removes the most recently added indent.
Definition at line 83 of file paragraphs.cpp.
Paragraphs & PushIndent | ( | const String & | indentFirstLine, |
const String & | indentOtherLines = nullptr ) |
Add the given strings to members IndentFirstLine and IndentOtherLines.
indentFirstLine | The string to add to the current indentation stored in IndentFirstLine. |
indentOtherLines | The string to add to the current indentation stored in IndentOtherLines. Defaults to NULL_STRING, which sets it to the same value as indentFirstLine. |
Definition at line 59 of file paragraphs.cpp.
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.
qty | The quantity of characters to add or remove |
fillChar | The character (used only if qty is positive). |
Definition at line 73 of file paragraphs.cpp.
|
inline |
Removes the last new line character at the end of the Buffer.
Definition at line 259 of file paragraphs.hpp.