TrinityCore
Loading...
Searching...
No Matches
StringFormat.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "StringFormat.h"
19#include <fmt/format.h>
20
21namespace Trinity::Impl
22{
23std::string StringVFormat(FormatStringView fmt, FormatArgs args) noexcept
24try
25{
26 return fmt::vformat(fmt, args);
27}
28catch (std::exception const& formatError)
29{
30 return fmt::format(R"(An error occurred formatting string "{}" : {})", fmt, formatError.what());
31}
32
33void StringVFormatToImpl(fmt::detail::buffer<char>& buffer, FormatStringView fmt, FormatArgs args) noexcept
34try
35{
36 fmt::detail::vformat_to(buffer, fmt, args, {});
37}
38catch (std::exception const& formatError)
39{
40 fmt::detail::vformat_to(buffer, FormatStringView(R"(An error occurred formatting string "{}" : {})"), MakeFormatArgs(fmt, formatError.what()), {});
41}
42}
43
44// explicit template instantiations
57
58template TC_COMMON_API fmt::appender fmt::detail::native_formatter<int, char, fmt::detail::type::int_type>::format<fmt::format_context>(int const&, format_context&) const;
59template TC_COMMON_API fmt::appender fmt::detail::native_formatter<unsigned, char, fmt::detail::type::uint_type>::format<fmt::format_context>(unsigned const&, format_context&) const;
60template TC_COMMON_API fmt::appender fmt::detail::native_formatter<long long, char, fmt::detail::type::long_long_type>::format<fmt::format_context>(long long const&, format_context&) const;
61template TC_COMMON_API fmt::appender fmt::detail::native_formatter<unsigned long long, char, fmt::detail::type::ulong_long_type>::format<fmt::format_context>(unsigned long long const&, format_context&) const;
62template TC_COMMON_API fmt::appender fmt::detail::native_formatter<bool, char, fmt::detail::type::bool_type>::format<fmt::format_context>(bool const&, format_context&) const;
63template TC_COMMON_API fmt::appender fmt::detail::native_formatter<char, char, fmt::detail::type::char_type>::format<fmt::format_context>(char const&, format_context&) const;
64template TC_COMMON_API fmt::appender fmt::detail::native_formatter<float, char, fmt::detail::type::float_type>::format<fmt::format_context>(float const&, format_context&) const;
65template TC_COMMON_API fmt::appender fmt::detail::native_formatter<double, char, fmt::detail::type::double_type>::format<fmt::format_context>(double const&, format_context&) const;
66template TC_COMMON_API fmt::appender fmt::detail::native_formatter<long double, char, fmt::detail::type::long_double_type>::format<fmt::format_context>(long double const&, format_context&) const;
67template TC_COMMON_API fmt::appender fmt::detail::native_formatter<char const*, char, fmt::detail::type::cstring_type>::format<fmt::format_context>(char const* const&, format_context&) const;
68template TC_COMMON_API fmt::appender fmt::detail::native_formatter<void const*, char, fmt::detail::type::pointer_type>::format<fmt::format_context>(void const* const&, format_context &) const;
69template TC_COMMON_API fmt::appender fmt::detail::native_formatter<fmt::string_view, char, fmt::detail::type::string_type>::format<fmt::format_context>(string_view const&, format_context &) const;
#define TC_COMMON_API
Definition Define.h:99
void StringVFormatToImpl(fmt::detail::buffer< char > &buffer, FormatStringView fmt, FormatArgs args) noexcept
std::string StringVFormat(FormatStringView fmt, FormatArgs args) noexcept
fmt::format_args FormatArgs
constexpr auto MakeFormatArgs(Args &&... args)
fmt::string_view FormatStringView