Avionics
Dropship Simulator
Extensions.h
Go to the documentation of this file.
1 #include <vector>
2 #include <string>
3 
4 namespace Library
5 {
6  class StringUtils
7  {
8  public:
9  static std::vector<std::string> Split(std::string s, std::string delimiter)
10  {
11  std::vector<std::string> elems;
12  size_t pos = 0;
13  std::string token;
14  while ((pos = s.find(delimiter)) != std::string::npos)
15  {
16  token = s.substr(0, pos);
17  elems.push_back(token);
18  s.erase(0, pos + delimiter.length());
19  }
20  elems.push_back(s);
21  return elems;
22  }
23 
24  static bool Replace(std::string& str, const std::string& from, const std::string& to)
25  {
26  size_t start_pos = str.find(from);
27  if (start_pos == std::string::npos)
28  return false;
29  str.replace(start_pos, from.length(), to);
30  return true;
31  }
32  };
33 
34  class MathUtils
35  {
36  public:
37  static float Clamp(float x, float min, float max)
38  {
39  return x < min ? min : (x > max ? max : x);
40  }
41  };
42 }
static float Clamp(float x, float min, float max)
Definition: Extensions.h:37
static std::vector< std::string > Split(std::string s, std::string delimiter)
Definition: Extensions.h:9
static bool Replace(std::string &str, const std::string &from, const std::string &to)
Definition: Extensions.h:24