#include "stream.hpp" namespace captured { namespace { bool equals_ascii(const Bytes& input, const char* expected, std::size_t length) { if (input.size() != length) { return false; } for (std::size_t index = 0; index < length; ++index) { const auto byte = static_cast(expected[index]); if (input[index] != byte) { return false; } } return true; } std::uint8_t uppercase(std::uint8_t byte) { if (byte >= static_cast('a') && byte <= static_cast('z')) { return static_cast(byte - ('a' - 'A')); } return byte; } std::uint8_t lowercase(std::uint8_t byte) { if (byte >= static_cast('A') && byte <= static_cast('Z')) { return static_cast(byte + ('a' - 'A')); } return byte; } } int parse_mode(const Bytes& text) { if (equals_ascii(text, "pass", 4)) { return 0; } if (equals_ascii(text, "upper", 5)) { return 1; } if (equals_ascii(text, "lower", 5)) { return 2; } return -22; } std::string mode_name(std::int64_t mode) { switch (mode) { case 0: return "pass"; case 1: return "upper"; case 2: return "lower"; default: return "invalid"; } } Bytes transform(const Bytes& input, std::int64_t mode) { Bytes output; output.reserve(input.size()); for (std::uint8_t byte : input) { if (mode == 1) { output.push_back(uppercase(byte)); } else if (mode == 2) { output.push_back(lowercase(byte)); } else { output.push_back(byte); } } return output; } }