Fixposition SDK 0.0.0-heads/main-0-g7b59b93
Collection of c++ libraries and apps for use with Fixposition products
Loading...
Searching...
No Matches
fpsdk::common::string Namespace Reference

String utilities. More...

Functions

std::string Sprintf (const char *const fmt,...) PRINTF_ATTR(1)
 Format string.
 
std::string Vsprintf (const char *fmt, va_list args)
 Format string.
 
std::string Strftime (const char *const fmt, const int64_t ts=0, const bool utc=false)
 Format time.
 
int StrReplace (std::string &str, const std::string &search, const std::string &replace, const int max=0)
 Search and replace.
 
void StrTrimLeft (std::string &str)
 Trim string left.
 
void StrTrimRight (std::string &str)
 Trim string right.
 
void StrTrim (std::string &str)
 Trim string left and right.
 
std::vector< std::string > StrSplit (const std::string &str, const std::string &sep, const int maxNum=0)
 Split string.
 
std::string StrJoin (const std::vector< std::string > &strs, const std::string &sep)
 Join strings.
 
std::vector< std::string > StrMap (const std::vector< std::string > &strs, std::function< std::string(const std::string &)> map)
 Map strings.
 
void MakeUnique (std::vector< std::string > &strs)
 Remove duplicates.
 
std::vector< std::string > HexDump (const std::vector< uint8_t > data)
 Format hexdump of data.
 
std::vector< std::string > HexDump (const uint8_t *data, const std::size_t size)
 Format hexdump of data.
 
bool StrStartsWith (const std::string &str, const std::string &prefix)
 Check if one string starts with another string.
 
bool StrEndsWith (const std::string &str, const std::string &suffix)
 Check if one string ends with another string.
 
bool StrContains (const std::string &str, const std::string &sub)
 Check if one string is contained within another string string.
 
bool StrToValue (const std::string &str, int8_t &value)
 Convert string to value (int8_t)
 
bool StrToValue (const std::string &str, uint8_t &value)
 Convert string to value (uint8_t)
 
bool StrToValue (const std::string &str, int16_t &value)
 Convert string to value (int16_t)
 
bool StrToValue (const std::string &str, uint16_t &value)
 Convert string to value (uint16_t)
 
bool StrToValue (const std::string &str, int32_t &value)
 Convert string to value (int32_t)
 
bool StrToValue (const std::string &str, uint32_t &value)
 Convert string to value (uint32_t)
 
bool StrToValue (const std::string &str, int64_t &value)
 Convert string to value (int64_t, long)
 
bool StrToValue (const std::string &str, uint64_t &value)
 Convert string to value (uint64_t, unsigned long)
 
bool StrToValue (const std::string &str, float &value)
 Convert string to value (float)
 
bool StrToValue (const std::string &str, double &value)
 Convert string to value (double)
 
std::string StrToUpper (const std::string &str)
 Convert string to all upper case.
 
std::string StrToLower (const std::string &str)
 Convert string to all lower case.
 

Detailed Description

String utilities.

Function Documentation

◆ Sprintf()

std::string fpsdk::common::string::Sprintf ( const char *const fmt,
... )

Format string.

Parameters
[in]fmtprintf() style format string
[in]...Arguments to the format string
Returns
the formatted string

◆ Vsprintf()

std::string fpsdk::common::string::Vsprintf ( const char * fmt,
va_list args )

Format string.

Parameters
[in]fmtprintf() style format string
[in]argsArguments list to the format string
Returns
the formatted string

◆ Strftime()

std::string fpsdk::common::string::Strftime ( const char *const fmt,
const int64_t ts = 0,
const bool utc = false )

Format time.

Parameters
[in]fmtFormat, see strftime(3), can be NULL for a default "yyyy-mm-dd hh:mm:ss" format
[in]tsPosix timestamp [s] (time_t), or 0 for "now"
[in]utcFormat as UTC (true) or localtime (false, default)
Returns
a string with the formatted time

◆ StrReplace()

int fpsdk::common::string::StrReplace ( std::string & str,
const std::string & search,
const std::string & replace,
const int max = 0 )

Search and replace.

Parameters
[in,out]strThe string to search and replace in
[in]searchThe search term
[in]replaceThe replacement
[in]maxMaximum number of replacements to do (or <= 0 for unlimited)
Returns
the number of matches

◆ StrTrimLeft()

void fpsdk::common::string::StrTrimLeft ( std::string & str)

