25std::vector<char *> stringsToCharPtrs(
const Strings & ss);
28MakeError(FormatError, Error);
31template<
class... Parts>
32auto concatStrings(Parts &&... parts)
33 -> std::enable_if_t<(... && std::is_convertible_v<Parts, std::string_view>), std::string>
35 std::string_view
views[
sizeof...(parts)] = {parts...};
36 return concatStringsSep({},
views);
47 res.push_back(
"'" +
s +
"'");
56std::string chomp(std::string_view
s);
62std::string trim(std::string_view
s, std::string_view whitespace =
" \n\r\t");
68std::string replaceStrings(
70 std::string_view
from,
74std::string rewriteStrings(std::string
s,
const StringMap & rewrites);
81std::optional<N> string2Int(
const std::string_view
s);
92 char u = std::toupper(*
s.rbegin());
93 if (std::isalpha(u)) {
98 else throw UsageError(
"invalid unit specifier '%1%'", u);
102 if (
auto n = string2Int<N>(
s))
104 throw UsageError(
"'%s' is not an integer",
s);
112std::string renderSize(uint64_t
value,
bool align =
false);
118std::optional<N> string2Float(
const std::string_view
s);
128 for (
size_t i = 0;
i <
sizeof(
x); ++
i, ++
p) {
129 x |= ((T) *
p) << (
i * 8);
138bool hasPrefix(std::string_view
s, std::string_view prefix);
144bool hasSuffix(std::string_view
s, std::string_view suffix);
150std::string toLower(std::string
s);
156std::string shellEscape(
const std::string_view
s);
169void ignoreExceptionInDestructor(Verbosity lvl = lvlError);
178void ignoreExceptionExceptInterrupt(Verbosity lvl = lvlError);
186constexpr char treeLast[] =
"└───";
187constexpr char treeLine[] =
"│ ";
188constexpr char treeNull[] =
" ";
194std::string base64Encode(std::string_view
s);
199std::string base64Decode(std::string_view
s);
207std::string stripIndentation(std::string_view
s);
215std::pair<std::string_view, std::string_view> getLine(std::string_view
s);
222const typename T::mapped_type * get(
const T & map,
const typename T::key_type &
key)
224 auto i = map.find(
key);
225 if (
i == map.end())
return nullptr;
230typename T::mapped_type * get(T & map,
const typename T::key_type &
key)
232 auto i = map.find(
key);
233 if (
i == map.end())
return nullptr;
241const typename T::mapped_type &
getOr(T & map,
242 const typename T::key_type &
key,
243 const typename T::mapped_type & defaultValue)
245 auto i = map.find(
key);
246 if (
i == map.end())
return defaultValue;
257 if (
i == c.end())
return {};
258 auto v = std::move(*
i);
268std::optional<typename T::value_type>
pop(T & c)
270 if (c.empty())
return {};
271 auto v = std::move(c.front());
281template<
class C,
typename T>
282void append(C & c, std::initializer_list<T> l)
284 c.insert(c.end(), l.begin(), l.end());
301 MaintainCount(T & counter,
long delta = 1) : counter(counter), delta(delta) { counter += delta; }
302 ~MaintainCount() { counter -= delta; }
312 typename TIter =
decltype(std::begin(std::declval<T>())),
313 typename =
decltype(std::end(std::declval<T>()))>
320 constexpr bool operator != (
const iterator & other)
const {
return iter != other.iter; }
321 constexpr void operator ++ () { ++
i; ++iter; }
322 constexpr auto operator * ()
const {
return std::tie(
i, *iter); }
328 constexpr auto begin() {
return iterator{ 0, std::begin(iterable) }; }
329 constexpr auto end() {
return iterator{ 0, std::end(iterable) }; }
339template<
class... Ts>
struct overloaded : Ts... {
using Ts::operator()...; };
343std::string showBytes(uint64_t bytes);
350inline std::string operator + (
const std::string & s1, std::string_view s2)
353 s.reserve(s1.size() + s2.size());
359inline std::string operator + (std::string &&
s, std::string_view s2)
365inline std::string operator + (std::string_view s1,
const char * s2)
367 auto s2Size = strlen(s2);
369 s.reserve(s1.size() + s2Size);
371 s.append(s2, s2Size);
This file defines two main structs/classes used in nix error handling.
PosIdx end
Definition lexer.l:5814
Consider removing the empty string dropping behavior If use concatStringsSep instead std::string std::enable_if_t<(... &&std::is_convertible_v< Parts, std::string_view >), std::string > std::string_view views[sizeof...(parts)]
Definition lexer.l:2556
const T::key_type & key
Definition lexer.l:2763
auto i
Definition lexer.l:2745
return s
Definition lexer.l:459
Strings res
Definition lexer.l:2566
T x
Definition lexer.l:2648
std::shared_ptr< T > p
Definition lexer.l:1269
std::string std::string_view from
Definition lexer.l:2591
PosIdx begin
Definition lexer.l:5809
uint64_t multiplier
Definition lexer.l:2611
const T & value
Definition lexer.l:492
TIter
Definition lexer.l:2833
std::string std::string_view std::string_view to
Definition lexer.l:2592
std::optional< typename T::value_type > remove_begin(T &c)
Definition util.hh:254
constexpr auto enumerate(T &&iterable)
Definition util.hh:314
T readLittleEndian(unsigned char *p)
Definition util.hh:125
N string2IntWithUnitPrefix(std::string_view s)
Definition util.hh:88
constexpr char treeConn[]
Definition util.hh:185
const T::mapped_type & getOr(T &map, const typename T::key_type &key, const typename T::mapped_type &defaultValue)
Definition util.hh:241
Strings quoteStrings(const C &c)
Definition util.hh:43