util.hpp
#ifndef BTLLIB_UTIL_HPP
#define BTLLIB_UTIL_HPP
#include "btllib/cstring.hpp"
#include <condition_variable>
#include <mutex>
#include <string>
#include <vector>
namespace btllib {
std::vector<std::string>
split(const std::string& s, const std::string& delim);
std::string
join(const std::vector<std::string>& s, const std::string& delim);
void
ltrim(std::string& s);
void
ltrim(btllib::CString& s);
void
rtrim(std::string& s);
void
rtrim(btllib::CString& s);
void
trim(std::string& s);
void
trim(btllib::CString& s);
bool
startswith(std::string s, std::string prefix);
bool
endswith(std::string s, std::string suffix);
std::string
get_basename(const std::string& path);
std::string
get_dirname(const std::string& path);
// This exists in C++20, but we don't support that yet
class Barrier
{
public:
Barrier(const unsigned count)
: counter(0)
, counter_default(count)
, waiting(0)
{}
void wait();
private:
std::mutex m;
std::condition_variable cv;
unsigned counter;
unsigned counter_default;
unsigned waiting;
};
} // namespace btllib
#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)