ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
FmtCore Class Reference

In C++20, the std::format library is introduced. However, it is not supported under restriction of ABACUS development that not later than C++11. Plus in ABACUS the formatting-output demands is not quite general but more specific, therefore, a simple alternative is proposed here. To use: More...

#include <formatter.h>

Collaboration diagram for FmtCore:

Public Member Functions

 FmtCore (const std::string &fmt)
 
 ~FmtCore ()
 
template<typename... Ts>
std::string format (const Ts &... args)
 std::string overload of the varadic template function
 
void reset (const std::string &fmt="")
 reset the format string (std::string overloads)
 
const std::string & fmt ()
 get the format string
 

Static Public Member Functions

template<typename... Ts>
static std::string format (const char *fmt, const Ts &... args)
 static function to format data
 
static std::vector< std::string > split (const std::string &in, const std::string &delim)
 split a string with a delimiter, return uncollapse vector
 
static std::vector< std::string > split (const std::string &in)
 split a string with a delimiter, return only non-empty elements
 
static bool startswith (const std::string &in, const std::string &prefix)
 
static bool endswith (const std::string &in, const std::string &suffix)
 
static std::string strip (const std::string &in, const std::string &chars=" ")
 
static std::string center (const std::string &in, const size_t &width, const char &fillchar=' ')
 
static std::string replace (const std::string &in, const std::string &old, const std::string &new_)
 
static std::string join (const std::string &delim, const std::vector< std::string > &src)
 
static std::string upper (const std::string &in)
 
static std::string lower (const std::string &in)
 

Static Private Member Functions

template<typename T >
static std::enable_if< std::is_same< T, std::string >::value, constchar * >::type filter (const T &s)
 
template<typename T >
static std::enable_if<!std::is_same< T, std::string >::value, constT & >::type filter (const T &s)
 

Private Attributes

std::string fmt_
 

Detailed Description

In C++20, the std::format library is introduced. However, it is not supported under restriction of ABACUS development that not later than C++11. Plus in ABACUS the formatting-output demands is not quite general but more specific, therefore, a simple alternative is proposed here. To use:

  1. Use the static function format() to format data like FmtCore::format("%d", 1);
  2. Use the class FmtCore to format data like FmtCore fmt("%d"); fmt.format(1);. The first way is more flexible while the second way is more efficient. The format string can be reset by reset() function. If empty, the format string is empty, otherwise it will be updated.

Constructor & Destructor Documentation

◆ FmtCore()

FmtCore::FmtCore ( const std::string &  fmt)
inline

◆ ~FmtCore()

FmtCore::~FmtCore ( )
inline

Member Function Documentation

◆ center()

static std::string FmtCore::center ( const std::string &  in,
const size_t &  width,
const char &  fillchar = ' ' 
)
inlinestatic
Here is the caller graph for this function:

◆ endswith()

static bool FmtCore::endswith ( const std::string &  in,
const std::string &  suffix 
)
inlinestatic
Here is the caller graph for this function:

◆ filter() [1/2]

template<typename T >
static std::enable_if< std::is_same< T, std::string >::value, constchar * >::type FmtCore::filter ( const T s)
inlinestaticprivate
Here is the caller graph for this function:

◆ filter() [2/2]

template<typename T >
static std::enable_if<!std::is_same< T, std::string >::value, constT & >::type FmtCore::filter ( const T s)
inlinestaticprivate

◆ fmt()

const std::string & FmtCore::fmt ( )
inline

get the format string

Returns
std::string
Here is the caller graph for this function:

◆ format() [1/2]

template<typename... Ts>
static std::string FmtCore::format ( const char *  fmt,
const Ts &...  args 
)
inlinestatic

static function to format data

Template Parameters
Tsdatatype of the data
Parameters
fmtformat string
argsdata to format
Returns
std::string
Here is the call graph for this function:
Here is the caller graph for this function:

◆ format() [2/2]

template<typename... Ts>
std::string FmtCore::format ( const Ts &...  args)
inline

std::string overload of the varadic template function

Parameters
fmt
arg
Returns
std::string
Here is the call graph for this function:

◆ join()

static std::string FmtCore::join ( const std::string &  delim,
const std::vector< std::string > &  src 
)
inlinestatic
Here is the caller graph for this function:

◆ lower()

static std::string FmtCore::lower ( const std::string &  in)
inlinestatic
Here is the caller graph for this function:

◆ replace()

static std::string FmtCore::replace ( const std::string &  in,
const std::string &  old,
const std::string &  new_ 
)
inlinestatic
Here is the caller graph for this function:

◆ reset()

void FmtCore::reset ( const std::string &  fmt = "")
inline

reset the format string (std::string overloads)

Parameters
fmt
Here is the call graph for this function:
Here is the caller graph for this function:

◆ split() [1/2]

static std::vector< std::string > FmtCore::split ( const std::string &  in)
inlinestatic

split a string with a delimiter, return only non-empty elements

Parameters
instring to split
Returns
std::vector<std::string>

◆ split() [2/2]

static std::vector< std::string > FmtCore::split ( const std::string &  in,
const std::string &  delim 
)
inlinestatic

split a string with a delimiter, return uncollapse vector

Python-style string functions will be implemented here as toolbox

Parameters
instring to split
delimdelimiter
Returns
std::vector<std::string>
Here is the caller graph for this function:

◆ startswith()

static bool FmtCore::startswith ( const std::string &  in,
const std::string &  prefix 
)
inlinestatic
Here is the caller graph for this function:

◆ strip()

static std::string FmtCore::strip ( const std::string &  in,
const std::string &  chars = " " 
)
inlinestatic
Here is the caller graph for this function:

◆ upper()

static std::string FmtCore::upper ( const std::string &  in)
inlinestatic

Member Data Documentation

◆ fmt_

std::string FmtCore::fmt_
private

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