26 #ifndef INCLUDE_OLA_STRINGUTILS_H_
27 #define INCLUDE_OLA_STRINGUTILS_H_
38 enum { HEX_BIT_WIDTH = 4 };
49 void StringSplit(
const std::string &input,
50 std::vector<std::string> &tokens,
51 const std::string &delimiters=
" ");
63 void ShortenString(std::string *input);
71 bool StringBeginsWith(
const std::string &s,
const std::string &prefix);
79 bool StringEndsWith(
const std::string &s,
const std::string &suffix);
87 bool StripPrefix(std::string *s,
const std::string &prefix);
95 bool StripSuffix(std::string *s,
const std::string &suffix);
166 void Escape(std::string *original);
174 std::string EscapeString(
const std::string &original);
182 void ReplaceAll(std::string *original,
183 const std::string &find,
184 const std::string &replace);
195 std::string EncodeString(
const std::string &original);
208 bool StringToBool(
const std::string &value,
bool *output);
223 bool StringToBoolTolerant(
const std::string &value,
bool *output);
233 bool StringToInt(
const std::string &value,
234 unsigned int *output,
235 bool strict =
false);
246 bool StringToInt(
const std::string &value,
248 bool strict =
false);
259 bool StringToInt(
const std::string &value,
261 bool strict =
false);
272 bool StringToInt(
const std::string &value,
int *output,
bool strict =
false);
283 bool StringToInt(
const std::string &value,
285 bool strict =
false);
296 bool StringToInt(
const std::string &value, int8_t *output,
bool strict =
false);
307 bool HexStringToInt(
const std::string &value, uint8_t *output);
318 bool HexStringToInt(
const std::string &value, uint16_t *output);
329 bool HexStringToInt(
const std::string &value, uint32_t *output);
340 bool HexStringToInt(
const std::string &value, int8_t *output);
351 bool HexStringToInt(
const std::string &value, int16_t *output);
362 bool HexStringToInt(
const std::string &value, int32_t *output);
368 void ToLower(std::string *s);
374 void ToUpper(std::string *s);
384 void CapitalizeLabel(std::string *s);
395 void CustomCapitalizeLabel(std::string *s);
412 unsigned int indent = 0,
413 unsigned int byte_per_line = 8);
418 template <
typename int_type>
420 if ((input.find(
"0x") != 0) && (input.find(
"0X") != 0))
422 std::string modified_input = input.substr(2);
423 return HexStringToInt(modified_input, output);
432 std::string
StringJoin(
const std::string &delim,
const T &input) {
433 std::ostringstream str;
434 typename T::const_iterator iter = input.begin();
435 while (iter != input.end()) {
437 if (iter != input.end())
443 #endif // INCLUDE_OLA_STRINGUTILS_H_