amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
One user-space repair task per eligible HWE debug-diag / compile-deploy base
ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content
filter. Each ships a public spec with a check-to-basis table, at least two
defects with single-fix fixtures, a symptom-masking fixture and an alternative
correct implementation. Claude re-checked all 320: structure, the HWE quality
items and trace6 Docker calibration receipts against current digests
(320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120
ad-hoc family names; the next batch maps them to the canonical list.
The batch's 1,256-line progress log stays in its factory report and the
36-local branch batch15-hwe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 01:55:56 +08:00

145 lines
3.4 KiB
C++

#include "request.hpp"
#include <climits>
#include <limits>
namespace remaining {
namespace {
bool horizontal(char value)
{
return value == ' ' || value == '\t' || value == '\r';
}
bool decimal(char value)
{
return value >= '0' && value <= '9';
}
bool digits(const std::string &word, std::size_t first,
std::uint64_t limit, std::uint64_t &value)
{
if (first == word.size()) {
return false;
}
std::uint64_t result = 0;
for (std::size_t offset = first; offset < word.size(); ++offset) {
if (!decimal(word[offset])) {
return false;
}
const auto digit = static_cast<unsigned>(word[offset] - '0');
if (digit > limit || result > (limit - digit) / 10) {
return false;
}
result = result * 10 + digit;
}
value = result;
return true;
}
bool scaling(const std::string &unit, std::uint64_t &factor)
{
if (unit.empty() || unit == "ns") {
factor = 1;
return true;
}
if (unit == "us") {
factor = 1000;
return true;
}
if (unit == "ms") {
factor = 1000000;
return true;
}
if (unit == "s") {
factor = kSecond;
return true;
}
return false;
}
} // namespace
std::vector<std::string> split_words(const std::string &line)
{
std::vector<std::string> words;
std::size_t cursor = 0;
while (cursor < line.size()) {
while (cursor < line.size() && horizontal(line[cursor])) {
++cursor;
}
if (cursor == line.size()) {
break;
}
const auto begin = cursor;
while (cursor < line.size() && !horizontal(line[cursor])) {
++cursor;
}
words.push_back(line.substr(begin, cursor - begin));
}
return words;
}
bool parse_unsigned(const std::string &word, std::uint64_t &value)
{
if (word.empty()) {
return false;
}
const std::size_t first = word[0] == '+' ? 1 : 0;
return digits(word, first, std::numeric_limits<std::uint64_t>::max(), value);
}
bool parse_signed(const std::string &word, int &value)
{
if (word.empty()) {
return false;
}
std::size_t first = 0;
bool negative = false;
if (word[0] == '+' || word[0] == '-') {
negative = word[0] == '-';
first = 1;
}
std::uint64_t magnitude = 0;
const auto limit = static_cast<std::uint64_t>(INT_MAX) + (negative ? 1ULL : 0ULL);
if (!digits(word, first, limit, magnitude)) {
return false;
}
if (negative && magnitude == static_cast<std::uint64_t>(INT_MAX) + 1ULL) {
value = INT_MIN;
return true;
}
value = negative ? -static_cast<int>(magnitude) : static_cast<int>(magnitude);
return true;
}
bool parse_duration(const std::string &word, std::uint64_t &value)
{
if (word.empty()) {
return false;
}
const std::size_t first = word[0] == '+' ? 1 : 0;
auto cursor = first;
while (cursor < word.size() && decimal(word[cursor])) {
++cursor;
}
if (cursor == first) {
return false;
}
const std::string unit = word.substr(cursor);
std::uint64_t factor = 0;
if (!scaling(unit, factor)) {
return false;
}
const std::string amount = word.substr(first, cursor - first);
std::uint64_t number = 0;
if (!digits(amount, 0, kMaximumDuration / factor, number)) {
return false;
}
value = number * factor;
return true;
}
} // namespace remaining