21 const char* delimiters,
22 bool tokenCompression =
true)
24 std::stringstream stringStream(str);
26 std::vector<std::string> tokenVector;
27 while (std::getline(stringStream, line))
31 while ((pos = line.find_first_of(delimiters, prev)) != std::string::npos)
36 tokenVector.push_back(line.substr(prev, pos - prev));
39 else if (!tokenCompression)
41 tokenVector.push_back(line.substr(prev, pos - prev));
45 if (prev < line.length())
47 tokenVector.push_back(line.substr(prev, std::string::npos));
59 inline std::string&
StringStartTrim(std::string& str,
const std::string& chars =
"\t\n\v\f\r ")
61 str.erase(0, str.find_first_not_of(chars));
68 inline std::string&
StringEndTrim(std::string& str,
const std::string& chars =
"\t\n\v\f\r ")
70 str.erase(str.find_last_not_of(chars) + 1);
77 inline std::string&
StringTrim(std::string& str,
const std::string& chars =
"\t\n\v\f\r ")
85 inline std::string
StringTrimCopy(
const std::string& str,
const std::string& chars =
"\t\n\v\f\r ")
87 std::string strCopy = str;
93 inline std::string
StringConcat(
const std::vector<std::string>& strings, std::string seperator =
"")
96 for (
auto string : strings)
98 ss <<
string << seperator;
107 const std::string& oldStr,
108 const std::string& newStr)
110 std::string::size_type pos = 0u;
111 while ((pos = str.find(oldStr, pos)) != std::string::npos)
113 str.replace(pos, oldStr.length(), newStr);
114 pos += newStr.length();
std::vector< std::string > StringTokenizer(const std::string &str, const char *delimiters, bool tokenCompression=true)
Function to take a string and a list of delimiters and split the string into tokens based on those de...
std::string & StringEndTrim(std::string &str, const std::string &chars="\\\")
Trim for the end of a string.
Copyright (c) 2021 ARM Limited and Contributors.
std::string StringTrimCopy(const std::string &str, const std::string &chars="\\\")
Trim from both the start and the end of a string, returns a trimmed copy of the string.
void StringReplaceAll(std::string &str, const std::string &oldStr, const std::string &newStr)
Iterates over a given str and replaces all instance of substring oldStr with newStr.
std::string StringConcat(const std::vector< std::string > &strings, std::string seperator="")
Takes a vector of strings and concatenates them together into one long std::string with an optional s...
std::string & StringStartTrim(std::string &str, const std::string &chars="\\\")
Trim from the start of a string.
std::string & StringTrim(std::string &str, const std::string &chars="\\\")
Trim from both the start and the end of a string.