![]() |
Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
|
#include "nix/util/types.hh"#include "nix/util/error.hh"#include "nix/util/strings.hh"#include <set>#include <bit>#include <optional>#include <ranges>#include <concepts>Go to the source code of this file.
Classes | |
| struct | nix::MaintainCount< T > |
| struct | nix::overloaded< Ts > |
Macros | |
| #define | NIX_DELETE_STRING2INT_OVERLOAD(T) |
| #define | NIX_UTIL_SIZE_UNITS |
| #define | NIX_UTIL_DEFINE_SIZE_UNIT(name, suffix) |
| #define | NIX_UTIL_DEFINE_SIZE_UNIT(name, suffix) |
| #define | NIX_INCOMPLETE_SWITCH_BEGIN _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wswitch-enum\"") |
| #define | NIX_INCOMPLETE_SWITCH_END _Pragma("GCC diagnostic pop") |
Enumerations | |
| enum class | SizeUnit { NIX_UTIL_SIZE_UNITS } |
Functions | |
| void | nix::initLibUtil () |
| std::vector< char * > | nix::stringsToCharPtrs (const Strings &ss) |
| nix::MakeError (FormatError, Error) | |
| template<class... Parts> | |
| auto | nix::concatStrings (Parts &&... parts) -> std::enable_if_t<(... &&std::is_convertible_v< Parts, std::string_view >), std::string > |
| std::string | nix::quoteString (std::string_view s, char quote='\'') |
| template<class C> | |
| Strings | nix::quoteStrings (const C &c, char quote='\'') |
| std::string | nix::chomp (std::string_view s) |
| std::string | nix::trim (std::string_view s, std::string_view whitespace=" \n\r\t") |
| std::string | nix::replaceStrings (std::string s, std::string_view from, std::string_view to) |
| std::string | nix::rewriteStrings (std::string s, const StringMap &rewrites, std::set< uint64_t > *matches=nullptr, uint64_t offsetShift=0) |
| template<std::integral N> | |
| std::optional< N > | nix::string2Int (const std::string_view s) |
| template<class N> | |
| N | nix::string2IntWithUnitPrefix (std::string_view s) |
| SizeUnit | nix::getSizeUnit (int64_t value) |
| std::optional< SizeUnit > | nix::getCommonSizeUnit (std::initializer_list< int64_t > values) |
| std::string | nix::renderSizeWithoutUnit (int64_t value, SizeUnit unit, bool align=false) |
| char | nix::getSizeUnitSuffix (SizeUnit unit) |
| std::string | nix::renderSize (int64_t value, bool align=false) |
| template<class N> | |
| std::optional< N > | nix::string2Float (const std::string_view s) |
| template<typename T> requires std::is_unsigned_v<T> && (sizeof(T) > 1) | |
| T | nix::readLittleEndian (unsigned char *p) |
| template<typename T> requires std::is_unsigned_v<T> && (sizeof(T) > 1) | |
| void | nix::writeBigEndian (unsigned char *p, T x) |
| bool | nix::hasPrefix (std::string_view s, std::string_view prefix) |
| bool | nix::hasSuffix (std::string_view s, std::string_view suffix) |
| std::string | nix::toLower (std::string s) |
| std::string | nix::escapeShellArgAlways (const std::string_view s) |
| void | nix::ignoreExceptionInDestructor (Verbosity lvl=lvlError) |
| void | nix::ignoreExceptionExceptInterrupt (Verbosity lvl=lvlError) |
| std::string | nix::stripIndentation (std::string_view s) |
| std::pair< std::string_view, std::string_view > | nix::getLine (std::string_view s) |
| template<class T> | |
| const T * | nix::get (const std::optional< T > &opt) |
| template<class T> | |
| T * | nix::get (std::optional< T > &opt) |
| template<class T, typename K> | |
| const T::mapped_type * | nix::get (const T &map, const K &key) |
| template<class T, typename K> | |
| T::mapped_type * | nix::get (T &map, const K &key) |
| template<class T, typename K> | |
| T::mapped_type * | nix::get (T &&map, const K &key)=delete |
| template<class T> | |
| std::optional< typename T::mapped_type > | nix::getConcurrent (const T &map, const typename T::key_type &key) |
| template<class T, typename K> | |
| const T::mapped_type & | nix::getOr (T &map, const K &key, const typename T::mapped_type &defaultValue) |
| template<class T, typename K> | |
| const T::mapped_type & | nix::getOr (T &&map, const K &key, const typename T::mapped_type &defaultValue)=delete |
| template<class T> | |
| std::optional< typename T::value_type > | nix::remove_begin (T &c) |
| template<class T> | |
| std::optional< typename T::value_type > | nix::pop (T &c) |
| template<std::ranges::viewable_range R> | |
| constexpr auto | nix::enumerate (R &&range) |
| template<std::ranges::viewable_range R> requires std::ranges::sized_range<R> | |
| constexpr auto | nix::markLast (R &&range) |
| template<class... Ts> | |
| nix::overloaded (Ts...) -> overloaded< Ts... > | |
| std::string | nix::operator+ (const std::string &s1, std::string_view s2) |
| std::string | nix::operator+ (std::string &&s, std::string_view s2) |
| std::string | nix::operator+ (std::string_view s1, const char *s2) |
Variables | |
| constexpr auto | nix::sizeUnits |
| constexpr char | nix::treeConn [] = "├───" |
| constexpr char | nix::treeLast [] = "└───" |
| constexpr char | nix::treeLine [] = "│ " |
| constexpr char | nix::treeNull [] = " " |
| #define NIX_DELETE_STRING2INT_OVERLOAD | ( | T | ) |
| #define NIX_INCOMPLETE_SWITCH_BEGIN _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wswitch-enum\"") |
Allow selecting a subset of enum values.
| #define NIX_UTIL_DEFINE_SIZE_UNIT | ( | name, | |
| suffix ) |
| #define NIX_UTIL_DEFINE_SIZE_UNIT | ( | name, | |
| suffix ) |
| #define NIX_UTIL_SIZE_UNITS |
| std::string nix::chomp | ( | std::string_view | s | ) |
Remove trailing whitespace from a string.
|
constexpr |
A Rust/Python-like enumerate() iterator adapter.
| std::string nix::escapeShellArgAlways | ( | const std::string_view | s | ) |
Escape a string as a shell word.
This always adds single quotes, even if escaping is not strictly necessary. So both
| const T * nix::get | ( | const std::optional< T > & | opt | ) |
Get a pointer to the contents of a std::optional if it is set, or a null pointer otherwise.
Const version.
| const T::mapped_type * nix::get | ( | const T & | map, |
| const K & | key ) |
Get a value for the specified key from an associate container.
| T * nix::get | ( | std::optional< T > & | opt | ) |
Non-const counterpart of const T * get(const std::optional<T>). Takes a mutable reference, but returns a mutable pointer.
|
delete |
Deleted because this is use-after-free liability. Just don't pass temporaries to this overload set.
| std::optional< SizeUnit > nix::getCommonSizeUnit | ( | std::initializer_list< int64_t > | values | ) |
Returns the unit if all values would be rendered using the same unit otherwise returns std::nullopt.
| std::optional< typename T::mapped_type > nix::getConcurrent | ( | const T & | map, |
| const typename T::key_type & | key ) |
Look up a value in a boost::concurrent_flat_map.
| std::pair< std::string_view, std::string_view > nix::getLine | ( | std::string_view | s | ) |
Get the prefix of 's' up to and excluding the next line break (LF optionally preceded by CR), and the remainder following the line break.
|
delete |
Deleted because this is use-after-free liability. Just don't pass temporaries to this overload set.
| const T::mapped_type & nix::getOr | ( | T & | map, |
| const K & | key, | ||
| const typename T::mapped_type & | defaultValue ) |
Get a value for the specified key from an associate container, or a default value if the key isn't present.
| bool nix::hasPrefix | ( | std::string_view | s, |
| std::string_view | prefix ) |
| bool nix::hasSuffix | ( | std::string_view | s, |
| std::string_view | suffix ) |
| void nix::ignoreExceptionExceptInterrupt | ( | Verbosity | lvl = lvlError | ) |
Not destructor-safe. Print an error message, then ignore the exception. If the exception is an Interrupted exception, rethrow it.
This may be used in a few places where Interrupt can't happen, but that's ok.
| void nix::ignoreExceptionInDestructor | ( | Verbosity | lvl = lvlError | ) |
Exception handling in destructors: print an error message, then ignore the exception.
If you're not in a destructor, you usually want to use ignoreExceptionExceptInterrupt().
This function might also be used in callbacks whose caller may not handle exceptions, but ideally we propagate the exception using an exception_ptr in such cases. See e.g. PackBuilderContext
|
constexpr |
An iterator adapter that enumerates the elements of a range, pairing each element with a boolean indicating whether it is the last element.
|
inline |
Provide an addition operator between strings and string_views inexplicably omitted from the standard library.
| std::optional< typename T::value_type > nix::pop | ( | T & | c | ) |
Remove and return the first item from a container.
|
inline |
Add quotes around a string.
| Strings nix::quoteStrings | ( | const C & | c, |
| char | quote = '\'' ) |
Add quotes around a collection of strings.
| T nix::readLittleEndian | ( | unsigned char * | p | ) |
Convert a little-endian integer to host order.
| std::optional< typename T::value_type > nix::remove_begin | ( | T & | c | ) |
Remove and return the first item from a container.
| std::string nix::renderSize | ( | int64_t | value, |
| bool | align = false ) |
Pretty-print a byte value, e.g. 12433615056 is rendered as 11.6 GiB. If align is set, the number will be right-justified by padding with spaces on the left.
| std::string nix::replaceStrings | ( | std::string | s, |
| std::string_view | from, | ||
| std::string_view | to ) |
Replace all occurrences of a string inside another string.
| std::string nix::rewriteStrings | ( | std::string | s, |
| const StringMap & | rewrites, | ||
| std::set< uint64_t > * | matches = nullptr, | ||
| uint64_t | offsetShift = 0 ) |
Replace all occurrences of the keys in rewrites with their corresponding values. Optionally returns the positions of the matches in matches.
| std::optional< N > nix::string2Float | ( | const std::string_view | s | ) |
Parse a string into a float.
| std::optional< N > nix::string2Int | ( | const std::string_view | s | ) |
Parse a string into an integer.
| N nix::string2IntWithUnitPrefix | ( | std::string_view | s | ) |
Like string2Int(), but support an optional suffix 'K', 'M', 'G' or 'T' denoting a binary unit prefix.
| std::vector< char * > nix::stringsToCharPtrs | ( | const Strings & | ss | ) |
Convert a list of strings to a null-terminated vector of char *s. The result must not be accessed beyond the lifetime of the list of strings.
| std::string nix::stripIndentation | ( | std::string_view | s | ) |
Remove common leading whitespace from the lines in the string 's'. For example, if every line is indented by at least 3 spaces, then we remove 3 spaces from the start of every line.
| std::string nix::toLower | ( | std::string | s | ) |
Convert a string to lower case.
| std::string nix::trim | ( | std::string_view | s, |
| std::string_view | whitespace = " \n\r\t" ) |
Remove whitespace from the start and end of a string.
| void nix::writeBigEndian | ( | unsigned char * | p, |
| T | x ) |
Write the integer in big endian order to the output.
|
inlineconstexpr |
|
constexpr |
Tree formatting.