amos 913d3c367f Add the usable task catalog and admit batch 6 tasks
All 161 task packages, including the 21 batch 6 C++17 tasks that passed
gates 1/2, are now in Git. rollout.catalog builds docs/task-catalog.{json,md}
from the task packages, a fresh trace5 calibration (128/128 PASS), every
verified controller receipt on the current task digest, documented holds
and digest-bound difficulty reviews. 123 tasks are usable (6 HARD),
5 are on hold and 33 still need a subprocess-only grader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 17:43:15 +08:00

55 lines
2.1 KiB
C++

#include "alternative_registry.h"
#include <limits>
namespace alternatives {
namespace {
bool identifier_byte(unsigned char byte) {
return (byte >= 'a' && byte <= 'z') || (byte >= 'A' && byte <= 'Z') ||
(byte >= '0' && byte <= '9') || byte == '_' || byte == '-';
}
}
bool valid_id(std::string_view value) {
if (value.empty() || value.size() > 32) return false;
for (unsigned char byte : value) if (!identifier_byte(byte)) return false;
return true;
}
bool valid_path(std::string_view value) {
if (value.size() < 2 || value.size() > 128 || value.front() != '/') return false;
std::size_t begin = 1;
for (std::size_t at = 1; at <= value.size(); ++at) {
if (at == value.size() || value[at] == '/') {
const std::string_view component = value.substr(begin, at - begin);
if (component.empty() || component == "." || component == "..") return false;
begin = at + 1;
} else {
const unsigned char byte = static_cast<unsigned char>(value[at]);
if (!identifier_byte(byte) && byte != '.' && byte != '+') return false;
}
}
return true;
}
Error parse_priority(std::string_view text, std::int32_t &output) {
output = 0;
if (text.empty() || text.size() > 11) return Error::invalid;
bool negative = false;
std::size_t at = 0;
if (text.front() == '+' || text.front() == '-') { negative = text.front() == '-'; ++at; }
if (at == text.size()) return Error::invalid;
const std::uint64_t limit = negative ? 2147483648ULL : 2147483647ULL;
std::uint64_t magnitude = 0;
for (; at < text.size(); ++at) {
const unsigned char byte = static_cast<unsigned char>(text[at]);
if (byte < '0' || byte > '9') return Error::invalid;
const std::uint64_t digit = byte - '0';
if (magnitude > (limit - digit) / 10) return Error::invalid;
magnitude = magnitude * 10 + digit;
}
if (negative && magnitude == 2147483648ULL) output = std::numeric_limits<std::int32_t>::min();
else output = negative ? -static_cast<std::int32_t>(magnitude) : static_cast<std::int32_t>(magnitude);
return Error::none;
}
}