mirror of
https://github.com/libretro/devilutionX.git
synced 2026-11-10 02:41:39 -10:00
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`.
29 lines
527 B
C++
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
|