jubilant-funicular
common.h
1 #ifndef UTILS_COMMON_H_INCLUDED
2 #define UTILS_COMMON_H_INCLUDED
3 
4 #include <sstream>
5 #include <vector>
6 #include <cassert>
7 
8 namespace utils {
10  extern bool starts_with(const std::string& str, const std::string& prefix);
12  extern bool ends_with(const std::string& str, const std::string& suffix);
14  extern std::string replace_all(const std::string& str, const std::string& o,
15  const std::string& n);
17  extern std::string replace_all(const std::string& str,
18  const std::vector<std::vector<std::string>>& os,
19  const std::vector<std::string>& ns);
21  extern std::string trim(const std::string& str,
22  const std::string& back_trash = " \t\n\v\f\r\0",
23  const std::string& front_trash = " \t\n\v\f\r\0");
25  extern std::vector<std::string> split(const std::string& str, char delim);
27  extern std::string read_file(const std::string_view path);
29  extern std::size_t hash_combine(std::size_t lhs, std::size_t rhs);
30 
32  template<class T>
33  std::string to_string(const T& input, std::size_t precision = 0) {
34  std::ostringstream os;
35  if (precision != 0) {
36  os.precision(precision);
37  }
38  os<<input;
39  return os.str();
40  }
41 }
42 
43 #endif // UTILS_COMMON_H_INCLUDED
nta::utils::hash_combine
std::size_t hash_combine(std::size_t lhs, std::size_t rhs)
Stolen from Boost.
Definition: utils.cpp:26
nta::utils::read_file
std::string read_file(const std::string_view path)
Reads the contents of a file into a string.
Definition: utils.cpp:23
nta::utils::trim
std::string trim(crstring str, crstring back_trash=" \t\n\v\f\r\0", crstring front_trash=" \t\n\v\f\r\0")
Removes leading and trailing whitespace.
Definition: utils.cpp:17
nta::utils::split
std::vector< std::string > split(crstring str, char delim)
Splits a string into substrings separated by delim.
Definition: utils.cpp:20
nta::utils::to_string
std::string to_string(const T &input, std::size_t precision=0)
converts input to a std::string
Definition: utils.h:36
nta::utils::replace_all
std::string replace_all(crstring str, crstring o, crstring n)
Replaces all occurences of o in str with n.
Definition: utils.cpp:11
nta::utils::starts_with
bool starts_with(crstring str, crstring prefix)
Checks if str starts with prefix.
Definition: utils.cpp:5
nta::utils::ends_with
bool ends_with(crstring str, crstring suffix)
Checks if str ends with suffix.
Definition: utils.cpp:8