cuSBF
Loading...
Searching...
No Matches
host_parse.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <charconv>
4#include <cstdint>
5#include <cstdlib>
6#include <string_view>
7
8namespace cusbf::detail {
9
16[[nodiscard]] inline uint64_t parse_env_mebibytes(std::string_view value) {
17 if (value.empty()) {
18 return 0;
19 }
20
22 const auto* begin = value.data();
23 const auto* end = begin + value.size();
24 const auto [ptr, ec] = std::from_chars(begin, end, mebibytes);
25 if (ec != std::errc{} || ptr == begin) {
26 return 0;
27 }
28 return mebibytes;
29}
30
32[[nodiscard]] inline std::string_view getenv_value(const char* env_name) {
33 const char* value = std::getenv(env_name);
34 if (value == nullptr || value[0] == '\0') {
35 return {};
36 }
37 return value;
38}
39
40} // namespace cusbf::detail
uint64_t parse_env_mebibytes(std::string_view value)
Parses a decimal mebibyte count from value.
consteval bool separatorPositionAlwaysEncodesInvalid(char *input, uint64_t separatorPosition, uint64_t index)
Recursively tests whether placing the separator byte at any position in an input of valid bytes alway...
Definition Alphabet.cuh:37
std::string_view getenv_value(const char *env_name)
Reads env_name via getenv, or an empty view when unset.