Hermes
hermes::Str Class Reference

String class and set of string functions. More...

Classes

struct  regex
 

Public Member Functions

template<typename T >
bool friend operator== (const T &t, const Str &s)
 Character-wise comparison. More...
 
 Str ()
 Default constructor.
 
 Str (std::string s)
 Constructor from std::string More...
 
 Str (const char *s)
 Constructor from const char*'s contents copy. More...
 
 Str (const Str &other)
 Copy constructor. More...
 
 Str (Str &&other) noexcept
 Move constructor. More...
 
const std::string & str () const
 Get std::string object. More...
 
const char * c_str () const
 Get const char* pointer. More...
 
size_t size () const
 Get the number of characters on the string. More...
 
bool empty () const
 Checks if string is empty. More...
 
Result< ConstStrViewsubstr (size_t pos=0, i64 len=-1)
 Get a sub-string view from this object. More...
 
template<class... Args>
void append (const Args &... args)
 Append arguments to this Str. More...
 
template<class... Args>
void appendLine (const Args &... args)
 Append arguments to this Str followed by a breakline. More...
 
Stroperator= (const Str &s)=default
 
template<typename T >
Stroperator= (const T &t)
 String of value assignment. More...
 
Stroperator+= (const Str &other)
 Simple concatenation with other More...
 
template<typename T >
Stroperator+= (const T &t)
 Simple concatenation with string of value. More...
 
template<typename T >
Str operator+ (const T &t) const
 Generates a copy appended by t More...
 
Str operator<< (const char *s) const
 Generates a copy appended by s More...
 
bool operator== (const char *ss) const
 Performs const char* comparison. More...
 
template<typename T >
bool operator== (const T &t) const
 Performs character comparison with string value of t More...
 

Static Public Member Functions

static bool isPrefix (const std::string &p, const std::string &s)
 Checks if s has prefix p. More...
 
static std::string abbreviate (const std::string &s, size_t width, const char fmt[4]="s.s")
 Abbreviates a string to fit in a string of width characters. More...
 
template<typename T >
static std::string rjust (const T &value, size_t width, char fill_char=' ')
 Right justifies string value. More...
 
template<typename T >
static std::string ljust (const T &value, size_t width, char fill_char=' ')
 Left justifies string value. More...
 
template<typename T >
static std::string cjust (const T &value, size_t width, char fill_char=' ')
 Center justifies string value. More...
 
template<typename... Ts>
static std::string format (const std::string &fmt, Ts &&... args)
 
template<typename T >
static std::string toHex (T i, bool leading_zeros=false, bool zero_x=false)
 Generates hexadecimal representation from number. More...
 
static std::string strip (const std::string &s, const std::string &patterns=" \t\n")
 
template<class... Args>
static std::string concat (const Args &... args)
 Concatenates multiple elements_ into a single string. More...
 
static std::string join (const std::vector< std::string > &v, const std::string &separator="")
 Concatenate strings together separated by a separator. More...
 
template<typename T >
static std::string join (const std::vector< T > &v, const std::string &separator="")
 Concatenate elements together separates by a separator. More...
 
static std::vector< std::string > split (const std::string &s, const std::string &delimiters=" ")
 Splits a string into tokens separated by delimiters. More...
 
static std::string printBits (u32 n)
 Print bits in big-endian order. More...
 
template<typename T >
static std::string binaryToHex (T input_n, bool uppercase=true, bool strip_leading_zeros=false)
 Get ascii representation of raw bit data of input_n More...
 
static std::string addressOf (uintptr_t ptr, u32 digit_count=8)
 Generates hexadecimal representation of memory address. More...
 
static std::string byteToBinary (byte b)
 Binary representation of byte. More...
 
static bool isInteger (const std::string &s)
 Checks if string represents an integer. More...
 
static bool isNumber (const std::string &s)
 Checks if string represents a number. More...
 

Friends

Str operator<< (const char *s, const Str &str)
 Concatenate. More...
 
Str operator+ (const std::string &s, const Str &str)
 Concatenate. More...
 
bool operator== (const char *ss, const Str &s)
 const char* pointer comparison More...
 

Detailed Description

String class and set of string functions.

Constructor & Destructor Documentation

◆ Str() [1/4]

hermes::Str::Str ( std::string  s)

Constructor from std::string

Parameters
s

