From d1793df1eda463b10107d41785ad1d7f055ed476 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 18 May 2024 14:48:12 +0500 Subject: upd: moved the bot part to a relative subfolder --- bot/src/utils/string.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 bot/src/utils/string.cpp (limited to 'bot/src/utils/string.cpp') diff --git a/bot/src/utils/string.cpp b/bot/src/utils/string.cpp new file mode 100644 index 0000000..71c06bf --- /dev/null +++ b/bot/src/utils/string.cpp @@ -0,0 +1,66 @@ +#include "string.hpp" + +#include +#include +#include + +namespace bot { + namespace utils { + namespace string { + std::vector split_text(const std::string &text, + char delimiter) { + std::vector 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 &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 &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; + } + } + } +} -- cgit v1.2.3