LogCabin
|
Namespaces | |
namespace | anonymous_namespace{StringUtil.cc} |
Functions | |
std::string | format (const char *format,...))) |
A safe version of sprintf. | |
std::string | flags (int value, std::initializer_list< std::pair< int, const char * >> flags) |
Format an ORed group of flags as a string. | |
bool | isPrintable (const char *str) |
Determine whether a null-terminated string is printable. | |
bool | isPrintable (const void *data, size_t length) |
Determine whether some data is a printable, null-terminated string. | |
std::string | join (const std::vector< std::string > &components, const std::string &glue) |
void | replaceAll (std::string &haystack, const std::string &needle, const std::string &replacement) |
For strings, replace all occurrences of 'needle' in 'haystack' with 'replacement'. | |
std::vector< std::string > | split (const std::string &subject, char delimiter) |
Split a string into multiple components by a character. | |
bool | startsWith (const std::string &haystack, const std::string &needle) |
Return true if haystack begins with needle. | |
bool | endsWith (const std::string &haystack, const std::string &needle) |
Return true if haystack ends with needle. | |
std::string | trim (const std::string &s) |
Return a copy of the given string except with no leading or trailing whitespace. | |
template<typename T > | |
std::string | toString (const T &t) |
Return a string returned from the given object's stream operator. |
std::string LogCabin::Core::StringUtil::format | ( | const char * | format, |
... | |||
) |
A safe version of sprintf.
Definition at line 70 of file StringUtil.cc.
std::string LogCabin::Core::StringUtil::flags | ( | int | value, |
std::initializer_list< std::pair< int, const char * >> | flags | ||
) |
Format an ORed group of flags as a string.
value | The ORed options. |
flags | Maps option identifiers to their string names, such as {{FOO, "FOO"}, {BAR, "BAR"}}. |
Definition at line 51 of file StringUtil.cc.
bool LogCabin::Core::StringUtil::isPrintable | ( | const char * | str | ) |
Determine whether a null-terminated string is printable.
str | A null-terminated string. |
Definition at line 100 of file StringUtil.cc.
bool LogCabin::Core::StringUtil::isPrintable | ( | const void * | data, |
size_t | length | ||
) |
Determine whether some data is a printable, null-terminated string.
data | The first byte. |
length | The number of bytes of 'data'. |
Definition at line 106 of file StringUtil.cc.
std::string LogCabin::Core::StringUtil::join | ( | const std::vector< std::string > & | components, |
const std::string & | glue | ||
) |
Definition at line 116 of file StringUtil.cc.
void LogCabin::Core::StringUtil::replaceAll | ( | std::string & | haystack, |
const std::string & | needle, | ||
const std::string & | replacement | ||
) |
For strings, replace all occurrences of 'needle' in 'haystack' with 'replacement'.
If this isn't what you're looking for, the standard algorithm std::replace might help you.
Definition at line 128 of file StringUtil.cc.
std::vector< std::string > LogCabin::Core::StringUtil::split | ( | const std::string & | subject, |
char | delimiter | ||
) |
Split a string into multiple components by a character.
subject | The string to split. |
delimiter | The character to split the string by. |
Definition at line 143 of file StringUtil.cc.
bool LogCabin::Core::StringUtil::startsWith | ( | const std::string & | haystack, |
const std::string & | needle | ||
) |
Return true if haystack begins with needle.
Definition at line 154 of file StringUtil.cc.
bool LogCabin::Core::StringUtil::endsWith | ( | const std::string & | haystack, |
const std::string & | needle | ||
) |
Return true if haystack ends with needle.
Definition at line 160 of file StringUtil.cc.
std::string LogCabin::Core::StringUtil::trim | ( | const std::string & | original | ) |
Return a copy of the given string except with no leading or trailing whitespace.
Definition at line 169 of file StringUtil.cc.
std::string LogCabin::Core::StringUtil::toString | ( | const T & | t | ) |
Return a string returned from the given object's stream operator.
This is useful when you're dealing with strings, but the object you want to print only has a stream operator.
Definition at line 117 of file StringUtil.h.