8#include <boost/container/small_vector.hpp>
16constexpr char treeLast[] =
"└───";
17constexpr char treeLine[] =
"│ ";
18constexpr char treeNull[] =
" ";
27std::vector<char *> stringsToCharPtrs(
const Strings & ss);
30MakeError(FormatError, Error);
36template<
class C> C tokenizeString(std::string_view s, std::string_view separators =
" \t\n\r");
47 for (
const auto & s : ss) size += sep.size() + std::string_view(s).size();
51 if (s.size() != 0) s += sep;
57template<
class ... Parts>
58auto concatStrings(Parts && ... parts)
59 -> std::enable_if_t<(... && std::is_convertible_v<Parts, std::string_view>), std::string>
61 std::string_view views[
sizeof...(parts)] = { parts... };
69template<
class C,
class F>
72 boost::container::small_vector<std::string, 64> strings;
73 strings.reserve(iterable.size());
74 for (
const auto & elem : iterable) {
75 strings.push_back(fn(elem));
89 res.push_back(
"'" + s +
"'");
98std::string chomp(std::string_view s);
104std::string trim(std::string_view s, std::string_view whitespace =
" \n\r\t");
110std::string replaceStrings(
112 std::string_view from,
113 std::string_view to);
130 std::string initials;
131 std::map<std::string, std::string> rewrites;
134 explicit Rewriter(std::map<std::string, std::string> rewrites);
136 std::string operator()(std::string s);
139inline std::string rewriteStrings(std::string s,
const StringMap & rewrites)
150std::optional<N> string2Int(
const std::string_view s);
161 char u = std::toupper(*s.rbegin());
162 if (std::isalpha(u)) {
163 if (u ==
'K') multiplier = 1ULL << 10;
164 else if (u ==
'M') multiplier = 1ULL << 20;
165 else if (u ==
'G') multiplier = 1ULL << 30;
166 else if (u ==
'T') multiplier = 1ULL << 40;
167 else throw UsageError(
"invalid unit specifier '%1%'", u);
171 if (
auto n = string2Int<N>(s))
172 return *n * multiplier;
173 throw UsageError(
"'%s' is not an integer", s);
180std::optional<N> string2Float(
const std::string_view s);
186std::string toLower(
const std::string & s);
192std::string shellEscape(
const std::string_view s);
197std::string base64Encode(std::string_view s);
198std::string base64Decode(std::string_view s);
206std::string stripIndentation(std::string_view s);
213std::pair<std::string_view, std::string_view> getLine(std::string_view s);
215std::string showBytes(uint64_t bytes);
232inline std::string operator + (
const std::string & s1, std::string_view s2)
239inline std::string operator + (std::string && s, std::string_view s2)
245inline std::string operator + (std::string_view s1,
const char * s2)
248 s.reserve(s1.size() + strlen(s2));
Definition strings.hh:128
This file defines two main structs/classes used in nix error handling.
std::string concatMapStringsSep(std::string_view separator, const C &iterable, F fn)
Definition strings.hh:70
N string2IntWithUnitPrefix(std::string_view s)
Definition strings.hh:157
std::string concatStringsSep(const std::string_view sep, const C &ss)
Definition strings.hh:43
constexpr char treeConn[]
Definition strings.hh:15
Strings quoteStrings(const C &c)
Definition strings.hh:85