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

79 lines
2.0 KiB
C++

#ifndef UNIT_SPECIFIERS_H
#define UNIT_SPECIFIERS_H
#include <cstddef>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
namespace unit_specifiers {
enum class Error { none = 0, invalid = 1 };
enum class Mode { escape = 0, unescape = 1 };
enum class Phase { open = 0, invalid = 1, finished = 2 };
enum class PieceKind {
literal = 0,
entire_unit = 1,
prefix = 2,
instance = 3,
decoded_instance = 4,
percent = 5
};
struct ServiceName {
std::string unit;
std::string prefix;
std::string instance;
std::string decoded_prefix;
std::string decoded_instance;
bool instantiated = false;
};
struct Piece {
PieceKind kind = PieceKind::literal;
std::string text;
};
struct Program {
std::vector<Piece> pieces;
};
struct StreamView {
Mode mode = Mode::escape;
Phase phase = Phase::open;
std::size_t capacity = 16384;
std::size_t input_bytes = 0;
std::size_t utf8_pending = 0;
std::size_t escape_pending = 0;
std::string result;
};
// UTF-8 validity has no implicit locale or file-system dependency.
bool valid_utf8(std::string_view bytes);
Error escape(std::string_view text, std::string& output);
Error unescape(std::string_view encoded, std::string& output);
Error parse_unit(std::string_view unit, ServiceName& output);
Error compile_template(std::string_view text, Program& output);
Error render(const Program& program, std::string_view unit,
std::size_t capacity, std::string& output);
Error expand(std::string_view text, std::string_view unit,
std::size_t capacity, std::string& output);
class Stream {
public:
Stream();
~Stream();
Stream(const Stream&) = delete;
Stream& operator=(const Stream&) = delete;
Stream(Stream&&) = delete;
Stream& operator=(Stream&&) = delete;
Error reset(Mode mode, std::size_t capacity);
Error feed(std::string_view chunk);
Error finish();
StreamView view() const;
private:
struct Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace unit_specifiers
#endif