15#include "auto_apms_util/string.hpp"
24std::vector<std::string>
splitString(
const std::string & str,
const std::string & delimiter,
bool remove_empty)
26 std::vector<std::string> parts;
28 size_t end = str.find(delimiter);
29 while (end != std::string::npos) {
30 parts.push_back(str.substr(start, end - start));
31 start = end + delimiter.length();
32 end = str.find(delimiter, start);
35 parts.push_back(str.substr(start));
39 auto it = parts.begin();
40 while (it != parts.end()) {
51 const std::map<std::string, std::string> & map,
const std::string & key_val_sep,
const std::string & entry_sep)
53 std::ostringstream oss;
55 for (
const auto & [key, val] : map) {
59 oss << key << key_val_sep << val;
68 case TextColor::GREEN:
69 return "\x1b[32m" + text +
"\x1b[0m";
71 return "\x1b[31m" + text +
"\x1b[0m";
72 case TextColor::YELLOW:
73 return "\x1b[33m" + text +
"\x1b[0m";
75 return "\x1b[34m" + text +
"\x1b[0m";
76 case TextColor::MAGENTA:
77 return "\x1b[35m" + text +
"\x1b[0m";
79 return "\x1b[36m" + text +
"\x1b[0m";
86 std::string::const_iterator start = str.begin();
87 while (start != str.end() && std::isspace(*start)) {
90 std::string::const_iterator end = str.end();
93 }
while (std::distance(start, end) > 0 && std::isspace(*end));
94 return std::string(start, end + 1);
100 bool capitalizeNext =
true;
101 for (
char ch : str) {
103 capitalizeNext =
true;
105 if (capitalizeNext) {
106 new_str += std::toupper(ch);
107 capitalizeNext =
false;
109 new_str += std::tolower(ch);
119 for (
size_t i = 0; i < str.size(); ++i) {
121 if (std::isupper(ch)) {
123 if (i > 0 && std::islower(str[i - 1])) {
129 new_str += std::tolower(ch);
132 if (i + 1 < str.size() && std::isupper(str[i + 1])) {
std::string trimWhitespaces(const std::string &str)
Trim whitespaces from both ends of a string.
std::string makeColoredText(const std::string &text, TextColor color)
Add ANSI color escape sequences to display the text in color when printed to console.
std::vector< std::string > splitString(const std::string &str, const std::string &delimiter, bool remove_empty=true)
Split a string into multiple tokens using a specific delimiter string (Delimiter may consist of multi...
std::string printMap(const std::map< std::string, std::string > &map, const std::string &key_val_sep="=", const std::string &entry_sep=", ")
Converts a map to a string representation that is suited for printing to console.
std::string toCamelCase(const std::string &str)
Transform a string to camelCase.
std::string toSnakeCase(const std::string &str)
Transform a string to snake_case.
Fundamental helper classes and utility functions.