CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
Format Class Referencefinal

Generate formatted text. More...

#include <cc/Format>

Inheritance diagram for Format:

Public Member Functions

 Format (const String &pattern, const Stream &stream=Stream{})
 Create a new formatted output text.
 
 Format (const Stream &stream=Stream{})
 Create a new formatted output text.
 
 ~Format ()
 Cleanup: flush the output text.
 
Formatoperator<< (const String &s)
 Add string s to the output text.
 
Formatoperator<< (const Bytes &s)
 Add string s to the output text.
 
Formatoperator<< (const List< String > &l)
 Merge and add string list l to the output text.
 
template<class T >
Formatoperator<< (const T &x)
 Add x to the output text.
 
Formatoperator<< (const NewLine &)
 Append newline.
 
Formatoperator<< (const Flush &)
 Flush output.
 
template<class T >
Formatarg (const T &x)
 Add x to the output text.
 
- Public Member Functions inherited from List< Bytes >
iterator begin ()
 Return iterator pointing to the first item (if any)
 
const_iterator begin () const
 Return readonly iterator pointing to the first item (if any)
 
iterator end ()
 Return iterator pointing behind the last item
 
const_iterator end () const
 Return readonly iterator pointing behind the last item
 
const_iterator cbegin () const
 Return readonly iterator pointing to the first item (if any)
 
const_iterator cend () const
 Return readonly iterator pointing behind the last item
 
reverse_iterator rbegin ()
 Return reverse iterator pointing to the last item (if any)
 
const_reverse_iterator rbegin () const
 Return readonly reverse iterator pointing to the last item (if any)
 
reverse_iterator rend ()
 Return reverse iterator pointing before the first item
 
const_reverse_iterator rend () const
 Return reverse iterator pointing before the first item
 
const_reverse_iterator crbegin () const
 Return readonly reverse iterator pointing to the last item (if any)
 
const_reverse_iterator crend () const
 Return reverse iterator pointing before the first item
 
const Tree & tree () const
 
 List ()=default
 Construct an empty list.
 
 List (const List &other)=default
 Construct a copy of other.
 
 List (std::initializer_list< Item > items)
 Construct with initial items.
 
 List (std::initializer_list< List > lists)
 Initialize by joining initial lists.
 
 List (List &&other)
 Take over the right-side list other.
 
Listoperator= (const List &other)=default
 Assign list other.
 
Listoperator= (List &&other)
 Assign right-side list other.
 
Locator head () const
 Get a locator pointing to the first item.
 
Locator tail () const
 Get a locator pointing to the last item.
 
Locator from (long index) const
 Get a locator pointing to the item at index.
 
long count () const
 Get the number of items stored in the list.
 
long size () const
 Get the number of items stored in the list.
 
bool has (long i) const
 Check if i is a valid index.
 
 operator bool () const
 Check if this list is non-empty.
 
long operator+ () const
 Get the number of items stored in the list.
 
const Itemat (Locator pos) const
 Get constant reference to the item at position pos.
 
const Itemat (long index) const
 Get constant reference to the item at index.
 
ItemmutableAt (Locator pos)
 Get reference to the item at position pos.
 
ItemmutableAt (long index)
 Get reference to the item at index.
 
const Itemoperator[] (long index) const
 Get constant reference to the item at index.
 
Itemoperator[] (long index)
 Get reference to the item at index.
 
Item operator() (long index) const
 Get value at index if 0 <= index && index < count(), otherwise return fallback.
 
Listoperator() (long index, const Bytes &value)
 Set value at index if 0 <= i && i < count(), otherwise do nothing.
 
const Itemfirst () const
 Get constant reference to first item.
 
const Itemlast () const
 Get constant reference to last item.
 
bool firstIs (const Item &item) const
 Tell if item is the first item.
 
bool lastIs (const Item &item) const
 Tell if item is the last item.
 
ItemtouchFirst ()
 Get reference to first item.
 
ItemtouchLast ()
 Get reference to last item.
 
void append (const Item &item)
 Insert item at the end of the list.
 
void prepend (const Item &item)
 Insert item at the beginning of the list.
 