Trim string left.

Parameters
[in,out]strThe string with all whitespace (" ", \t, \r, \n) removed on the left

◆ StrTrimRight()

void fpsdk::common::string::StrTrimRight ( std::string & str)

Trim string right.

Parameters
[in,out]strThe string with all whitespace (" ", \t, \r, \n) removed on the right

◆ StrTrim()

void fpsdk::common::string::StrTrim ( std::string & str)

Trim string left and right.

Parameters
[in,out]strThe string with all whitespace (" ", \t, \r, \n) removed on the left and the right

◆ StrSplit()

std::vector< std::string > fpsdk::common::string::StrSplit ( const std::string & str,
const std::string & sep,
const int maxNum = 0 )

Split string.

Splits a string using a separator string. All parts, including empty ones, are returned. An empty separator leads to only one part, that is equal to the input string.

Examples: "foo,bar,baz" separated by "," --> [ "foo", "bar", "baz" ] "foo,bar,baz" separated by "," (max=2) --> [ "foo", "bar,baz" ] "foo,,baz,,," separated by "," --> [ "foo", "", "baz", "", "", "" ]

Parameters
[in]strThe string
[in]sepThe separator, empty string is allowed
[in]maxNumThe maximum number of parts, or 0 (default) for as many as necessary
Returns
a vector with all parts

◆ StrJoin()

std::string fpsdk::common::string::StrJoin ( const std::vector< std::string > & strs,
const std::string & sep )

Join strings.

Parameters
[in]strsList of strings to join
[in]sepSeparator
Returns
a string of all given parts separated by the given separator

◆ StrMap()

std::vector< std::string > fpsdk::common::string::StrMap ( const std::vector< std::string > & strs,
std::function< std::string(const std::string &)> map )

Map strings.

Parameters
[in]strsList of strings to map
[in]mapMap function
Returns
the mapped list of strings

◆ MakeUnique()

void fpsdk::common::string::MakeUnique ( std::vector< std::string > & strs)

Remove duplicates.

Parameters
[in]strsList of strings

◆ HexDump() [1/2]

std::vector< std::string > fpsdk::common::string::HexDump ( const std::vector< uint8_t > data)

Format hexdump of data.

Parameters
[in]dataThe data
Returns
one or more lines (strings) with a hexdump of the data

◆ HexDump() [2/2]

std::vector< std::string > fpsdk::common::string::HexDump ( const uint8_t * data,
const std::size_t size )

Format hexdump of data.

Parameters
[in]dataThe data
[in]sizeThe size of the data
Returns
one or more lines (strings) with a hexdump of the data

◆ StrStartsWith()

bool fpsdk::common::string::StrStartsWith ( const std::string & str,
const std::string & prefix )

Check if one string starts with another string.

Parameters
[in]strString to check
[in]prefixPrefix to check, length must be >= length of str
Returns
true if string starts with the prefix, false otherwise (no match or empty string(s))

◆ StrEndsWith()

bool fpsdk::common::string::StrEndsWith ( const std::string & str,
const std::string & suffix )

Check if one string ends with another string.

Parameters
[in]strString to check
[in]suffixPrefix to check, length must be >= length of str
Returns
true if string ends with the suffix, false otherwise (no match or empty string(s))

◆ StrContains()

bool fpsdk::common::string::StrContains ( const std::string & str,
const std::string & sub )

Check if one string is contained within another string string.

Parameters
[in]strString to check
[in]subString to find
Returns
true if string contains the substriong, false otherwise(no match or empty string(s))

◆ StrToValue() [1/10]

bool fpsdk::common::string::StrToValue ( const std::string & str,
int8_t & value )

Convert string to value (int8_t)

Note
White-space or other spurious characters in the string or valid number strings that are out of range of the target value type result in a failure (return false). The output value is only modified on success.
Parameters
[in]strThe string, decimal, hex ("0x...") or octal ("0..."), valid range: INT8_MIN..INT8_MAX
[out]valueThe value
Returns
true if the string could be converted, false otherwise

Referenced by fpsdk::apps::fpltool::FplToolOptions::HandleOption().

◆ StrToValue() [2/10]

bool fpsdk::common::string::StrToValue ( const std::string & str,
uint8_t & value )

Convert string to value (uint8_t)

