| 152 | #endif |
| 153 | |
| 154 | std::vector<std::string> LoadHexLines(const char *a_path) { |
| 155 | std::ifstream in(a_path); |
| 156 | if (!in.is_open()) { |
| 157 | FailMissingTestData(a_path); |
| 158 | } |
| 159 | std::vector<std::string> payloads; |
| 160 | std::string line; |
| 161 | while (std::getline(in, line)) { |
| 162 | if (line.empty() || line[0] == '#') { |
| 163 | continue; |
| 164 | } |
| 165 | if (line.size() % 2 != 0) { |
| 166 | continue; |
| 167 | } |
| 168 | std::string bytes; |
| 169 | bytes.reserve(line.size() / 2); |
| 170 | bool ok = true; |
| 171 | for (size_t i = 0; i < line.size(); i += 2) { |
| 172 | if (!std::isxdigit((unsigned char)line[i]) || |
| 173 | !std::isxdigit((unsigned char)line[i + 1])) { |
| 174 | ok = false; |
| 175 | break; |
| 176 | } |
| 177 | char hex[3] = {line[i], line[i + 1], '\0'}; |
| 178 | bytes.push_back((char)std::strtoul(hex, nullptr, 16)); |
| 179 | } |
| 180 | if (ok) { |
| 181 | payloads.push_back(bytes); |
| 182 | } |
| 183 | } |
| 184 | return payloads; |
| 185 | } |
| 186 | |
| 187 | bool DecodeUtf8Sequence(const std::string &a_utf8, |
| 188 | std::vector<char32_t> &a_cps) { |
no test coverage detected