◆ Str() [2/4]

hermes::Str::Str ( const char *  s)

Constructor from const char*'s contents copy.

Parameters
s

◆ Str() [3/4]

hermes::Str::Str ( const Str other)
default

Copy constructor.

Parameters
other

◆ Str() [4/4]

hermes::Str::Str ( Str &&  other)
noexcept

Move constructor.

Parameters
other

Member Function Documentation

◆ abbreviate()

std::string hermes::Str::abbreviate ( const std::string &  s,
size_t  width,
const char  fmt[4] = "s.s" 
)
static

Abbreviates a string to fit in a string of width characters.

Note
If width >= string size, no abbreviation occurs.
Parameters
sinput string
widthfinal character count
fmta three-character string describing the abbreviation type: ("..s", "s.s", ".s.", or "..s"). where 's' represents the input string contents and '.' the abbreviated portion of s.
Returns
abbreviated string

◆ addressOf()

static std::string hermes::Str::addressOf ( uintptr_t  ptr,
u32  digit_count = 8 
)
inlinestatic

Generates hexadecimal representation of memory address.

Parameters
ptr
digit_count
Returns

◆ append()

template<class... Args>
void hermes::Str::append ( const Args &...  args)
inline

Append arguments to this Str.

Note
Arguments must support << operator from std::ostringstream
Template Parameters
Args
Parameters
args

◆ appendLine()

template<class... Args>
void hermes::Str::appendLine ( const Args &...  args)
inline

Append arguments to this Str followed by a breakline.

Note
Arguments must support << operator from std::ostringstream
Template Parameters
Args
Parameters
args

◆ binaryToHex()

template<typename T >
static std::string hermes::Str::binaryToHex ( input_n,
bool  uppercase = true,
bool  strip_leading_zeros = false 
)
inlinestatic

Get ascii representation of raw bit data of input_n

Template Parameters
T
Parameters
input_n
uppercase
strip_leading_zeros
Returns

◆ byteToBinary()

static std::string hermes::Str::byteToBinary ( byte  b)
inlinestatic

Binary representation of byte.

Parameters
b
Returns

◆ c_str()

const char* hermes::Str::c_str ( ) const
inline

Get const char* pointer.

Returns

◆ cjust()

template<typename T >
static std::string hermes::Str::cjust ( const T &  value,
size_t  width,
char  fill_char = ' ' 
)
inlinestatic

Center justifies string value.

Template Parameters
Tstring-convertible type
Parameters
value
widthoutput size
fill_char
Returns

◆ concat()

template<class... Args>
static std::string hermes::Str::concat ( const Args &...  args)
inlinestatic

Concatenates multiple elements_ into a single string.

Template Parameters
Args
Parameters
args
Returns
a single string of the resulting concatenation

◆ empty()

bool hermes::Str::empty ( ) const
inline

Checks if string is empty.

Returns
true if string size is zero.

◆ format()

template<typename... Ts>
static std::string hermes::Str::format ( const std::string &  fmt,
Ts &&...  args 
)
inlinestatic
Template Parameters
Ts
Parameters
fmt
args
Returns

◆ isInteger()

bool hermes::Str::isInteger ( const std::string &  s)
static

Checks if string represents an integer.

Note
Checks the pattern [+|-]?[1-9]+
Parameters
s
Returns

◆ isNumber()

bool hermes::Str::isNumber ( const std::string &  s)
static

Checks if string represents a number.

Note
Checks the pattern [+|-]?([1-9]+ or .[0-9]+f? or e[1-9]+)
Parameters
s
Returns

◆ isPrefix()

bool hermes::Str::isPrefix ( const std::string &  p,
const std::string &  s 
)
static

Checks if s has prefix p.

Parameters
pprefix string
sstring
Returns
true if p is prefix of s

◆ join() [1/2]

std::string hermes::Str::join ( const std::vector< std::string > &  v,
const std::string &  separator = "" 
)
static

Concatenate strings together separated by a separator.

Parameters
varray of strings
separator[in | ""]
Returns
final string

◆ join() [2/2]

template<typename T >
static std::string hermes::Str::join ( const std::vector< T > &  v,
const std::string &  separator = "" 
)
inlinestatic

Concatenate elements together separates by a separator.

Note
Element type must be able to perform << operator with std::stringstream
Template Parameters
Telement type
Parameters
v
separator
Returns

