File tree Expand file tree Collapse file tree 3 files changed +29
-12
lines changed
Expand file tree Collapse file tree 3 files changed +29
-12
lines changed Original file line number Diff line number Diff line change 55cmake_path (GET JSON_SOURCE_PATH STEM json_source_basename )
66
77file (READ ${JSON_SOURCE_PATH} hex_content HEX )
8- string (REGEX REPLACE "................" "\\ 0\n " formatted_bytes "${hex_content} " )
9- string (REGEX REPLACE "[^\n ][^\n ]" "'\\\\ x\\ 0'," formatted_bytes "${formatted_bytes} " )
8+ string (REGEX REPLACE "................................................................" "\\ 0\n " formatted_bytes "${hex_content} " )
9+ string (REGEX REPLACE "[^\n ][^\n ]" "\\\\ x\\ 0" formatted_bytes "${formatted_bytes} " )
10+ if (formatted_bytes STREQUAL "" )
11+ set (formatted_bytes "\"\" " )
12+ else ()
13+ string (REGEX REPLACE "([^\n ]+)" "\"\\ 1\" " formatted_bytes "${formatted_bytes} " )
14+ endif ()
1015
1116set (header_content
1217"#include <string_view>
1318
1419namespace json_tests {
15- inline constexpr char detail_${json_source_basename} _bytes[] {
20+ inline constexpr char detail_${json_source_basename} _bytes[] =
1621${formatted_bytes}
17- } ;
22+ ;
1823
19- inline constexpr std::string_view ${json_source_basename} {std::begin( detail_${json_source_basename} _bytes), std::end (detail_${json_source_basename} _bytes)};
24+ inline constexpr std::string_view ${json_source_basename} {detail_${json_source_basename} _bytes, sizeof (detail_${json_source_basename} _bytes) - 1 };
2025}
2126" )
2227file (WRITE ${HEADER_PATH} "${header_content} " )
Original file line number Diff line number Diff line change 55cmake_path (GET RAW_SOURCE_PATH STEM raw_source_basename )
66
77file (READ ${RAW_SOURCE_PATH} hex_content HEX )
8- string (REGEX REPLACE "................" "\\ 0\n " formatted_bytes "${hex_content} " )
9- string (REGEX REPLACE "[^\n ][^\n ]" "std::byte{0x\\ 0}," formatted_bytes "${formatted_bytes} " )
8+ string (REGEX REPLACE "................................................................" "\\ 0\n " formatted_bytes "${hex_content} " )
9+ string (REGEX REPLACE "[^\n ][^\n ]" "\\\\ x\\ 0" formatted_bytes "${formatted_bytes} " )
10+ if (formatted_bytes STREQUAL "" )
11+ set (formatted_bytes "\"\" " )
12+ else ()
13+ string (REGEX REPLACE "([^\n ]+)" "\"\\ 1\" " formatted_bytes "${formatted_bytes} " )
14+ endif ()
1015
1116set (header_content
12- "#include <cstddef>
13- #include <span>
17+ "#include <span.h>
1418
1519namespace ${RAW_NAMESPACE} {
16- inline constexpr std::byte detail_${raw_source_basename} _raw[] {
20+ inline constexpr auto detail_${raw_source_basename} _raw{MakeByteArray(
1721${formatted_bytes}
18- };
22+ ) };
1923
20- inline constexpr std::span ${raw_source_basename} { detail_${raw_source_basename} _raw};
24+ inline constexpr auto ${raw_source_basename} { std::span{detail_ ${raw_source_basename} _raw}.first< detail_${raw_source_basename} _raw.size() - 1>() };
2125}" )
2226file (WRITE ${HEADER_PATH} "${header_content} " )
Original file line number Diff line number Diff line change 55#ifndef BITCOIN_SPAN_H
66#define BITCOIN_SPAN_H
77
8+ #include < array>
9+ #include < bit>
810#include < cassert>
911#include < cstddef>
1012#include < span>
@@ -80,6 +82,12 @@ T& SpanPopBack(std::span<T>& span)
8082 return back;
8183}
8284
85+ template <size_t N>
86+ consteval auto MakeByteArray (const char (&bytes)[N])
87+ {
88+ return std::bit_cast<std::array<std::byte, N>>(std::to_array (bytes));
89+ }
90+
8391template <typename V>
8492auto MakeByteSpan (const V& v) noexcept
8593{
You can’t perform that action at this time.
0 commit comments