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
14namespace btllib {
15
25std::vector<std::string>
26split(const std::string& s, const std::string& delim);
27
36std::string
37join(const std::vector<std::string>& s, const std::string& delim);
38
45void
46ltrim(std::string& s);
47void
48ltrim(btllib::CString& s);
49
56void
57rtrim(std::string& s);
58void
59rtrim(btllib::CString& s);
60
67void
68trim(std::string& s);
69void
70trim(btllib::CString& s);
71
79bool
80startswith(std::string s, std::string prefix);
81
89bool
90endswith(std::string s, std::string suffix);
91
100std::string
101get_basename(const std::string& path);
102
111std::string
112get_dirname(const std::string& path);
113
114// This exists in C++20, but we don't support that yet
116class Barrier
117{
118
119public:
120 Barrier(const unsigned count)
121 : counter(0)
122 , counter_default(count)
123 , waiting(0)
124 {}
125
126 void wait();
127
128private:
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
Definition: bloom_filter.hpp:16
bool endswith(std::string s, std::string suffix)
std::string join(const std::vector< std::string > &s, const std::string &delim)
void trim(std::string &s)
std::string get_dirname(const std::string &path)
std::string get_basename(const std::string &path)
std::vector< std::string > split(const std::string &s, const std::string &delim)
void rtrim(std::string &s)
bool startswith(std::string s, std::string prefix)
void ltrim(std::string &s)