23inline std::vector<std::string>
split(
const std::string& input,
const char delimiter, int64_t limit = -1) {
25 std::vector<std::string> out;
26 std::transform(input.begin(), input.end(), std::back_inserter(out), [](
const char& chr) {
27 return std::string(1, chr);
30 }
else if (limit == 0) {
32 }
else if (input.empty()) {
36 std::vector<std::string> out;
37 std::stringstream stream(input);
40 while (getline(stream, line, delimiter)) {
47 std::stringstream remainder;
48 remainder << stream.rdbuf();
49 std::string res = remainder.str();
52 }
else if (input.at(input.size() - 1) == delimiter) {
68inline std::vector<std::string>
split(
const std::string& input,
const std::string& delimiter, int64_t limit = -1) {
69 if (delimiter.size() == 1) {
70 return split(input, delimiter[0], limit);
71 }
else if (delimiter.size() == 0) {
72 return split(input, 0, limit);
73 }
else if (limit == 0) {
75 }
else if (input.empty()) {
79 std::vector<std::string> out;
84 while ((pos = input.find(delimiter, index)) != std::string::npos) {
86 token = input.substr(index, pos - index);
87 index = pos + delimiter.size();
94 if (index < input.size()) {
95 out.push_back(input.substr(index));
96 }
else if (index == input.size()) {
105 std::vector<int> out;
106 for (
auto& chr : input) {
117 for (
const char c : input) {
118 output += std::to_string(c) +
" ";
123inline void replaceAll(std::string& input,
const std::string& find,
const std::string& replaceWith,
size_t limit = 0) {
130 while ((pos = input.find(find, pos)) != std::string::npos) {
131 input.replace(pos, find.length(), replaceWith);
132 pos += replaceWith.length();
134 if (++count == limit) {
145 input.begin(), input.end(), std::back_inserter(output),
147 return std::isspace(a) != 0 && std::isspace(b) != 0;
156 if (a.size() != b.size()) {
return false; }
158 for (
size_t i = 0; i < a.size(); ++i) {
161 a.at(i) >=
'A' && a.at(i) <=
'Z' ? a.at(i) + 32 : a.at(i)
163 b.at(i) >=
'A' && b.at(i) <=
'Z' ? b.at(i) + 32 : b.at(i)
Definition StringUtil.hpp:13
std::vector< std::string > split(const std::string &input, const char delimiter, int64_t limit=-1)
Definition StringUtil.hpp:23
std::string getByteString(const std::string &input)
Definition StringUtil.hpp:115
void removeDuplicateWhitespace(const std::string &input, std::string &output)
Definition StringUtil.hpp:143
bool equalsIgnoreCaseAscii(const std::string &a, const std::string &b)
Definition StringUtil.hpp:155
std::vector< int > byteArrayOf(const std::string &input)
Definition StringUtil.hpp:104
void replaceAll(std::string &input, const std::string &find, const std::string &replaceWith, size_t limit=0)
Definition StringUtil.hpp:123