Miscellaneous string, parsing, and version utilities.
| Name | Description |
|---|---|
Version | Semantic version number with major, minor, and patch fields. |
| Return | Name | Description |
|---|---|---|
std::string | format | Printf-style string formatting for POD types. |
void | toUnderscore | Replaces all non-alphanumeric characters in str with underscores and converts to lowercase. |
bool | isNumber | Returns true if str consists entirely of digit characters. |
bool | endsWith | Returns true if str ends with the given suffix. |
void | removeSpecialCharacters | Replaces non-alphanumeric characters. Removes all non-alphanumeric characters from str in place. |
void | replaceSpecialCharacters | Replaces all non-alphanumeric characters in str with with in place. |
bool | tryParseHex | Attempts to parse a hex string into an unsigned integer. |
unsigned | parseHex | Parses a hex string into an unsigned integer. |
std::string | dumpbin | Formats the binary contents of data as a hex+ASCII dump string. |
bool | compareVersion | Compares two dot-separated version strings. |
bool | matchNodes | Checks whether node matches xnode by splitting both on delim and comparing element-wise. |
bool | matchNodes | Checks whether params matches xparams element-wise. |
std::string | memAddress | Returns the memory address of ptr as a hex string (e.g. "0x7f3a2b10c0"). |
std::string | itostr | Converts an integer (or any stream-insertable type) to its string representation. |
T | strtoi | Parses a string into integer type T using std::istringstream. Returns 0 if parsing fails. Ensure T has sufficient range for the value. |
uint32_t | randomNumber | Generates a 31-bit pseudo random number using the internal Random instance. |
std::string | randomString | Generates a random alphanumeric string of the given length. |
std::string | randomBinaryString | Generates a random binary string of the given byte length. |
void | split | Splits str on the delimiter string and appends tokens to elems. |
std::vector< std::string > | split | Splits str on the delimiter string and returns the tokens as a vector. |
void | split | Splits str on the delimiter character and appends tokens to elems. |
std::vector< std::string > | split | Splits str on the delimiter character and returns the tokens as a vector. |
S & | replaceInPlace | Replace all occurrences of from in str with to, starting at position start. Modifies and returns str in place. from must not be empty. |
S & | replaceInPlace | Replace all occurrences of from in str with to, starting at position start. C-string overload. Modifies and returns str in place. |
S | replace | Replace all occurences of from (which must not be the empty string) in str with to, starting at position start. |
S | replace | Returns a copy of str with all occurrences of from replaced by to (C-string overload). |
S | trimLeft | Returns a copy of str with all leading whitespace removed. |
S & | trimLeftInPlace | Removes all leading whitespace in str. |
S | trimRight | Returns a copy of str with all trailing whitespace removed. |
S & | trimRightInPlace | Removes all trailing whitespace in str. |
S | trim | Returns a copy of str with all leading and trailing whitespace removed. |
S & | trimInPlace | Removes all leading and trailing whitespace in str. |
S | toUpper | Returns a copy of str containing all upper-case characters. |
S & | toUpperInPlace | Replaces all characters in str with their upper-case counterparts. |
S | toLower | Returns a copy of str containing all lower-case characters. |
S & | toLowerInPlace | Replaces all characters in str with their lower-case counterparts. |
int | icompare inline | Case-insensitive string comparison (locale-independent, ASCII only). |
std::streamsize | copyStreamUnbuffered | Copies all bytes from istr to ostr one byte at a time (no internal buffer). |
std::streamsize | copyStream | Copies all bytes from istr to ostr using an internal buffer. |
std::streamsize | copyToString | Reads all bytes from istr and appends them to str. |
void | clearList inline | Delete all elements from a list of pointers. |
void | clearDeque inline | Delete all elements from a deque of pointers. |
void | clearVector inline | Delete all elements from a vector of pointers. |
void | clearMap inline | Delete all associated values from a map (not the key elements). |
std::string format(const char * fmt, ...)Printf-style string formatting for POD types.
fmt printf format string.
... Format arguments.
Formatted string.
void toUnderscore(std::string & str)Replaces all non-alphanumeric characters in str with underscores and converts to lowercase.
str String to transform in place.bool isNumber(std::string_view str)Returns true if str consists entirely of digit characters.
str String to test.true if every character in str is a decimal digit.
bool endsWith(std::string_view str, std::string_view suffix)Returns true if str ends with the given suffix.
str String to test.
suffix Suffix to look for.
true if str ends with suffix.
void removeSpecialCharacters(std::string & str, bool allowSpaces)Replaces non-alphanumeric characters. Removes all non-alphanumeric characters from str in place.
str String to modify.
allowSpaces If true, ASCII spaces are preserved.
void replaceSpecialCharacters(std::string & str, char with, bool allowSpaces)Replaces all non-alphanumeric characters in str with with in place.
str String to modify.
with Replacement character (default: '_').
allowSpaces If true, ASCII spaces are preserved rather than replaced.
bool tryParseHex(std::string_view s, unsigned & value)Attempts to parse a hex string into an unsigned integer.
s Hex string (with or without 0x prefix).
value Output: parsed value on success.
true if parsing succeeded, false otherwise.
unsigned parseHex(std::string_view s)Parses a hex string into an unsigned integer.
s Hex string (with or without 0x prefix).Parsed value.
std::invalid_argument if the string is not valid hex.std::string dumpbin(const char * data, size_t len)Formats the binary contents of data as a hex+ASCII dump string.
data Pointer to the buffer to dump.
len Number of bytes to dump.
Multi-line hex dump string.
bool compareVersion(std::string_view l, std::string_view r)Compares two dot-separated version strings.
l Left (local) version string.
r Right (remote) version string.
true if l is strictly greater than r, false if l is equal or less.
bool matchNodes(std::string_view node, std::string_view xnode, std::string_view delim)Checks whether node matches xnode by splitting both on delim and comparing element-wise.
node Node list string to test.
xnode Expected node list pattern.
delim Delimiter used to split both strings (default: "\r\n").
true if all elements of node match the corresponding elements of xnode.
bool matchNodes(const std::vector< std::string > & params, const std::vector< std::string > & xparams)Checks whether params matches xparams element-wise.
params Parameter list to test.
xparams Expected parameter list.
true if every element of params matches the corresponding element of xparams.
std::string memAddress(const void * ptr)Returns the memory address of ptr as a hex string (e.g. "0x7f3a2b10c0").
ptr Pointer whose address to format.Hex string representation of the pointer value.
template<typename T> std::string itostr(const T & t)Converts an integer (or any stream-insertable type) to its string representation.
T Type to convert; must support operator<< on std::ostream.t Value to convert.String representation of t.
template<typename T> T strtoi(std::string_view s)Parses a string into integer type T using std::istringstream. Returns 0 if parsing fails. Ensure T has sufficient range for the value.
T Target integer type.s String to parse.Parsed value, or 0 on failure.
uint32_t randomNumber()Generates a 31-bit pseudo random number using the internal Random instance.
Pseudo random uint32_t value.
std::string randomString(int size)Generates a random alphanumeric string of the given length.
size Number of characters to generate.Random string of length size.
std::string randomBinaryString(int size, bool doBase64)Generates a random binary string of the given byte length.
size Number of random bytes to generate.
doBase64 If true, returns the bytes as a base64-encoded string.
Random binary string, optionally base64-encoded.
void split(std::string_view str, std::string_view delim, std::vector< std::string > & elems, int limit)Splits str on the delimiter string and appends tokens to elems.
str String to split.
delim Delimiter string.
elems Output vector; tokens are appended to it.
limit Maximum number of splits (-1 for unlimited).
std::vector< std::string > split(std::string_view str, std::string_view delim, int limit)Splits str on the delimiter string and returns the tokens as a vector.
str String to split.
delim Delimiter string.
limit Maximum number of splits (-1 for unlimited).
Vector of token strings.
void split(std::string_view str, char delim, std::vector< std::string > & elems, int limit)Splits str on the delimiter character and appends tokens to elems.
str String to split.
delim Delimiter character.
elems Output vector; tokens are appended to it.
limit Maximum number of splits (-1 for unlimited).
std::vector< std::string > split(std::string_view str, char delim, int limit)Splits str on the delimiter character and returns the tokens as a vector.
str String to split.
delim Delimiter character.
limit Maximum number of splits (-1 for unlimited).
Vector of token strings.
template<class S> S & replaceInPlace(S & str, const S & from, const S & to, typename S::size_type start)Replace all occurrences of from in str with to, starting at position start. Modifies and returns str in place. from must not be empty.
template<class S> S & replaceInPlace(S & str, const typename S::value_type * from, const typename S::value_type * to, typename S::size_type start)Replace all occurrences of from in str with to, starting at position start. C-string overload. Modifies and returns str in place.
template<class S> S replace(const S & str, const S & from, const S & to, typename S::size_type start)Replace all occurences of from (which must not be the empty string) in str with to, starting at position start.
template<class S> S replace(const S & str, const typename S::value_type * from, const typename S::value_type * to, typename S::size_type start)Returns a copy of str with all occurrences of from replaced by to (C-string overload).
str Source string.
from Substring to search for; must not be empty.
to Replacement string.
start Position in str at which to begin searching (default: 0).
New string with all replacements applied.
template<class S> S trimLeft(const S & str)Returns a copy of str with all leading whitespace removed.
template<class S> S & trimLeftInPlace(S & str)Removes all leading whitespace in str.
template<class S> S trimRight(const S & str)Returns a copy of str with all trailing whitespace removed.
template<class S> S & trimRightInPlace(S & str)Removes all trailing whitespace in str.
template<class S> S trim(const S & str)Returns a copy of str with all leading and trailing whitespace removed.
template<class S> S & trimInPlace(S & str)Removes all leading and trailing whitespace in str.
template<class S> S toUpper(const S & str)Returns a copy of str containing all upper-case characters.
template<class S> S & toUpperInPlace(S & str)Replaces all characters in str with their upper-case counterparts.
template<class S> S toLower(const S & str)Returns a copy of str containing all lower-case characters.
template<class S> S & toLowerInPlace(S & str)Replaces all characters in str with their lower-case counterparts.
inline
inline int icompare(std::string_view a, std::string_view b)Case-insensitive string comparison (locale-independent, ASCII only).
a First string.
b Second string.
Negative if a < b, zero if a == b, positive if a > b.
std::streamsize copyStreamUnbuffered(std::istream & istr, std::ostream & ostr)Copies all bytes from istr to ostr one byte at a time (no internal buffer).
istr Source stream.
ostr Destination stream.
Total number of bytes copied.
std::streamsize copyStream(std::istream & istr, std::ostream & ostr, size_t bufferSize)Copies all bytes from istr to ostr using an internal buffer.
istr Source stream.
ostr Destination stream.
bufferSize Internal buffer size in bytes (default: 8192).
Total number of bytes copied.
std::streamsize copyToString(std::istream & istr, std::string & str, size_t bufferSize)Reads all bytes from istr and appends them to str.
istr Source stream.
str Output string to append data to.
bufferSize Internal buffer size in bytes (default: 8192).
Total number of bytes read.
inline
template<typename Val> inline void clearList(std::list< Val * > & L)Delete all elements from a list of pointers.
inline
template<typename Val> inline void clearDeque(std::deque< Val * > & D)Delete all elements from a deque of pointers.
inline
template<typename Val> inline void clearVector(std::vector< Val * > & V)Delete all elements from a vector of pointers.
inline
template<typename Key, typename Val> inline void clearMap(std::map< Key, Val * > & M)Delete all associated values from a map (not the key elements).