UTILLib 2.0
Common C++ library with utilities.
Loading...
Searching...
No Matches
util::string Namespace Reference

The string namespace is used for string manipulation functions. More...

Classes

class  IgnoreCase
class  StringParser
 Helper class that splits a string. More...
class  UnitHelper
 Support class that wrap useful Unit functions. More...
struct  UnitQuantity
 Unit - quantity -physical dimension relation. More...

Typedefs

using UnitQuantityList = std::vector<UnitQuantity>
 List of unit quantity physical dimension relation.

Functions

bool IEquals (const std::string &s1, const std::string &s2, size_t nChar=0)
 Compare strings by ignoring case.
bool IEquals (const std::wstring &s1, const std::wstring &s2, size_t nChar=0)
 Compare wide strings by ignoring case.
void Trim (std::string &text)
 Remove white space from string.
std::string Trim (const std::string &text)
 Remove white space from string.
std::string FormatDouble (double value, uint8_t decimals, bool fixed=false, const std::string &unit={})
 Converts a float to a string.
bool WildcardMatch (const std::string &text, const std::string &wildcard, bool ignore_case)
std::string FloatToString (float value)
 Converts a float to string without loosing precision.
std::string DoubleToString (double value)
 Converts a double to string without loosing precision.

Detailed Description

The string namespace is used for string manipulation functions.

Function Documentation

◆ DoubleToString()

std::string util::string::DoubleToString ( double value)
nodiscard

Converts a double value to a string without loosing any precision.

Parameters
valueDouble value to convert
Returns
The double value as text

◆ FloatToString()

std::string util::string::FloatToString ( float value)
nodiscard

Converts a float value to a string without loosing any precision.

Parameters
valueFloat value to convert
Returns
The float value as text

◆ FormatDouble()

std::string util::string::FormatDouble ( double value,
uint8_t decimals,
bool fixed = false,
const std::string & unit = {} )

Converts a floating point value to a string using number of decimals.
It also fix rounding and returning a fixed decimals. Presenting fixed number of decimals means that it fills up the string with '0' characters.
Example: Value: 1.23 and decimals 3,String: (Fixed = false) "1.23" (Fixed = true) "1.230"
Optional it can append a unit to the string (Example: "1.23 m/s").

Parameters
[in]valueThe floating point value.
[in]decimalsMax number of decimals.
[in]fixedIf it should show fixed number of decimals.
[in]unitAppends a unit string to the output.
Returns
The formatted string.

◆ IEquals() [1/2]

bool util::string::IEquals ( const std::string & s1,
const std::string & s2,
size_t nChar = 0 )

Compare two strings by ignoring case characters.

Parameters
s1String 1
s2String 2
nChar0 = Compare all whole string otherwise compare nChar characters.
Returns
True if the string matches.

◆ IEquals() [2/2]

bool util::string::IEquals ( const std::wstring & s1,
const std::wstring & s2,
size_t nChar = 0 )

Compare two strings by ignoring case characters.

Parameters
s1String 1
s2String 2
nChar0 = Compare all whole string otherwise compare nChar characters.
Returns
True if the string matches.

◆ Trim() [1/2]

std::string util::string::Trim ( const std::string & text)
nodiscard

Remove white space from the begin and end of the string but keep original string.

Parameters
textInput string
Returns
Output trimmed string.

◆ Trim() [2/2]

void util::string::Trim ( std::string & text)

Removes white spaces from the begin and end of the string

Parameters
textString to trim

◆ WildcardMatch()

bool util::string::WildcardMatch ( const std::string & text,
const std::string & wildcard,
bool ignore_case )

Compare a string against a simple * or ? wildcard string

Parameters
textThe text to match
wildcardThe wildcard string
ignore_caseTrue if the algorithm should ignore case
Returns
Returns True if the text string match the wildcard pattern