您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from pathlib import Path
  2. import gzip
  3. ROOT = Path(__file__).absolute().parent.parent
  4. c2_header = ROOT / 'res/catch2.hpp'
  5. buf = c2_header.read_bytes()
  6. compr = gzip.compress(buf, compresslevel=9)
  7. chars = ', '.join(f"'\\x{b:02x}'" for b in compr)
  8. def oct_encode_one(b: int) -> str:
  9. if b >= 33 and b <= 126:
  10. c = chr(b)
  11. if c in ('"', '\\'):
  12. return '\\' + c
  13. return c
  14. else:
  15. return f'\\{oct(b)[2:]:>03}'
  16. def oct_encode(b: bytes) -> str:
  17. return ''.join(oct_encode_one(byt) for byt in b)
  18. bufs = []
  19. while compr:
  20. head = compr[:2000]
  21. compr = compr[len(head):]
  22. octl = oct_encode(head)
  23. bufs.append(f'"{octl}"_buf')
  24. bufs_arr = ',\n '.join(bufs)
  25. c2_embedded = ROOT / 'src/dds/catch2_embedded.generated.cpp'
  26. c2_embedded.write_text(f'''
  27. #include "./catch2_embedded.hpp"
  28. #include <neo/gzip_io.hpp>
  29. #include <neo/string_io.hpp>
  30. using namespace neo::literals;
  31. namespace dds::detail {{
  32. static const neo::const_buffer catch2_gzip_bufs[] = {{
  33. {bufs_arr}
  34. }};
  35. }}
  36. std::string_view dds::detail::catch2_embedded_single_header_str() noexcept {{
  37. static const std::string decompressed = [] {{
  38. neo::string_dynbuf_io str;
  39. neo::gzip_decompress(str, catch2_gzip_bufs);
  40. str.shrink_uncommitted();
  41. return std::move(str.string());
  42. }}();
  43. return decompressed;
  44. }}
  45. ''')