debugging.odin 716 B

123456789101112131415161718192021222324252627282930313233
  1. package regex_common
  2. /*
  3. (c) Copyright 2024 Feoramund <[email protected]>.
  4. Made available under Odin's BSD-3 license.
  5. List of contributors:
  6. Feoramund: Initial implementation.
  7. */
  8. @require import "core:os"
  9. import "core:io"
  10. import "core:strings"
  11. ODIN_DEBUG_REGEX :: #config(ODIN_DEBUG_REGEX, false)
  12. when ODIN_DEBUG_REGEX {
  13. debug_stream := os.stream_from_handle(os.stderr)
  14. }
  15. write_padded_hex :: proc(w: io.Writer, #any_int n, zeroes: int) {
  16. sb := strings.builder_make()
  17. defer strings.builder_destroy(&sb)
  18. sbw := strings.to_writer(&sb)
  19. io.write_int(sbw, n, 0x10)
  20. io.write_string(w, "0x")
  21. for _ in 0..<max(0, zeroes - strings.builder_len(sb)) {
  22. io.write_byte(w, '0')
  23. }
  24. io.write_int(w, n, 0x10)
  25. }