26 #ifndef INCLUDE_OLA_STRINGUTILS_H_ 27 #define INCLUDE_OLA_STRINGUTILS_H_ 51 std::vector<std::string> *tokens,
52 const std::string &delimiters =
" ");
65 const std::string &input,
66 std::vector<std::string> &tokens,
67 const std::string &delimiters =
" ") {
97 bool StringEndsWith(
const std::string &s,
const std::string &suffix);
105 bool StripPrefix(std::string *s,
const std::string &prefix);
113 bool StripSuffix(std::string *s,
const std::string &suffix);
155 std::ostringstream str;
168 std::ostringstream str;
181 std::ostringstream str;
201 void Escape(std::string *original);
218 const std::string &find,
219 const std::string &replace);
243 bool StringToBool(
const std::string &value,
bool *output);
269 unsigned int *output,
270 bool strict =
false);
283 bool strict =
false);
296 bool strict =
false);
307 bool StringToInt(
const std::string &value,
int *output,
bool strict =
false);
320 bool strict =
false);
331 bool StringToInt(
const std::string &value, int8_t *output,
bool strict =
false);
342 template <
typename int_type>
344 int_type alternative,
345 bool strict =
false) {
347 return (
StringToInt(value, &output, strict)) ? output : alternative;
479 unsigned int indent = 0,
480 unsigned int byte_per_line = 8) {
487 template <
typename int_type>
489 if ((input.find(
"0x") != 0) && (input.find(
"0X") != 0))
491 std::string modified_input = input.substr(2);
501 std::string
StringJoin(
const std::string &delim,
const T &input) {
502 std::ostringstream str;
503 typename T::const_iterator iter = input.begin();
504 while (iter != input.end()) {
506 if (iter != input.end())
512 #endif // INCLUDE_OLA_STRINGUTILS_H_ void CapitalizeLabel(string *s)
Transform a string to a pretty-printed form.
Definition: StringUtils.cpp:414
string EscapeString(const string &original)
Escape a string, returning a copy.
Definition: StringUtils.cpp:296
bool StripPrefix(string *s, const string &prefix)
Strips a prefix from a string.
Definition: StringUtils.cpp:97
void CapitalizeFirst(string *s)
Transform a string by capitalizing the first character.
Definition: StringUtils.cpp:483
bool HexStringToInt(const string &value, uint8_t *output)
Convert a hex string to a uint8_t.
Definition: StringUtils.cpp:330
std::string StringJoin(const std::string &delim, const T &input)
Join a vector of a type.
Definition: StringUtils.h:501
string EncodeString(const string &original)
Encode any unprintable characters in a string as hex, returning a copy.
Definition: StringUtils.cpp:302
std::string IntToString(int i)
Convert an int to a string.
Definition: StringUtils.h:121
void StringTrim(string *input)
Trim leading and trailing whitespace from a string.
Definition: StringUtils.cpp:61
void ShortenString(string *input)
Truncate the string based on the presence of \0 characters.
Definition: StringUtils.cpp:73
bool StringBeginsWith(const string &s, const string &prefix)
Check if one string is a prefix of another.
Definition: StringUtils.cpp:80
void FormatData(std::ostream *out, const uint8_t *data, unsigned int length, unsigned int indent=0, unsigned int byte_per_line=8)
Write binary data to an ostream in a human readable form.
Definition: StringUtils.h:476
bool StringToBool(const string &value, bool *output)
Convert a string to a bool.
Definition: StringUtils.cpp:123
void FormatData(std::ostream *out, const uint8_t *data, unsigned int length, unsigned int indent, unsigned int byte_per_line)
Write binary data to an ostream in a human readable form.
Definition: Format.cpp:46
bool StringEndsWith(const string &s, const string &suffix)
Check if one string is a suffix of another.
Definition: StringUtils.cpp:88
_ToHex< T > ToHex(T v, bool prefix=true)
Convert a value to a hex string.
Definition: Format.h:68
bool StringToBoolTolerant(const string &value, bool *output)
Convert a string to a bool in a tolerant way.
Definition: StringUtils.cpp:136
void CustomCapitalizeLabel(string *s)
Similar to CapitalizeLabel() but this also capitalized known acronyms.
Definition: StringUtils.cpp:437
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
void ToUpper(string *s)
Convert a string to upper case.
Definition: StringUtils.cpp:409
bool StripSuffix(string *s, const string &suffix)
Strips a suffix from a string.
Definition: StringUtils.cpp:106
bool PrefixedHexStringToInt(const std::string &input, int_type *output)
Convert a hex string, prefixed with 0x or 0X to an int type.
Definition: StringUtils.h:488
void StringSplit(const string &input, vector< string > *tokens, const string &delimiters)
Split a string into pieces.
Definition: StringUtils.cpp:42
void ToLower(string *s)
Convert a string to lower case.
Definition: StringUtils.cpp:404
void ReplaceAll(string *original, const string &find, const string &replace)
Replace all instances of the find string with the replace string.
Definition: StringUtils.cpp:317
string IntToHexString(unsigned int i, unsigned int width)
Definition: StringUtils.cpp:115
int_type StringToIntOrDefault(const std::string &value, int_type alternative, bool strict=false)
Convert a string to an int type or return a default if it failed.
Definition: StringUtils.h:343
string IntToString(int i)
Convert an int to a string.
Definition: Format.cpp:34
bool StringToInt(const string &value, unsigned int *output, bool strict)
Convert a string to a unsigned int.
Definition: StringUtils.cpp:155
void Escape(string *original)
Escape a string with \ .
Definition: StringUtils.cpp:249