18#ifndef __FPSDK_COMMON_STRING_HPP__
19#define __FPSDK_COMMON_STRING_HPP__
47# define PRINTF_ATTR(n) __attribute__((format(printf, n, n + 1)))
68std::
string Vsprintf(const
char* fmt, va_list args);
79std::
string Strftime(const
char* const fmt, const int64_t ts = 0, const
bool utc = false);
91int StrReplace(std::
string& str, const std::
string& search, const std::
string& replace, const
int max = 0);
131std::vector<std::
string>
StrSplit(const std::
string& str, const std::
string& sep, const
int maxNum = 0);
141std::
string StrJoin(const std::vector<std::
string>& strs, const std::
string& sep);
152 const std::vector<std::
string>& strs, std::function<std::
string(const std::
string&)> map);
168std::vector<std::
string>
HexDump(const std::vector<uint8_t> data);
178std::vector<std::
string>
HexDump(const uint8_t* data, const std::
size_t size);
188std::
string StrFormatBits(const uint64_t value, const std::
size_t size = 64);
208bool StrEndsWith(const std::
string& str, const std::
string& suffix);
404constexpr const
char*
ToStr(const
bool value)
406 return value ?
"true" :
"false";
416std::vector<uint8_t>
StrToVec(
const std::string& str);
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.
void StrTrimLeft(std::string &str)
Trim string left.
std::vector< std::string > StrSplit(const std::string &str, const std::string &sep, const int maxNum=0)
Split string.
std::string StrToUpper(const std::string &str)
Convert string to all upper case.
std::vector< std::string > HexDump(const std::vector< uint8_t > data)
Format hexdump of data.
void StrTrimRight(std::string &str)
Trim string right.
std::vector< std::string > StrMap(const std::vector< std::string > &strs, std::function< std::string(const std::string &)> map)
Map strings.
void StrTrim(std::string &str)
Trim string left and right.
constexpr const char * ToStr(const bool value)
Stringify value (bool)
std::string StrToLower(const std::string &str)
Convert string to all lower case.
bool StrToValue(const std::string &str, int8_t &value)
Convert string to value (int8_t)
bool StrEndsWith(const std::string &str, const std::string &suffix)
Check if one string ends with another string.
std::string StrFormatBits(const uint64_t value, const std::size_t size=64)
Format value to "bits string".
std::vector< uint8_t > StrToVec(const std::string &str)
Convert string to buffer.
bool StrContains(const std::string &str, const std::string &sub)
Check if one string is contained within another string string.
std::string Sprintf(const char *const fmt,...) PRINTF_ATTR(1)
Format string.
bool StrStartsWith(const std::string &str, const std::string &prefix)
Check if one string starts with another string.
std::string StrJoin(const std::vector< std::string > &strs, const std::string &sep)
Join strings.
std::string StrError(const int errnum)
Stringify glibc error.
int StrReplace(std::string &str, const std::string &search, const std::string &replace, const int max=0)
Search and replace.
void MakeUnique(std::vector< std::string > &strs)
Remove duplicates.
#define PRINTF_ATTR(n)
Helper macro for marking functions as taking printf() style formatting strings.