@ -2,25 +2,21 @@
# D i s t r i b u t e d u n d e r t h e M I T s o f t w a r e l i c e n s e , s e e t h e a c c o m p a n y i n g
# D i s t r i b u t e d u n d e r t h e M I T s o f t w a r e l i c e n s e , s e e t h e a c c o m p a n y i n g
# f i l e C O P Y I N G o r h t t p s : / / o p e n s o u r c e . o r g / l i c e n s e / m i t / .
# f i l e C O P Y I N G o r h t t p s : / / o p e n s o u r c e . o r g / l i c e n s e / m i t / .
cmake_path ( GET JSON_SOURCE_PATH STEM json_source_basename )
file ( READ ${ JSON_SOURCE_PATH } hex_content HEX )
file ( READ ${ JSON_SOURCE_PATH } hex_content HEX )
string ( REGEX MATCHALL "([A-Za-z0-9][A-Za-z0-9])" bytes "${hex_content}" )
string ( REGEX REPLACE "................" "\\0\n" formatted_bytes "${hex_content}" )
string ( REGEX REPLACE "[^\n][^\n]" "0x\\0, " formatted_bytes "${formatted_bytes}" )
file ( WRITE ${ HEADER_PATH } "#include <string_view>\n" )
set ( header_content
file ( APPEND ${ HEADER_PATH } "namespace json_tests{\n" )
" # i n c l u d e < s t r i n g _ v i e w >
get_filename_component ( json_source_basename ${ JSON_SOURCE_PATH } NAME_WE )
file ( APPEND ${ HEADER_PATH } "inline constexpr char detail_${json_source_basename}_bytes[]{\n" )
set ( i 0 )
n a m e s p a c e j s o n _ t e s t s {
foreach ( byte ${ bytes } )
i n l i n e c o n s t e x p r c h a r d e t a i l _ $ { j s o n _ s o u r c e _ b a s e n a m e } _ b y t e s [ ] {
math ( EXPR i "${i} + 1" )
$ { f o r m a t t e d _ b y t e s }
math ( EXPR remainder "${i} % 8" )
} ;
if ( remainder EQUAL 0 )
file ( APPEND ${ HEADER_PATH } "0x${byte},\n" )
else ( )
file ( APPEND ${ HEADER_PATH } "0x${byte}, " )
endif ( )
endforeach ( )
file ( APPEND ${ HEADER_PATH } "\n};\n" )
i n l i n e c o n s t e x p r s t d : : s t r i n g _ v i e w $ { j s o n _ s o u r c e _ b a s e n a m e } { s t d : : begin ( detail_ ${ json_source_basename } _bytes ) , s t d : : end ( detail_ ${ json_source_basename } _bytes ) } ;
file ( APPEND ${ HEADER_PATH } "inline constexpr std::string_view ${json_source_basename}{std::begin(detail_${json_source_basename}_bytes), std::end(detail_${json_source_basename}_bytes)};" )
}
file ( APPEND ${ HEADER_PATH } "\n}" )
" )
file ( WRITE ${ HEADER_PATH } "${header_content}" )