Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
std_string.cpp
Go to the documentation of this file.
1#include "std_string.hpp"
2#include <algorithm>
3#include <cctype>
4#include <iostream>
5#include <locale>
6#include <sstream>
7#include <vector>
8
9namespace bb::detail {
10std::vector<std::string> split(const std::string& str, char delimiter)
11{
12 std::vector<std::string> result;
13 std::istringstream iss(str);
14 std::string token;
15
16 while (std::getline(iss, token, delimiter)) {
17 result.push_back(token);
18 }
19
20 return result;
21}
22
23// trim from start (in place)
24void ltrim(std::string& s)
25{
26 s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); }));
27}
28
29// trim from end (in place)
30void rtrim(std::string& s)
31{
32 s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), s.end());
33}
34
35// trim from both ends (in place)
36void trim(std::string& s)
37{
38 rtrim(s);
39 ltrim(s);
40}
41std::vector<std::string> split_and_trim(const std::string& str, char delimiter)
42{
43 std::vector<std::string> ret = split(str, delimiter);
44 for (std::string& part : ret) {
45 trim(part);
46 }
47 return ret;
48}
49} // namespace bb::detail
std::vector< std::string > split(const std::string &str, char delimiter)
void ltrim(std::string &s)
void trim(std::string &s)
std::vector< std::string > split_and_trim(const std::string &str, char delimiter)
void rtrim(std::string &s)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13