10#include "llvm/ADT/StringExtras.h"
19 if (ch >=
'a' && ch <=
'f')
21 if (ch >=
'A' && ch <=
'F')
23 if (ch >=
'0' && ch <=
'9')
32 m_packet.assign(packet_str.begin(), packet_str.end());
65 if (hi_nibble == -1 || lo_nibble == -1) {
69 return static_cast<uint8_t
>((hi_nibble << 4) + lo_nibble);
89 ch =
static_cast<uint8_t
>(byte);
96 const char *start =
m_packet.c_str();
97 const char *cstr = start +
m_index;
98 uint32_t result =
static_cast<uint32_t
>(::strtoul(cstr, &end, base));
100 if (end && end != cstr) {
111 const char *start =
m_packet.c_str();
112 const char *cstr = start +
m_index;
113 int32_t result =
static_cast<int32_t
>(::strtol(cstr, &end, base));
115 if (end && end != cstr) {
126 const char *start =
m_packet.c_str();
127 const char *cstr = start +
m_index;
128 uint64_t result = ::strtoull(cstr, &end, base);
130 if (end && end != cstr) {
141 const char *start =
m_packet.c_str();
142 const char *cstr = start +
m_index;
143 int64_t result = ::strtoll(cstr, &end, base);
145 if (end && end != cstr) {
154 uint32_t fail_value) {
156 uint32_t nibble_count = 0;
160 uint32_t shift_amount = 0;
163 if (nibble_count >= (
sizeof(uint32_t) * 2)) {
174 result |= (
static_cast<uint32_t
>(nibble_hi) << (shift_amount + 4));
175 result |= (
static_cast<uint32_t
>(nibble_lo) << shift_amount);
179 result |= (
static_cast<uint32_t
>(nibble_hi) << shift_amount);
187 if (nibble_count >= (
sizeof(uint32_t) * 2)) {
205 uint64_t fail_value) {
207 uint32_t nibble_count = 0;
211 uint32_t shift_amount = 0;
214 if (nibble_count >= (
sizeof(uint64_t) * 2)) {
225 result |= (
static_cast<uint64_t
>(nibble_hi) << (shift_amount + 4));
226 result |= (
static_cast<uint64_t
>(nibble_lo) << shift_amount);
230 result |= (
static_cast<uint64_t
>(nibble_hi) << shift_amount);
238 if (nibble_count >= (
sizeof(uint64_t) * 2)) {
257 if (!S.starts_with(str))
265 uint8_t fail_fill_value) {
266 size_t bytes_extracted = 0;
268 dest[0] =
GetHexU8(fail_fill_value);
272 dest = dest.drop_front();
276 ::memset(dest.data(), fail_fill_value, dest.size());
278 return bytes_extracted;
286 size_t bytes_extracted = 0;
287 while (!dest.empty()) {
291 dest[0] =
static_cast<uint8_t
>(decode);
292 dest = dest.drop_front();
295 return bytes_extracted;
308 uint32_t nibble_length) {
311 uint32_t nibble_count = 0;
312 for (
const char *pch =
Peek();
313 (nibble_count < nibble_length) && (pch !=
nullptr);
314 str.append(1,
GetHexU8(0,
false)), pch =
Peek(), nibble_count += 2) {
324 while ((ch =
GetHexU8(0,
false)) !=
'\0')
326 if (
Peek() && *
Peek() == terminator)
334 llvm::StringRef &value) {
345 llvm::StringRef a, b, c, d;
347 std::tie(a, b) = view.split(
':');
348 if (a.empty() || b.empty())
350 std::tie(c, d) = b.split(
';');
351 if (b == c && d.empty())
359 size_t bytes_consumed = d.data() - view.data();