33 #include <boost/algorithm/string/find.hpp> 37 std::string
toString(
double val,
int precision) {
38 std::ostringstream ss;
39 ss.precision(precision);
40 ss << std::fixed << val;
44 std::vector<std::string>
split(
const std::string &text,
char sep) {
49 std::vector<std::string> tokens;
52 while ((end = text.find(sep, start)) != std::string::npos) {
54 tokens.push_back(text.substr(start, end - start));
59 auto token = text.substr(start);
61 tokens.push_back(text.substr(start));
67 bool contains(
const std::string& text,
const std::string& substr,
bool case_insensitive) {
72 if (case_insensitive) {
73 auto it = std::search(
74 text.begin(), text.end(),
75 substr.begin(), substr.end(),
76 [](
char ch1,
char ch2) {
return std::toupper(ch1) == std::toupper(ch2); }
78 return it != text.end();
81 return text.find(substr) != std::string::npos;
85 std::vector<size_t>
find(
const std::string& text,
const std::string& substr,
bool case_insensitive) {
90 std::vector<size_t> indices;
92 if (case_insensitive) {
93 auto it = std::search(
94 text.begin(), text.end(),
95 substr.begin(), substr.end(),
96 [](
char ch1,
char ch2) {
return std::toupper(ch1) == std::toupper(ch2); }
99 while (it != text.end()) {
100 size_t index = std::distance(text.begin(), it);
101 indices.push_back(index);
103 text.begin() + index + 1, text.end(),
104 substr.begin(), substr.end(),
105 [](
char ch1,
char ch2) {
return std::toupper(ch1) == std::toupper(ch2); }
110 size_t loc = text.find(substr, 0);
111 while (loc != std::string::npos) {
112 indices.push_back(loc);
113 loc = text.find(substr, loc + 1);
126 FILE* pipe = popen(
"xclip -sel clip",
"w");
130 fwrite(text.data(),
sizeof(char), text.size(), pipe);
std::vector< size_t > find(const std::string &text, const std::string &substr, bool case_insensitive)
std::vector< std::string > split(const std::string &text, char sep)
std::string toString(double val, int precision)
bool contains(const std::string &text, const std::string &substr, bool case_insensitive)
void toClipboard(const std::string &text)