void appendList (const List< Item > &other)
 Append a copy of list other.
 
void prependList (const List< Item > &other)
 Prepend a copy of list other.
 
void pushBack (const Item &item)
 Insert item as a new last item.
 
void pushFront (const Item &item)
 Insert item as a new first item.
 
void popBack ()
 Remove the last item.
 
void popFront ()
 Remove the first item.
 
void emplaceBack (Args... args)
 Insert a new last item.
 
void emplaceFront (Args... args)
 Emplace a new first item.
 
Listoperator<< (const Item &item)
 Append item.
 
Listoperator>> (Item &item)
 Remove and return the first item.
 
void insertAt (Locator &pos, const Item &item)
 Insert item at position pos.
 
void insertAt (long index, const Item &item)
 Insert item at index.
 
void removeAt (Locator &pos)
 Remove item at position pos (and advance pos to the next item)
 
void removeAt (long index)
 Remove item at index.
 
void emplaceAt (Locator &pos, Args... args)
 Create a new item at position pos (initialized with args)
 
void emplaceAt (long index, Args... args)
 Create a new item at index (initialized with args)
 
bool find (const Pattern &pattern, InOut< Locator > pos=None{}) const
 Find item b.
 
bool contains (const Pattern &pattern) const
 Convenience method.
 
void replace (const Pattern &pattern, const Item &substitute)
 Replace all occurences of pattern by substitute.
 
void sort ()
 Sort the list in-situ.
 
void sortUnique ()
 Sorts the list and removes all doubles.
 
List sorted () const
 Return a sorted copy of this list
 
List sortedUnique () const
 Return a sorted copy of this list which does not contain repeated items
 
void reverse ()
 Reverse the order of items in the list
 
List reversed () const
 Return a copy of the list in which the order of items is reversed
 
void forEach (F f) const
 Call function f for each item
 
void forEach (F f)
 Call function f for each item
 
void deplete ()
 Remove all items.
 
join (S sep) const
 Merge into a single item interspersed by sep.
 
join () const
 Merge into a single item.
 
bool operator== (const Other &other) const
 Equality operator.
 
std::strong_ordering operator<=> (const Other &other) const
 Ordering operator.
 

Additional Inherited Members

- Public Types inherited from List< Bytes >
using Item
 Item type.
 
using value_type
 Item value type.
 
using size_type
 Type of the container capacity.
 
using iterator
 Value iterator.
 
using const_iterator
 Readonly value iterator.
 
using reverse_iterator
 Reverse value iterator.
 
using const_reverse_iterator
 Readonly reverse value iterator.
 
using Tree
 

Detailed Description

Generate formatted text.

See also
IoStream::stdOut(), IoStream::stdErr()

Constructor & Destructor Documentation

◆ Format() [1/2]

Format ( const String & pattern,
const Stream & stream = Stream{} )

Create a new formatted output text.

Parameters
patternOutput format with zero or more placeholders ("%%")
streamOutput stream to write the resulting text to (optional)

◆ Format() [2/2]

Format ( const Stream & stream = Stream{})

Create a new formatted output text.

Parameters
streamOutput stream to write the resulting text to (optional)

◆ ~Format()

~Format ( )

Cleanup: flush the output text.

Member Function Documentation

◆ operator<<() [1/6]

Format & operator<< ( const String & s)

Add string s to the output text.

◆ operator<<() [2/6]

Format & operator<< ( const Bytes & s)

Add string s to the output text.

◆ operator<<() [3/6]

Format & operator<< ( const List< String > & l)

Merge and add string list l to the output text.

◆ operator<<() [4/6]

template<class T >
Format & operator<< ( const T & x)

Add x to the output text.

Template Parameters
TType of x
Parameters
xVariable to be stringified

◆ operator<<() [5/6]

Format & operator<< ( const NewLine & )

Append newline.

◆ operator<<() [6/6]

Format & operator<< ( const Flush & )

Flush output.

◆ arg()

template<class T >
Format & arg ( const T & x)

Add x to the output text.

Template Parameters
TType of x
Parameters
xVariable to be stringified