Skip to content

Commit

Permalink
Fixing a formatting bug where most default formatters would be ignored.
Browse files Browse the repository at this point in the history
  • Loading branch information
asoffer committed Sep 9, 2024
1 parent 47d176e commit b1d922e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions nth/format/common_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "nth/format/common_formatters.h"
#include "nth/meta/type.h"

namespace nth::fmt {
namespace nth {

inline word_formatter<casing::lower> NthDefaultFormatter(
nth::type_tag<decltype(nullptr)>) {
Expand Down Expand Up @@ -49,6 +49,6 @@ auto NthDefaultFormatter(nth::type_tag<I>) {
return base_formatter(10);
}

} // namespace nth::fmt
} // namespace nth

#endif // NTH_FORMAT_COMMON_DEFAULTS_H
4 changes: 2 additions & 2 deletions nth/format/common_formatters.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef NTH_IO_FORMAT_COMMON_FORMATTERS_H
#define NTH_IO_FORMAT_COMMON_FORMATTERS_H
#ifndef NTH_FORMAT_COMMON_FORMATTERS_H
#define NTH_FORMAT_COMMON_FORMATTERS_H

#include <cstdint>
#include <charconv>
Expand Down
15 changes: 13 additions & 2 deletions nth/format/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,20 @@ struct structural_formatter {
};

template <typename F, typename T>
void NthFormat(nth::io::writer auto& w, F&, T const&) {
void NthFormat(nth::io::writer auto& w, F&, T const& t) {
char buffer[sizeof(T) * 3 + 1];
buffer[0] = '[';
constexpr std::string_view Hex = "0123456789abcdef";
char* p = buffer;
for (std::byte b : nth::bytes(t)) {
*++p = Hex[static_cast<uint8_t>(b) >> 4];
*++p = Hex[static_cast<uint8_t>(b) & 0x0f];
*++p = ' ';
}
*p = ']';

nth::io::write_text(w, std::string_view(nth::type<T>.name()));
nth::io::write_text(w, "?");
nth::io::write_text(w, std::string_view(buffer, 3 * sizeof(T) + 1));
}

} // namespace nth
Expand Down

0 comments on commit b1d922e

Please sign in to comment.