summaryrefslogtreecommitdiff
path: root/bot/src/utils/string.hpp
blob: f46b608dc0e0a43782f450d6e19ba1de9a024ca2 (plain)
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
#pragma once

#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::string join_vector(const std::vector<std::string> &vec,
                              char delimiter);
      std::string join_vector(const std::vector<std::string> &vec);

      template <typename T>
      std::string str(T begin, T end, char delimiter) {
        std::stringstream ss;
        bool first = true;

        for (; begin != end; begin++) {
          if (!first) ss << delimiter;
          ss << *begin;
          first = false;
        }
        return ss.str();
      }

      bool string_contains_sql_injection(const std::string &input);

      std::vector<std::vector<std::string>> separate_by_length(
          const std::vector<std::string> &vector, const int &max_length);

      std::vector<std::string> separate_by_length(
          const std::string &base, const std::vector<std::string> &values,
          const std::string &prefix, const std::string &separator,
          const long long &max_length);

      std::vector<std::string> split_text_n(std::string value,
                                            const std::string &separator,
                                            const int &n);
    }
  }
}