Files
devilutionX/Source/utils/str_cat.cpp
T
Gleb Mazovetskiy 197e1180b2 Add StrCat and StrAppend
Adds simple string / integer concatenation functions.

Many of the uses of `fmt::format` are simply concatenation
of a few strings and integers.

`StrCat` is an easier-to-read alternative to such uses of `fmt`.
2022-07-10 06:14:58 +02:00

29 lines
527 B
C++

#include "utils/str_cat.hpp"
#include <cstddef>
#include <fmt/compile.h>
#include <fmt/core.h>
namespace devilution {
namespace {
template <typename T>
constexpr size_t MaxDecimalDigits = 241 * sizeof(T) / 100 + 1;
} // namespace
char *BufCopy(char *out, int value)
{
return fmt::format_to(out, FMT_COMPILE("{}"), value);
}
void StrAppend(std::string &out, int value)
{
char buf[MaxDecimalDigits<int> + 1];
out.append(&buf[0], BufCopy(buf, value) - &buf[0]);
}
} // namespace devilution