fiber
Loading...
Searching...
No Matches
fiber::FormatStr Struct Reference

Formats a string and allows to pass an additional size parameter. More...

#include <OStream.hpp>

Inheritance diagram for fiber::FormatStr:
fiber::FormatStrParams

Public Member Functions

constexpr FormatStr ()=default
 Default format constructor.
 
constexpr FormatStr (const char *str, size_t len)
 Construcs a string formater.
 
constexpr FormatStr (const char *str)
 Constructs a string from a terminated c-style string. I urge you to use FormatStr(const char* str, size_t len) instead.
 
constexpr FormatStr (const char *first, const char *last)
 Constructs a string from a range given by the closed-open iterators [first, last)
 
template<CStringView StringView>
constexpr FormatStr (const StringView &str)
 
constexpr FormatStroperator() (const char *str)
 Assigns a string to the object. Allows to re-use formats.
 
constexpr FormatStroperator() (const char *str, size_t len)
 Assigns a string to the object. Allows to re-use formats.
 
constexpr FormatStroperator() (const char *first, const char *last)
 Assigns a string to the object. Allows to re-use formats.
 
template<CStringView StringView>
constexpr FormatStroperator() (const StringView &str)
 Assigns a string to the object. Allows to re-use formats.
 
constexpr FormatStrmwidth (int mw)
 Sets the minimum number of character that will be put into the stream.
 
constexpr FormatStrleft ()
 Formats the string to the left area set by mwidth().
 
constexpr FormatStrright ()
 Formats the string to the left area set by mwidth().
 
constexpr FormatStrcenter ()
 Formats the string to the left area set by mwidth().
 
constexpr FormatStrfill (char c)
 Sets the fill characters used by padding that is applied when mwidth() is used.
 

Static Public Member Functions

static constexpr FormatStr like (const char *str, size_t len, const FormatStrParams &params)
 
static constexpr FormatStr like (const char *str, const FormatStrParams &params)
 
static constexpr FormatStr like (const char *first, const char *last, const FormatStrParams &params)
 
template<CStringView StringView>
static constexpr FormatStr like (const StringView &str, const FormatStrParams &params)
 

Public Attributes

const char * _str = ""
 
size_t _len = 0
 
- Public Attributes inherited from fiber::FormatStrParams
AlignmentLRC _alignment = AlignmentLRC::Right
 
int _mwidth = 0
 
char _fill = ' '
 

Detailed Description

Formats a string and allows to pass an additional size parameter.

Constructor & Destructor Documentation

◆ FormatStr() [1/5]

fiber::FormatStr::FormatStr ( )
constexprdefault

Default format constructor.

◆ FormatStr() [2/5]

fiber::FormatStr::FormatStr ( const char * str,
size_t len )
inlineconstexpr

Construcs a string formater.

Parameters
strPointer to the start of the string
lenThe length of the string, aka. the number of character that should be printed

◆ FormatStr() [3/5]

fiber::FormatStr::FormatStr ( const char * str)
inlineconstexpr

Constructs a string from a terminated c-style string. I urge you to use FormatStr(const char* str, size_t len) instead.

◆ FormatStr() [4/5]

fiber::FormatStr::FormatStr ( const char * first,
const char * last )
inlineconstexpr

Constructs a string from a range given by the closed-open iterators [first, last)

Parameters
firstThe start of the string that should be printed. Points to the first character.
lastThe end of the string that should be printed. Points past the last character.

◆ FormatStr() [5/5]

template<CStringView StringView>
fiber::FormatStr::FormatStr ( const StringView & str)
inlineconstexpr

Member Function Documentation

◆ center()

FormatStr & fiber::FormatStr::center ( )
inlineconstexpr

Formats the string to the left area set by mwidth().

Example:

stream << "[" << FormatStr("OK").mwidth(6).center() << "]" << endl; // Outputs: [ OK ]
void endl(OStream &stream)
Writes a new line character to the stream followed by a call to OStream::flush()
Definition OStream.hpp:198
constexpr FormatStr()=default
Default format constructor.
Returns
self

