MCPcopy Create free account
hub / github.com/ccache/ccache / parse_signed

Function parse_signed

src/ccache/util/string.cpp:361–390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359}
360
361tl::expected<int64_t, std::string>
362parse_signed(std::string_view value,
363 const std::optional<int64_t> min_value,
364 const std::optional<int64_t> max_value,
365 const std::string_view description)
366{
367 const std::string stripped_value = strip_whitespace(value);
368
369 size_t end = 0;
370 long long result = 0;
371 bool failed = false;
372 try {
373 // Note: sizeof(long long) is guaranteed to be >= sizeof(int64_t)
374 result = std::stoll(stripped_value, &end, 10);
375 } catch (std::exception&) {
376 failed = true;
377 }
378 if (failed || end != stripped_value.size()) {
379 return tl::unexpected(FMT("invalid integer: \"{}\"", stripped_value));
380 }
381
382 const int64_t min = min_value ? *min_value : INT64_MIN;
383 const int64_t max = max_value ? *max_value : INT64_MAX;
384 if (result < min || result > max) {
385 return tl::unexpected(
386 FMT("{} must be between {} and {}", description, min, max));
387 } else {
388 return result;
389 }
390}
391
392tl::expected<std::pair<uint64_t, SizeUnitPrefixType>, std::string>
393parse_size(const std::string& value)

Callers 4

mainFunction · 0.85
set_itemMethod · 0.85
parse_compression_levelFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by 1

mainFunction · 0.68