refactor(Core/Misc): port gossip validation, StringFormat APIs, and spell attribute naming from TC (#24789)

Co-authored-by: Rochet2 <tqbattlenet@gmail.com>
Co-authored-by: Shauren <shauren.trinity@gmail.com>
Co-authored-by: tobmaps <spambot42@yandex.ru>
This commit is contained in:
Francesco Borzì
2026-03-11 00:50:32 +01:00
committed by GitHub
parent 47e6aed9a7
commit 6ffe41dd59
8 changed files with 67 additions and 10 deletions

View File

@@ -29,6 +29,16 @@ namespace Acore
template<typename... Args>
using FormatString = fmt::format_string<Args...>;
using FormatStringView = fmt::string_view;
using FormatArgs = fmt::format_args;
template<typename... Args>
constexpr auto MakeFormatArgs(Args&&... args)
{
return fmt::make_format_args(args...);
}
/// Default AC string format function.
template<typename... Args>
inline std::string StringFormat(FormatString<Args...> fmt, Args&&... args)
@@ -43,6 +53,47 @@ namespace Acore
}
}
/// Format directly to an output iterator.
template<typename OutputIt, typename... Args>
inline OutputIt StringFormatTo(OutputIt out, FormatString<Args...> fmt, Args&&... args)
{
try
{
return fmt::format_to(out, fmt, std::forward<Args>(args)...);
}
catch (std::exception const& e)
{
return fmt::format_to(out, "Wrong format occurred ({}). Fmt string: '{}'", e.what(), fmt.get());
}
}
/// Format with pre-built format args.
inline std::string StringVFormat(FormatStringView fmt, FormatArgs args)
{
try
{
return fmt::vformat(fmt, args);
}
catch (std::exception const& e)
{
return fmt::format("Wrong format occurred ({}). Fmt string: '{}'", e.what(), fmt);
}
}
/// Format with pre-built format args directly to an output iterator.
template<typename OutputIt>
inline OutputIt StringVFormatTo(OutputIt out, FormatStringView fmt, FormatArgs args)
{
try
{
return fmt::vformat_to(out, fmt, args);
}
catch (std::exception const& e)
{
return fmt::format_to(out, "Wrong format occurred ({}). Fmt string: '{}'", e.what(), fmt);
}
}
/// Returns true if the given char pointer is null.
inline bool IsFormatEmptyOrNull(char const* fmt)
{