btllib

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
25std::vector<std::string>
26 split(const std::string& s, const std::string& delim);
27
36std::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
100std::string
101 get_basename(const std::string& path);
102
111std::string
112 get_dirname(const std::string& path);
113
114// This exists in C++20, but we don't support that yet
116 class Barrier
117{
118
119 public:
120 Barrier(const unsigned count)
121 : counter(0)
122 , counter_default(count)
123 , waiting(0)
124 {}
125
126 void wait();
127
128 private:
129 std::mutex m;
130 std::condition_variable cv;
131 unsigned counter;
132 unsigned counter_default;
133 unsigned waiting;
134};
136
137} // namespace btllib
138
139#endif
btllib
Definition: bloom_filter.hpp:16
btllib::endswith
bool endswith(std::string s, std::string suffix)
btllib::join
std::string join(const std::vector< std::string > &s, const std::string &delim)
btllib::trim
void trim(std::string &s)
btllib::get_dirname
std::string get_dirname(const std::string &path)
btllib::get_basename
std::string get_basename(const std::string &path)
btllib::split
std::vector< std::string > split(const std::string &s, const std::string &delim)
btllib::rtrim
void rtrim(std::string &s)
btllib::startswith
bool startswith(std::string s, std::string prefix)
btllib::ltrim
void ltrim(std::string &s)