Note
White-space or other spurious characters in the string or valid number strings that are out of range of the target value type result in a failure (return false). The output value is only modified on success.
Parameters
[in]strThe string, decimal, hex ("0x...") or octal ("0..."), valid range: 0..UINT8_MAX
[out]valueThe value
Returns
true if the string could be converted, false otherwise

◆ StrToValue() [3/10]

bool fpsdk::common::string::StrToValue ( const std::string & str,
int16_t & value )

Convert string to value (int16_t)

Note
White-space or other spurious characters in the string or valid number strings that are out of range of the target value type result in a failure (return false). The output value is only modified on success.
Parameters
[in]strThe string, decimal, hex ("0x...") or octal ("0..."), valid range: INT16_MIN..INT16_MAX
[out]valueThe value
Returns
true if the string could be converted, false otherwise

◆ StrToValue() [4/10]

bool fpsdk::common::string::StrToValue ( const std::string & str,
uint16_t & value )

Convert string to value (uint16_t)

Note
White-space or other spurious characters in the string or valid number strings that are out of range of the target value type result in a failure (return false). The output value is only modified on success.
Parameters
[in]strThe string, decimal, hex ("0x...") or octal ("0..."), valid range: 0..UINT16_MAX
[out]valueThe value
Returns
true if the string could be converted, false otherwise

◆ StrToValue() [5/10]

bool fpsdk::common::string::StrToValue ( const std::string & str,
int32_t & value )

Convert string to value (int32_t)

Note
White-space or other spurious characters in the string or valid number strings that are out of range of the target value type result in a failure (return false). The output value is only modified on success.
Parameters
[in]strThe string, decimal, hex ("0x...") or octal ("0..."), valid range: INT32_MIN..INT32_MAX
[out]valueThe value
Returns
true if the string could be converted, false otherwise

◆ StrToValue() [6/10]

bool fpsdk::common::string::StrToValue ( const std::string & str,
uint32_t & value )

Convert string to value (uint32_t)

Note
White-space or other spurious characters in the string or valid number strings that are out of range of the target value type result in a failure (return false). The output value is only modified on success.
Parameters
[in]strThe string, decimal, hex ("0x...") or octal ("0..."), valid range: 0..UINT32_MAX
[out]valueThe value
Returns
true if the string could be converted, false otherwise

◆ StrToValue() [7/10]

bool fpsdk::common::string::StrToValue ( const std::string & str,
int64_t & value )

Convert string to value (int64_t, long)

Note
White-space or other spurious characters in the string or valid number strings that are out of range of the target value type result in a failure (return false). The output value is only modified on success.
Parameters
[in]strThe string, decimal, hex ("0x...") or octal ("0..."), valid range: (INT64_MIN+1)..(INT64_MAX-1)
[out]valueThe value
Returns
true if the string could be converted, false otherwise

◆ StrToValue() [8/10]

bool fpsdk::common::string::StrToValue ( const std::string & str,
uint64_t & value )

Convert string to value (uint64_t, unsigned long)

Note
White-space or other spurious characters in the string or valid number strings that are out of range of the target value type result in a failure (return false). The output value is only modified on success.
Parameters
[in]strThe string, decimal, hex ("0x...") or octal ("0..."), valid range: 0..(INT64_MAX-1)
[out]valueThe value
Returns
true if the string could be converted, false otherwise

◆ StrToValue() [9/10]

bool fpsdk::common::string::StrToValue ( const std::string & str,
float & value )

Convert string to value (float)

Note
White-space or other spurious characters in the string or valid number strings that are out of range of the target value type result in a failure (return false). The output value is only modified on success.
Parameters
[in]strThe string, anything f understands (but not infinite or NaN)
[out]valueThe value
Returns
true if the string could be converted, false otherwise

◆ StrToValue() [10/10]

bool fpsdk::common::string::StrToValue ( const std::string & str,
double & value )

Convert string to value (double)

Note
White-space or other spurious characters in the string or valid number strings that are out of range of the target value type result in a failure (return false). The output value is only modified on success.
Parameters
[in]strThe string, anything f understands (but not infinite or NaN)
[out]valueThe value
Returns
true if the string could be converted, false otherwise

◆ StrToUpper()

std::string fpsdk::common::string::StrToUpper ( const std::string & str)

Convert string to all upper case.

Parameters
[in]strThe string
Returns
the string converted to all upper case

◆ StrToLower()

std::string fpsdk::common::string::StrToLower ( const std::string & str)

Convert string to all lower case.

Parameters
[in]strThe string
Returns
the string converted to all lower case