◆ ljust()

template<typename T >
static std::string hermes::Str::ljust ( const T &  value,
size_t  width,
char  fill_char = ' ' 
)
inlinestatic

Left justifies string value.

Template Parameters
Tstring-convertible type
Parameters
value
widthoutput size
fill_char
Returns

◆ operator+()

template<typename T >
Str hermes::Str::operator+ ( const T &  t) const
inline

Generates a copy appended by t

Note
Argument must support << operator from std::stringstream
Template Parameters
T
Parameters
t
Returns

◆ operator+=() [1/2]

Str& hermes::Str::operator+= ( const Str other)
inline

Simple concatenation with other

Parameters
other
Returns

◆ operator+=() [2/2]

template<typename T >
Str& hermes::Str::operator+= ( const T &  t)
inline

Simple concatenation with string of value.

Note
Argument must support << operator from std::stringstream
Template Parameters
T
Parameters
t
Returns

◆ operator<<()

Str hermes::Str::operator<< ( const char *  s) const
inline

Generates a copy appended by s

Parameters
s
Returns

◆ operator=() [1/2]

Str& hermes::Str::operator= ( const Str s)
default

Copy assignment

Parameters
s
Returns

◆ operator=() [2/2]

template<typename T >
Str& hermes::Str::operator= ( const T &  t)
inline

String of value assignment.

Note
Argument must support << operator from std::stringstream
Template Parameters
T
Parameters
t
Returns

◆ operator==() [1/3]

bool hermes::Str::operator== ( const char *  ss) const
inline

Performs const char* comparison.

Parameters
ss
Returns

◆ operator==() [2/3]

template<typename T >
bool hermes::Str::operator== ( const T &  t) const
inline

Performs character comparison with string value of t

Note
Argument must support << operator from std::stringstream

◆ operator==() [3/3]

template<typename T >
bool friend hermes::Str::operator== ( const T &  t,
const Str s 
)
inline

Character-wise comparison.

Template Parameters
T
Parameters
t
s
Returns

◆ printBits()

static std::string hermes::Str::printBits ( u32  n)
inlinestatic

Print bits in big-endian order.

Parameters
n
Returns

◆ rjust()

template<typename T >
static std::string hermes::Str::rjust ( const T &  value,
size_t  width,
char  fill_char = ' ' 
)
inlinestatic

Right justifies string value.

Template Parameters
Tstring-convertible type
Parameters
value
widthoutput size
fill_char
Returns

◆ size()

size_t hermes::Str::size ( ) const
inline

Get the number of characters on the string.

Returns
number of characters on the string.

◆ split()

std::vector< std::string > hermes::Str::split ( const std::string &  s,
const std::string &  delimiters = " " 
)
static

Splits a string into tokens separated by delimiters.

Parameters
s[in] input string
delimiters[in | default = " "] delimiters
Returns
a vector of substrings

◆ str()

const std::string& hermes::Str::str ( ) const
inline

Get std::string object.

Returns

◆ strip()

std::string hermes::Str::strip ( const std::string &  s,
const std::string &  patterns = " \t\n" 
)
static
Parameters
s
patterns
Returns

◆ substr()

Result< ConstStrView > hermes::Str::substr ( size_t  pos = 0,
i64  len = -1 
)

Get a sub-string view from this object.

Parameters
posposition of the first character of the sub-string in str.
lennumber of characters of the sub-string. If len = -1, then the size is str.size() - pos.
Returns
const view reference of the sub-string

◆ toHex()

template<typename T >
static std::string hermes::Str::toHex ( i,
bool  leading_zeros = false,
bool  zero_x = false 
)
inlinestatic

Generates hexadecimal representation from number.

Note
Calls std::hex on i
Template Parameters
T
Parameters
inumber
leading_zerosputs leading zeros up to the size of T
zero_xputs the "0x" suffix
Returns

Friends And Related Function Documentation

◆ operator+

Str operator+ ( const std::string &  s,
const Str str 
)
friend

Concatenate.

Parameters
s
str
Returns

◆ operator<<

Str operator<< ( const char *  s,
const Str str 
)
friend

Concatenate.

Parameters
s
str
Returns

◆ operator==

bool operator== ( const char *  ss,
const Str s 
)
friend

const char* pointer comparison

Parameters
ss
s
Returns

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