stmm-games-doc  0.32.0
Functions
stmg::Util Namespace Reference

Functions

template<typename ... T>
std::string stringCompose (const std::string &sFormat, const T &... oParam) noexcept
 Format a string. More...
 
std::string strStrip (const std::string &sStr) noexcept
 Strips a string of its leading and trailing space characters. More...
 
bool strContainsWhitespace (const std::string &sStr) noexcept
 Whether a string contains whitespace characters. More...
 
void strTextToLines (const std::string &sText, std::vector< std::string > &aLine) noexcept
 Adds lines contained in a string to a vector of strings. More...
 
int32_t strUTF8SizeInCodePoints (const std::string &sUtf8) noexcept
 UTF8 string size in code points rather than bytes. More...
 
std::string intToMillString (int32_t nValue) noexcept
 Formats integer with every 3 digits separator. More...
 
std::string millisecToMinSecString (int32_t nMilliseconds) noexcept
 Formats milliseconds to minutes and seconds. More...
 
std::string secToMinSecString (int32_t nSeconds) noexcept
 Formats seconds to minutes. More...
 
std::pair< bool, std::string > strToBool (const std::string &sStr)
 Convert a string to boolean. More...
 
template<class LT >
bool listContains (std::list< LT > &oList, const LT &oValue, typename std::list< LT >::iterator &it) noexcept
 
template<class LT >
bool listContains (const std::list< LT > &oList, const LT &oValue) noexcept
 
template<class LT >
bool listExtract (std::list< LT > &oList, const LT &oValue) noexcept
 
template<class ValueType >
bool vectorContains (const std::vector< ValueType > &oVector, const ValueType &oValue) noexcept
 
int32_t packPointToInt32 (NPoint oXY) noexcept
 Packs a point (64 bit) to an int32_t. More...
 
NPoint unpackPointFromInt32 (int32_t nXY) noexcept
 Unpacks a point (64 bit) from an int32_t. More...
 
int64_t packPointToInt64 (NPoint oXY) noexcept
 Packs a point to an int64_t. More...
 
NPoint unpackPointFromInt64 (int64_t nXY) noexcept
 Unpacks a point from an int64_t. More...
 
std::pair< int32_t, int32_t > unpackPairFromInt64 (int64_t nXY) noexcept
 Unpacks a XY pair from an int64_t. More...
 

Function Documentation

◆ intToMillString()

std::string stmg::Util::intToMillString ( int32_t  nValue)
noexcept

Formats integer with every 3 digits separator.

Ex. 12345678 is formatted as "12'345'678".

Parameters
nValueThe value.
Returns
The string.

◆ listContains() [1/2]

template<class LT >
bool stmg::Util::listContains ( std::list< LT > &  oList,
const LT &  oValue,
typename std::list< LT >::iterator &  it 
)
noexcept

◆ listContains() [2/2]

template<class LT >
bool stmg::Util::listContains ( const std::list< LT > &  oList,
const LT &  oValue 
)
noexcept

◆ listExtract()

template<class LT >
bool stmg::Util::listExtract ( std::list< LT > &  oList,
const LT &  oValue 
)
noexcept

◆ millisecToMinSecString()

std::string stmg::Util::millisecToMinSecString ( int32_t  nMilliseconds)
noexcept

Formats milliseconds to minutes and seconds.

Ex. 1001 outputs string "0:01.001"

Parameters
nMillisecondsThe value in milliseconds.
Returns
The formatted string.

◆ packPointToInt32()

int32_t stmg::Util::packPointToInt32 ( NPoint  oXY)
inlinenoexcept

Packs a point (64 bit) to an int32_t.

Parameters
oXYThe point to pack. Both m_nX and m_nY must be >= -16384 and < 16384.
Returns
The packed value.

◆ packPointToInt64()

int64_t stmg::Util::packPointToInt64 ( NPoint  oXY)
inlinenoexcept

Packs a point to an int64_t.

Parameters
oXYThe point to pack.
Returns
The packed value.

◆ secToMinSecString()

std::string stmg::Util::secToMinSecString ( int32_t  nSeconds)
noexcept

Formats seconds to minutes.

Ex. 61 outputs string "1:01"

Parameters
nSecondsThe value in seconds.
Returns
The formatted string.

◆ strContainsWhitespace()

bool stmg::Util::strContainsWhitespace ( const std::string &  sStr)
noexcept

Whether a string contains whitespace characters.

Parameters
sStrThe string. Can be empty.
Returns
Whether has any space.

◆ stringCompose()

template<typename ... T>
std::string stmg::Util::stringCompose ( const std::string &  sFormat,
const T &...  oParam 
)
noexcept

Format a string.

Ex. stringCompose("%2ce I saw %1 b%2s", 2, "one") returns "once I saw 2 bones"

Parameters
sFormatThe format string.
oParamThe parameters to be inserted in the format string.
Returns
The formatted string.

◆ strStrip()

std::string stmg::Util::strStrip ( const std::string &  sStr)
noexcept

Strips a string of its leading and trailing space characters.

Ex. " HI there " to "HI there".

Parameters
sStrThe string to strip.
Returns
The stripped string.

◆ strTextToLines()

void stmg::Util::strTextToLines ( const std::string &  sText,
std::vector< std::string > &  aLine 
)
noexcept

Adds lines contained in a string to a vector of strings.

Parameters
sTextThe string containing the text.
aLineThe vector of strings to which the single lines are added.

◆ strToBool()

std::pair<bool, std::string> stmg::Util::strToBool ( const std::string &  sStr)

Convert a string to boolean.

The string can be "t", "T", "true", "True", "TRUE", "y", "Y", "yes", "Yes", "YES" or "f", "F", "false", "False", "FALSE", "n", "N", "no", "No", "NO".

Parameters
sStrThe string. Cannot be empty.
Returns
The result and an empty string or an error string.

◆ strUTF8SizeInCodePoints()

int32_t stmg::Util::strUTF8SizeInCodePoints ( const std::string &  sUtf8)
noexcept

UTF8 string size in code points rather than bytes.

Parameters
sUtf8The UTF8 string.
Returns
The size.

◆ unpackPairFromInt64()

std::pair<int32_t, int32_t> stmg::Util::unpackPairFromInt64 ( int64_t  nXY)
inlinenoexcept

Unpacks a XY pair from an int64_t.

Parameters
nXYThe packed value.
Returns
The point.

◆ unpackPointFromInt32()

NPoint stmg::Util::unpackPointFromInt32 ( int32_t  nXY)
inlinenoexcept

Unpacks a point (64 bit) from an int32_t.

Parameters
nXYThe packed value.
Returns
The point.

◆ unpackPointFromInt64()

NPoint stmg::Util::unpackPointFromInt64 ( int64_t  nXY)
inlinenoexcept

Unpacks a point from an int64_t.

Parameters
nXYThe packed value.
Returns
The point.

◆ vectorContains()

template<class ValueType >
bool stmg::Util::vectorContains ( const std::vector< ValueType > &  oVector,
const ValueType &  oValue 
)
noexcept