19template <std::
size_t N>
28 for (std::size_t i = 0; i < N; ++i)
buf[i] =
str[i];
34 constexpr std::size_t
length()
const {
return N - 1; }
46template <FixedString FormatStr, const
char* Digits>
50 static constexpr std::size_t
s_FormatLen = FormatStr.length();
57 if (FormatStr.buf[i] ==
'{' && FormatStr.buf[i + 1] ==
'}')
return i;
59 return static_cast<std::size_t
>(-1);
64 static_assert(
s_PlaceholderPos !=
static_cast<std::size_t
>(-1),
"Format string must contain a '{}' placeholder.");
85 static_assert(std::is_integral_v<T>,
"HexString only accepts integer types.");
87 constexpr std::size_t HexDigits =
sizeof(T) * 2;
91 using UnsignedT = std::make_unsigned_t<T>;
92 UnsignedT value =
static_cast<UnsignedT
>(context);
96 m_text[i] = FormatStr.buf[i];
100 for (std::size_t i = 0; i < HexDigits; ++i) {
101 const std::size_t shift = (HexDigits - 1 - i) * 4;
102 m_text[
s_PrefixLen + i] = Digits[(value >> shift) &
static_cast<UnsignedT
>(0xF)];
117 constexpr operator std::string_view()
const noexcept {
122 lhs.append(
static_cast<std::string_view
>(rhs));
127 std::string_view lhs_view = lhs;
129 result.reserve(lhs_view.size() + rhs.size());
130 result.append(lhs_view).append(rhs);
136 const std::string& rhs_l = rhs;
141 return std::string(lhs) + rhs;
144 return lhs + std::string(rhs);
A class that formats an integer as a hexadecimal string embedded within a format string.
constexpr std::size_t size() const noexcept
Returns the total size of the formatted string.
static constexpr std::size_t s_MaxHexDigits
static constexpr std::size_t get_placeholder_pos()
Finds the position of the "{}" placeholder within the format string.
friend constexpr std::string operator+(const char *lhs, const BasicHexString &rhs)
static constexpr std::size_t s_PlaceholderPos
constexpr BasicHexString(T context)
Constructs the formatted string by injecting the hex value of the context into the placeholder.
static constexpr std::size_t s_PrefixLen
friend constexpr std::string operator+(std::string lhs, const BasicHexString &rhs)
static constexpr std::size_t s_FormatLen
std::size_t m_actual_size
static constexpr std::size_t s_PostfixLen
friend constexpr std::string operator+(const BasicHexString &lhs, std::string &&rhs)
char m_text[s_PrefixLen+s_MaxHexDigits+s_PostfixLen+1]
friend constexpr std::string operator+(const BasicHexString &lhs, const char *rhs)
const char * c_str() const noexcept
Returns a pointer to the underlying null-terminated character array.
friend constexpr std::string operator+(const BasicHexString &lhs, const std::string &rhs)
constexpr char LowerHexDigits[]
constexpr char UpperHexDigits[]
detail::BasicHexString< FormatStr, detail::LowerHexDigits > hexstring
detail::BasicHexString< FormatStr, detail::UpperHexDigits > HexString
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.