1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#include "string.hpp"
#include <sstream>
#include <string>
#include <vector>
namespace bot {
namespace utils {
namespace string {
std::vector<std::string> split_text(const std::string &text,
char delimiter) {
std::vector<std::string> parts;
std::istringstream iss(text);
std::string part;
while (std::getline(iss, part, delimiter)) {
parts.push_back(part);
}
return parts;
}
std::string join_vector(const std::vector<std::string> &vec,
char delimiter) {
if (vec.empty()) {
return "";
}
std::string str;
for (auto i = vec.begin(); i != vec.end() - 1; i++) {
str += *i + delimiter;
}
str += vec[vec.size() - 1];
return str;
}
std::string join_vector(const std::vector<std::string> &vec) {
std::string str;
for (const auto &e : vec) {
str += e;
}
return str;
}
bool string_contains_sql_injection(const std::string &input) {
std::string forbidden_strings[] = {";", "--", "'", "\"",
"/*", "*/", "xp_", "exec",
"sp_", "insert", "select", "delete"};
for (const auto &str : forbidden_strings) {
if (input.find(str) != std::string::npos) {
return true;
}
}
return false;
}
std::vector<std::vector<std::string>> separate_by_length(
const std::vector<std::string> &vector, const int &max_length) {
std::vector<std::vector<std::string>> output;
std::vector<std::string> active;
int length = 0;
for (const std::string &str : vector) {
length += str.length();
if (length >= max_length) {
output.push_back(active);
active = {str};
} else {
active.push_back(str);
}
}
if (!active.empty()) output.push_back(active);
return output;
}
}
}
}
|