jubilant-funicular
utils.h
1 #ifndef NTA_UTILS_H_INCLUDED
2 #define NTA_UTILS_H_INCLUDED
3 
4 #include <string>
5 #include <vector>
6 
7 #include <utils/common.h>
8 
9 #include "nta/MyEngine.h"
10 
11 namespace nta {
14  namespace utils {
16  extern bool starts_with(crstring str, crstring prefix);
18  extern bool ends_with(crstring str, crstring suffix);
20  extern std::string replace_all(crstring str, crstring o, crstring n);
22  extern std::string replace_all(crstring str, const std::vector<std::vector<std::string>>& os, const std::vector<std::string>& ns);
24  extern std::string trim(crstring str, crstring back_trash = " \t\n\v\f\r\0", crstring front_trash = " \t\n\v\f\r\0");
26  extern std::vector<std::string> split(crstring str, char delim);
28  extern glm::vec2 rotate(crvec2 pt, float angle);
30  extern std::string read_file(const std::string_view path);
32  extern std::size_t hash_combine(std::size_t lhs, std::size_t rhs);
33 
35  template<class T>
36  std::string to_string(const T& input, std::size_t precision = 0) {
37  return ::utils::to_string(input, precision);
38  }
39 
41  template<class T>
42  bool in_range(T val, T min, T max) {
43  return min <= val && val <= max;
44  }
45  }
46 }
47 
48 #endif // NTA_UTILS_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
Definition: Animation2D.h:6
nta::utils::rotate
glm::vec2 rotate(crvec2 pt, float angle)
Rotates a point (about the origin) by the given angle.
Definition: utils.cpp:29
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
nta::utils::in_range
bool in_range(T val, T min, T max)
returns whether or not min <= val <= max
Definition: utils.h:42