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;
156 str << ola::strings::ToHex(i);
168 std::ostringstream str;
169 str << ola::strings::ToHex(i);
181 std::ostringstream str;
182 str << ola::strings::ToHex(i);
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;
471 unsigned int indent = 0,
472 unsigned int byte_per_line = 8) {
479 template <
typename int_type>
481 if ((input.find(
"0x") != 0) && (input.find(
"0X") != 0))
483 std::string modified_input = input.substr(2);
493 std::string
StringJoin(
const std::string &delim,
const T &input) {
494 std::ostringstream str;
495 typename T::const_iterator iter = input.begin();
496 while (iter != input.end()) {
498 if (iter != input.end())
504 #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:478
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:493
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:468
bool StringToBool(const string &value, bool *output)
Convert a string to a bool.
Definition: StringUtils.cpp:123
bool StringEndsWith(const string &s, const string &suffix)
Check if one string is a suffix of another.
Definition: StringUtils.cpp:88
bool StringToBoolTolerant(const string &value, bool *output)
Convert a string to a bool in a tolerant way.
Definition: StringUtils.cpp:136
std::string IntToString(unsigned int i)
Definition: StringUtils.h:131
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:480
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
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