btllib
 All Classes Namespaces Functions Variables
util.hpp
1 
4 #ifndef BTLLIB_UTIL_HPP
5 #define BTLLIB_UTIL_HPP
6 
7 #include "btllib/cstring.hpp"
8 
9 #include <condition_variable>
10 #include <mutex>
11 #include <string>
12 #include <vector>
13 
14 namespace btllib {
15 
25 std::vector<std::string>
26 split(const std::string& s, const std::string& delim);
27 
36 std::string
37 join(const std::vector<std::string>& s, const std::string& delim);
38 
45 void
46 ltrim(std::string& s);
47 void
48 ltrim(btllib::CString& s);
49 
56 void
57 rtrim(std::string& s);
58 void
59 rtrim(btllib::CString& s);
60 
67 void
68 trim(std::string& s);
69 void
70 trim(btllib::CString& s);
71 
79 bool
80 startswith(std::string s, std::string prefix);
81 
89 bool
90 endswith(std::string s, std::string suffix);
91 
100 std::string
101 get_basename(const std::string& path);
102 
111 std::string
112 get_dirname(const std::string& path);
113 
125 double
126 calc_phred_avg(const std::string& qual, size_t start_pos = 0, size_t len = 0);
127 
128 // This exists in C++20, but we don't support that yet
130 class Barrier
131 {
132 
133 public:
134  Barrier(const unsigned count)
135  : counter_default(count)
136  {
137  }
138 
139  void wait();
140 
141 private:
142  std::mutex m;
143  std::condition_variable cv;
144  unsigned counter{ 0 };
145  unsigned counter_default;
146  unsigned waiting{ 0 };
147 };
149 
150 } // namespace btllib
151 
152 #endif
std::vector< std::string > split(const std::string &s, const std::string &delim)
void rtrim(std::string &s)
std::string join(const std::vector< std::string > &s, const std::string &delim)
bool startswith(std::string s, std::string prefix)
bool endswith(std::string s, std::string suffix)
std::string get_dirname(const std::string &path)
double calc_phred_avg(const std::string &qual, size_t start_pos=0, size_t len=0)
std::string get_basename(const std::string &path)
void trim(std::string &s)
void ltrim(std::string &s)