26template <std::
size_t N>
35 for (std::size_t i = 0; i < N; ++i)
buf[i] =
str[i];
41 constexpr std::size_t
length()
const {
return N - 1; }
53template <detail::FixedString FormatStr>
57 static constexpr std::size_t
s_FormatLen = FormatStr.length();
65 if (FormatStr.buf[i] ==
'{' && FormatStr.buf[i + 1] ==
'}')
return i;
67 return static_cast<std::size_t
>(-1);
72 static_assert(
s_PlaceholderPos !=
static_cast<std::size_t
>(-1),
"Format string must contain a '{}' placeholder.");
96 static_assert(std::is_integral_v<T>,
"HexString only accepts integer types.");
98 constexpr char digits[] =
"0123456789ABCDEF";
101 constexpr std::size_t HexDigits =
sizeof(T) * 2;
106 using UnsignedT = std::make_unsigned_t<T>;
107 UnsignedT value =
static_cast<UnsignedT
>(context);
111 m_text[i] = FormatStr.buf[i];
115 for (std::size_t i = 0; i < HexDigits; ++i) {
116 std::size_t shift = (HexDigits - 1 - i) * 4;
133 constexpr operator std::string_view()
const noexcept {
141 lhs.append(
static_cast<std::string_view
>(rhs));
146 std::string_view lhs_view = lhs;
148 result.reserve(lhs_view.size() + rhs.size());
149 result.append(lhs_view).append(rhs);
154 return std::string(lhs) + rhs;
158 return lhs + std::string(rhs);
std::size_t m_actual_size
The actual length of the generated string.
static constexpr std::size_t get_placeholder_pos()
Finds the position of the "{}" placeholder within the format string.
friend constexpr std::string operator+(const HexString &lhs, const char *rhs)
friend constexpr std::string operator+(std::string lhs, const HexString &rhs)
static constexpr std::size_t s_PostfixLen
The length of the string postfix (after the placeholder).
const char * c_str() const noexcept
Returns a pointer to the underlying null-terminated character array.
static constexpr std::size_t s_FormatLen
The total length of the format string.
constexpr HexString(T context)
Constructs the formatted string by injecting the hex value of the context into the placeholder.
static constexpr std::size_t s_MaxHexDigits
The maximum number of hex digits (supports up to 64-bit integers).
friend constexpr std::string operator+(const char *lhs, const HexString &rhs)
friend constexpr std::string operator+(const HexString &lhs, const std::string &rhs)
static constexpr std::size_t s_PlaceholderPos
The index of the "{}" placeholder.
static constexpr std::size_t s_PrefixLen
The index of the "{}" placeholder.
char m_text[s_PrefixLen+s_MaxHexDigits+s_PostfixLen+1]
The internal buffer storing the fully formatted string.
constexpr std::size_t size() const noexcept
Returns the total size of the formatted string.
constexpr std::size_t length() const
Gets the length of the string excluding the null terminator.
constexpr FixedString(const char(&str)[N])
Constructs a FixedString from a string literal.
char buf[N]
The internal character buffer.