◆ fill()

FormatStr & fiber::FormatStr::fill ( char c)
inlineconstexpr

Sets the fill characters used by padding that is applied when mwidth() is used.

Parameters
cThe new fill character
Returns
self

◆ left()

FormatStr & fiber::FormatStr::left ( )
inlineconstexpr

Formats the string to the left area set by mwidth().

Example:

stream << "[" << FormatStr("OK").mwidth(6).left() << "]" << endl; // Outputs: [OK ]
Returns
self

◆ like() [1/4]

static constexpr FormatStr fiber::FormatStr::like ( const char * first,
const char * last,
const FormatStrParams & params )
inlinestaticconstexpr

◆ like() [2/4]

static constexpr FormatStr fiber::FormatStr::like ( const char * str,
const FormatStrParams & params )
inlinestaticconstexpr

◆ like() [3/4]

static constexpr FormatStr fiber::FormatStr::like ( const char * str,
size_t len,
const FormatStrParams & params )
inlinestaticconstexpr

◆ like() [4/4]

template<CStringView StringView>
static constexpr FormatStr fiber::FormatStr::like ( const StringView & str,
const FormatStrParams & params )
inlinestaticconstexpr

◆ mwidth()

FormatStr & fiber::FormatStr::mwidth ( int mw)
inlineconstexpr

Sets the minimum number of character that will be put into the stream.

Padded characters are defined by FormatStr::fill(char c). The default fill character is a space ' '.

Example:

stream << "[" << FormatStr("OK").mwidth(6) << "]" << endl; // Outputs: [ OK]
Parameters
mwAn integer that sets the new minimal width
Returns
self

◆ operator()() [1/4]

FormatStr & fiber::FormatStr::operator() ( const char * first,
const char * last )
inlineconstexpr

Assigns a string to the object. Allows to re-use formats.

Like: FormatStr& operator()(const char* str)

Parameters
firstThe start of the string that should be printed. Points to the first character.
lastThe end of the string that should be printed. Points past the last character.
Returns
self

◆ operator()() [2/4]

FormatStr & fiber::FormatStr::operator() ( const char * str)
inlineconstexpr

Assigns a string to the object. Allows to re-use formats.

This function allows to create custom formaters and reuse them when printing - reusing code bloat and clutter.

Example:

FormatStr lformat = FormatStr().mwidth(64).fill('.').left();
FormatStr rformat = FormatStr().mwidth(8).fill('.');
stream << lformat("Chapter 1 The Beginning") << rformat("1") << endl;
stream << lformat("Chapter 2 The Action") << rformat("22") << endl;
stream << lformat("Chapter 3 The End") << rformat("333") << endl;

Output:

Chapter 1 The Beginning................................................1
Chapter 2 The Action..................................................22
Chapter 3 The End....................................................333
Parameters
strA terminated c-style string
Returns
self

◆ operator()() [3/4]

FormatStr & fiber::FormatStr::operator() ( const char * str,
size_t len )
inlineconstexpr

Assigns a string to the object. Allows to re-use formats.

Like: FormatStr& operator()(const char* str)

Parameters
strA terminated c-style string
lenthe length of the string
Returns
self

◆ operator()() [4/4]

template<CStringView StringView>
FormatStr & fiber::FormatStr::operator() ( const StringView & str)
inlineconstexpr

Assigns a string to the object. Allows to re-use formats.

Like: FormatStr& operator()(const char* str)

Parameters
stra string view like object. Has to offer the following two methods:
  • data(): that returns a pointer to the start of the stream
  • size(): that returns the size/length of the stream
Returns
self

◆ right()

FormatStr & fiber::FormatStr::right ( )
inlineconstexpr

Formats the string to the left area set by mwidth().

Example:

stream << "[" << FormatStr("OK").mwidth(6).right() << "]" << endl; // Outputs: [ OK]
Returns
self

Member Data Documentation

◆ _len

size_t fiber::FormatStr::_len = 0

◆ _str

const char* fiber::FormatStr::_str = ""

The documentation for this struct was generated from the following file: