dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
Utility.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Vincent Leroy
2// SPDX-License-Identifier: MIT
3//
4// This file is part of dfx.
5//
6// Licensed under the MIT License. See the LICENSE file in the project root
7// for full license information.
8
9#pragma once
10
11// C++ includes
12#include <algorithm>
13#include <cstdint>
14#include <optional>
15#include <span>
16#include <string>
17#include <string_view>
18#include <vector>
19
33
34namespace dfx::Utils
35{
47 std::vector<std::string> split(std::string const & str, std::string_view sep = " ", bool skipEmpty = true, bool shouldTrim = false);
48
61 std::vector<std::string_view> splitView(std::string_view str, std::string_view sep = " ", bool skipEmpty = true, bool shouldTrim = false);
62
67 std::string toLower(std::string_view str);
68
73 std::string toUpper(std::string_view str);
74
81 std::string & ltrim(std::string & s) noexcept;
88 std::string & rtrim(std::string & s) noexcept;
95 std::string & trim(std::string & s) noexcept;
96
103 std::string_view & trimView(std::string_view & str) noexcept;
104
115 template<typename T1, typename T2>
116 bool isOneOf(T1 val, std::initializer_list<T2 const> list)
117 { return std::find(std::begin(list), std::end(list), val) != std::end(list); }
118
129 template<typename T1, typename T2>
130 bool isOneOf(T1 val, std::span<T2 const> list)
131 { return std::find(std::begin(list), std::end(list), val) != std::end(list); }
132
139 std::string formatBytes(std::uint64_t byteCount, std::size_t precision = 2);
140
150 std::optional<bool> boolFromString(std::string_view str) noexcept;
157 std::string_view boolToString(bool value) noexcept;
158
173 std::string_view strsignal(int sig) noexcept;
174} // !namespace dfx::Utils
Definition SystemConfigCommandHandler.hpp:15
std::string_view boolToString(bool value) noexcept
Convert a boolean value to a stable textual representation.
std::string & trim(std::string &s) noexcept
Trim leading and trailing whitespace from a string in-place.
std::string formatBytes(std::uint64_t byteCount, std::size_t precision=2)
Format a byte count as a human-readable string.
std::string_view & trimView(std::string_view &str) noexcept
Trim leading and trailing whitespace from a string view by adjusting its boundaries.
std::vector< std::string_view > splitView(std::string_view str, std::string_view sep=" ", bool skipEmpty=true, bool shouldTrim=false)
Split a string view into substring views separated by sep.
std::string toLower(std::string_view str)
Convert a string to lower case.
std::string & ltrim(std::string &s) noexcept
Trim leading whitespace from a string in-place.
std::string & rtrim(std::string &s) noexcept
Trim trailing whitespace from a string in-place.
std::optional< bool > boolFromString(std::string_view str) noexcept
Parse a boolean value from text.
std::string_view strsignal(int sig) noexcept
Convert a signal number to a stringified version.
std::string toUpper(std::string_view str)
Convert a string to upper case.
std::vector< std::string > split(std::string const &str, std::string_view sep=" ", bool skipEmpty=true, bool shouldTrim=false)
Split a string into substrings separated by sep.
bool isOneOf(T1 val, std::initializer_list< T2 const > list)
Test whether val is equal to one of the elements in list.
Definition Utility.hpp:116