mirror of
https://github.com/fmtlib/fmt.git
synced 2025-09-25 14:10:55 +02:00
Remove deprecated functions
This commit is contained in:
10
ChangeLog.md
10
ChangeLog.md
@@ -74,10 +74,16 @@
|
|||||||
formatters (https://github.com/fmtlib/fmt/issues/4424,
|
formatters (https://github.com/fmtlib/fmt/issues/4424,
|
||||||
https://github.com/fmtlib/fmt/pull/4434). Thanks @jeremy-rifkin.
|
https://github.com/fmtlib/fmt/pull/4434). Thanks @jeremy-rifkin.
|
||||||
|
|
||||||
- Removed deprecated `basic_format_args::parse_context_type` and
|
- Removed the deprecated `has_formatter` trait. Use `is_formattable` instead.
|
||||||
|
|
||||||
|
- Removed the deprecated `basic_format_args::parse_context_type`,
|
||||||
`basic_format_args::formatter_type` and similar aliases in context types.
|
`basic_format_args::formatter_type` and similar aliases in context types.
|
||||||
|
|
||||||
- Removed deprecated `has_formatter`. Use `is_formattable` instead.
|
- Removed the deprecated wide stream overload of `fmt::printf` and deprecated
|
||||||
|
wide overloads of `fmt::fprintf` and `fmt::sprintf`.
|
||||||
|
|
||||||
|
- Removed the deprecated wide stream overloads of `fmt::print` that take text
|
||||||
|
styles.
|
||||||
|
|
||||||
- Removed legacy `is_*char` traits.
|
- Removed legacy `is_*char` traits.
|
||||||
|
|
||||||
|
@@ -674,9 +674,9 @@ if an argument type doesn't match its format specification.
|
|||||||
|
|
||||||
::: printf(string_view, const T&...)
|
::: printf(string_view, const T&...)
|
||||||
|
|
||||||
::: fprintf(std::FILE*, const S&, const T&...)
|
::: fprintf(std::FILE*, string_view, const T&...)
|
||||||
|
|
||||||
::: sprintf(const S&, const T&...)
|
::: sprintf(string_view, const T&...)
|
||||||
|
|
||||||
<a id="xchar-api"></a>
|
<a id="xchar-api"></a>
|
||||||
## Wide Strings
|
## Wide Strings
|
||||||
|
@@ -513,19 +513,7 @@ struct time_zone {
|
|||||||
template <typename... T> auto current_zone(T...) -> time_zone* {
|
template <typename... T> auto current_zone(T...) -> time_zone* {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... T> void _tzset(T...) {}
|
|
||||||
} // namespace tz
|
} // namespace tz
|
||||||
|
|
||||||
// DEPRECATED!
|
|
||||||
inline void tzset_once() {
|
|
||||||
static bool init = []() {
|
|
||||||
using namespace tz;
|
|
||||||
_tzset();
|
|
||||||
return false;
|
|
||||||
}();
|
|
||||||
ignore_unused(init);
|
|
||||||
}
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
FMT_BEGIN_EXPORT
|
FMT_BEGIN_EXPORT
|
||||||
|
@@ -75,11 +75,6 @@ template <typename Locale> auto locale_ref::get() const -> Locale {
|
|||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
// DEPRECATED!
|
|
||||||
FMT_FUNC void assert_fail(const char* file, int line, const char* message) {
|
|
||||||
fmt::assert_fail(file, line, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
FMT_FUNC void format_error_code(detail::buffer<char>& out, int error_code,
|
FMT_FUNC void format_error_code(detail::buffer<char>& out, int error_code,
|
||||||
string_view message) noexcept {
|
string_view message) noexcept {
|
||||||
// Report error code making sure that the output fits into
|
// Report error code making sure that the output fits into
|
||||||
|
@@ -18,10 +18,6 @@
|
|||||||
FMT_BEGIN_NAMESPACE
|
FMT_BEGIN_NAMESPACE
|
||||||
FMT_BEGIN_EXPORT
|
FMT_BEGIN_EXPORT
|
||||||
|
|
||||||
template <typename T> struct printf_formatter {
|
|
||||||
printf_formatter() = delete;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Char> class basic_printf_context {
|
template <typename Char> class basic_printf_context {
|
||||||
private:
|
private:
|
||||||
basic_appender<Char> out_;
|
basic_appender<Char> out_;
|
||||||
@@ -33,8 +29,6 @@ template <typename Char> class basic_printf_context {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
using char_type = Char;
|
using char_type = Char;
|
||||||
using parse_context_type = parse_context<Char>;
|
|
||||||
template <typename T> using formatter_type = printf_formatter<T>;
|
|
||||||
enum { builtin_types = 1 };
|
enum { builtin_types = 1 };
|
||||||
|
|
||||||
/// Constructs a `printf_context` object. References to the arguments are
|
/// Constructs a `printf_context` object. References to the arguments are
|
||||||
@@ -74,7 +68,7 @@ inline auto find<false, char>(const char* first, const char* last, char value,
|
|||||||
|
|
||||||
// Checks if a value fits in int - used to avoid warnings about comparing
|
// Checks if a value fits in int - used to avoid warnings about comparing
|
||||||
// signed and unsigned integers.
|
// signed and unsigned integers.
|
||||||
template <bool IsSigned> struct int_checker {
|
template <bool IS_SIGNED> struct int_checker {
|
||||||
template <typename T> static auto fits_in_int(T value) -> bool {
|
template <typename T> static auto fits_in_int(T value) -> bool {
|
||||||
return value <= to_unsigned(max_value<int>());
|
return value <= to_unsigned(max_value<int>());
|
||||||
}
|
}
|
||||||
@@ -570,14 +564,18 @@ inline auto vsprintf(basic_string_view<Char> fmt,
|
|||||||
*
|
*
|
||||||
* std::string message = fmt::sprintf("The answer is %d", 42);
|
* std::string message = fmt::sprintf("The answer is %d", 42);
|
||||||
*/
|
*/
|
||||||
template <typename S, typename... T, typename Char = detail::char_t<S>>
|
template <typename... T>
|
||||||
inline auto sprintf(const S& fmt, const T&... args) -> std::basic_string<Char> {
|
inline auto sprintf(string_view fmt, const T&... args) -> std::string {
|
||||||
return vsprintf(detail::to_string_view(fmt),
|
return vsprintf(fmt, make_printf_args(args...));
|
||||||
fmt::make_format_args<basic_printf_context<Char>>(args...));
|
}
|
||||||
|
template <typename... T>
|
||||||
|
FMT_DEPRECATED auto sprintf(basic_string_view<wchar_t> fmt, const T&... args)
|
||||||
|
-> std::wstring {
|
||||||
|
return vsprintf(fmt, make_printf_args<wchar_t>(args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
inline auto vfprintf(std::FILE* f, basic_string_view<Char> fmt,
|
auto vfprintf(std::FILE* f, basic_string_view<Char> fmt,
|
||||||
typename vprintf_args<Char>::type args) -> int {
|
typename vprintf_args<Char>::type args) -> int {
|
||||||
auto buf = basic_memory_buffer<Char>();
|
auto buf = basic_memory_buffer<Char>();
|
||||||
detail::vprintf(buf, fmt, args);
|
detail::vprintf(buf, fmt, args);
|
||||||
@@ -595,17 +593,14 @@ inline auto vfprintf(std::FILE* f, basic_string_view<Char> fmt,
|
|||||||
*
|
*
|
||||||
* fmt::fprintf(stderr, "Don't %s!", "panic");
|
* fmt::fprintf(stderr, "Don't %s!", "panic");
|
||||||
*/
|
*/
|
||||||
template <typename S, typename... T, typename Char = detail::char_t<S>>
|
template <typename... T>
|
||||||
inline auto fprintf(std::FILE* f, const S& fmt, const T&... args) -> int {
|
inline auto fprintf(std::FILE* f, string_view fmt, const T&... args) -> int {
|
||||||
return vfprintf(f, detail::to_string_view(fmt),
|
return vfprintf(f, fmt, make_printf_args(args...));
|
||||||
make_printf_args<Char>(args...));
|
|
||||||
}
|
}
|
||||||
|
template <typename... T>
|
||||||
template <typename Char>
|
FMT_DEPRECATED auto fprintf(std::FILE* f, basic_string_view<wchar_t> fmt,
|
||||||
FMT_DEPRECATED inline auto vprintf(basic_string_view<Char> fmt,
|
const T&... args) -> int {
|
||||||
typename vprintf_args<Char>::type args)
|
return vfprintf(f, fmt, make_printf_args<wchar_t>(args...));
|
||||||
-> int {
|
|
||||||
return vfprintf(stdout, fmt, args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -620,11 +615,6 @@ template <typename... T>
|
|||||||
inline auto printf(string_view fmt, const T&... args) -> int {
|
inline auto printf(string_view fmt, const T&... args) -> int {
|
||||||
return vfprintf(stdout, fmt, make_printf_args(args...));
|
return vfprintf(stdout, fmt, make_printf_args(args...));
|
||||||
}
|
}
|
||||||
template <typename... T>
|
|
||||||
FMT_DEPRECATED inline auto printf(basic_string_view<wchar_t> fmt,
|
|
||||||
const T&... args) -> int {
|
|
||||||
return vfprintf(stdout, fmt, make_printf_args<wchar_t>(args...));
|
|
||||||
}
|
|
||||||
|
|
||||||
FMT_END_EXPORT
|
FMT_END_EXPORT
|
||||||
FMT_END_NAMESPACE
|
FMT_END_NAMESPACE
|
||||||
|
@@ -330,18 +330,6 @@ inline auto format(text_style ts, wformat_string<T...> fmt, T&&... args)
|
|||||||
return fmt::vformat(ts, fmt, fmt::make_wformat_args(args...));
|
return fmt::vformat(ts, fmt, fmt::make_wformat_args(args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... T>
|
|
||||||
FMT_DEPRECATED void print(std::FILE* f, text_style ts, wformat_string<T...> fmt,
|
|
||||||
const T&... args) {
|
|
||||||
vprint(f, ts, fmt, fmt::make_wformat_args(args...));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... T>
|
|
||||||
FMT_DEPRECATED void print(text_style ts, wformat_string<T...> fmt,
|
|
||||||
const T&... args) {
|
|
||||||
return print(stdout, ts, fmt, args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void vprint(std::wostream& os, wstring_view fmt, wformat_args args) {
|
inline void vprint(std::wostream& os, wstring_view fmt, wformat_args args) {
|
||||||
auto buffer = basic_memory_buffer<wchar_t>();
|
auto buffer = basic_memory_buffer<wchar_t>();
|
||||||
detail::vformat_to(buffer, fmt, args);
|
detail::vformat_to(buffer, fmt, args);
|
||||||
|
@@ -6,16 +6,12 @@
|
|||||||
// For the license information refer to format.h.
|
// For the license information refer to format.h.
|
||||||
|
|
||||||
#include "fmt/printf.h"
|
#include "fmt/printf.h"
|
||||||
// include <format> if possible for https://github.com/fmtlib/fmt/pull/4042
|
|
||||||
#if FMT_HAS_INCLUDE(<format>) && FMT_CPLUSPLUS > 201703L
|
|
||||||
# include <format>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "fmt/xchar.h"
|
#include "fmt/xchar.h" // DEPRECATED!
|
||||||
#include "gtest-extra.h"
|
#include "gtest-extra.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
@@ -26,27 +22,21 @@ using fmt::detail::max_value;
|
|||||||
const unsigned big_num = INT_MAX + 1u;
|
const unsigned big_num = INT_MAX + 1u;
|
||||||
|
|
||||||
// Makes format string argument positional.
|
// Makes format string argument positional.
|
||||||
static std::string make_positional(fmt::string_view format) {
|
static auto make_positional(fmt::string_view format) -> std::string {
|
||||||
std::string s(format.data(), format.size());
|
std::string s(format.data(), format.size());
|
||||||
s.replace(s.find('%'), 1, "%1$");
|
s.replace(s.find('%'), 1, "%1$");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::wstring make_positional(fmt::basic_string_view<wchar_t> format) {
|
|
||||||
std::wstring s(format.data(), format.size());
|
|
||||||
s.replace(s.find(L'%'), 1, L"%1$");
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
// A wrapper around fmt::sprintf to workaround bogus warnings about invalid
|
// A wrapper around fmt::sprintf to workaround bogus warnings about invalid
|
||||||
// format strings in MSVC.
|
// format strings in MSVC.
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
std::string test_sprintf(fmt::string_view format, const Args&... args) {
|
auto test_sprintf(fmt::string_view format, const Args&... args) -> std::string {
|
||||||
return fmt::sprintf(format, args...);
|
return fmt::sprintf(format, args...);
|
||||||
}
|
}
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
std::wstring test_sprintf(fmt::basic_string_view<wchar_t> format,
|
auto test_sprintf(fmt::basic_string_view<wchar_t> format, const Args&... args)
|
||||||
const Args&... args) {
|
-> std::wstring {
|
||||||
return fmt::sprintf(format, args...);
|
return fmt::sprintf(format, args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,10 +45,7 @@ std::wstring test_sprintf(fmt::basic_string_view<wchar_t> format,
|
|||||||
<< "format: " << format; \
|
<< "format: " << format; \
|
||||||
EXPECT_EQ(expected_output, fmt::sprintf(make_positional(format), arg))
|
EXPECT_EQ(expected_output, fmt::sprintf(make_positional(format), arg))
|
||||||
|
|
||||||
TEST(printf_test, no_args) {
|
TEST(printf_test, no_args) { EXPECT_EQ("test", test_sprintf("test")); }
|
||||||
EXPECT_EQ("test", test_sprintf("test"));
|
|
||||||
EXPECT_EQ(L"test", fmt::sprintf(L"test"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(printf_test, escape) {
|
TEST(printf_test, escape) {
|
||||||
EXPECT_EQ("%", test_sprintf("%%"));
|
EXPECT_EQ("%", test_sprintf("%%"));
|
||||||
@@ -66,11 +53,6 @@ TEST(printf_test, escape) {
|
|||||||
EXPECT_EQ("% after", test_sprintf("%% after"));
|
EXPECT_EQ("% after", test_sprintf("%% after"));
|
||||||
EXPECT_EQ("before % after", test_sprintf("before %% after"));
|
EXPECT_EQ("before % after", test_sprintf("before %% after"));
|
||||||
EXPECT_EQ("%s", test_sprintf("%%s"));
|
EXPECT_EQ("%s", test_sprintf("%%s"));
|
||||||
EXPECT_EQ(L"%", fmt::sprintf(L"%%"));
|
|
||||||
EXPECT_EQ(L"before %", fmt::sprintf(L"before %%"));
|
|
||||||
EXPECT_EQ(L"% after", fmt::sprintf(L"%% after"));
|
|
||||||
EXPECT_EQ(L"before % after", fmt::sprintf(L"before %% after"));
|
|
||||||
EXPECT_EQ(L"%s", fmt::sprintf(L"%%s"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(printf_test, positional_args) {
|
TEST(printf_test, positional_args) {
|
||||||
@@ -467,9 +449,6 @@ TEST(printf_test, char) {
|
|||||||
EXPECT_PRINTF("x", "%c", 'x');
|
EXPECT_PRINTF("x", "%c", 'x');
|
||||||
int max = max_value<int>();
|
int max = max_value<int>();
|
||||||
EXPECT_PRINTF(fmt::format("{}", static_cast<char>(max)), "%c", max);
|
EXPECT_PRINTF(fmt::format("{}", static_cast<char>(max)), "%c", max);
|
||||||
// EXPECT_PRINTF("x", "%lc", L'x');
|
|
||||||
EXPECT_PRINTF(L"x", L"%c", L'x');
|
|
||||||
EXPECT_PRINTF(fmt::format(L"{}", static_cast<wchar_t>(max)), L"%c", max);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(printf_test, string) {
|
TEST(printf_test, string) {
|
||||||
@@ -477,10 +456,6 @@ TEST(printf_test, string) {
|
|||||||
const char* null_str = nullptr;
|
const char* null_str = nullptr;
|
||||||
EXPECT_PRINTF("(null)", "%s", null_str);
|
EXPECT_PRINTF("(null)", "%s", null_str);
|
||||||
EXPECT_PRINTF(" (null)", "%10s", null_str);
|
EXPECT_PRINTF(" (null)", "%10s", null_str);
|
||||||
EXPECT_PRINTF(L"abc", L"%s", L"abc");
|
|
||||||
const wchar_t* null_wstr = nullptr;
|
|
||||||
EXPECT_PRINTF(L"(null)", L"%s", null_wstr);
|
|
||||||
EXPECT_PRINTF(L" (null)", L"%10s", null_wstr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(printf_test, pointer) {
|
TEST(printf_test, pointer) {
|
||||||
@@ -494,16 +469,6 @@ TEST(printf_test, pointer) {
|
|||||||
EXPECT_PRINTF(fmt::format("{:p}", s), "%p", s);
|
EXPECT_PRINTF(fmt::format("{:p}", s), "%p", s);
|
||||||
const char* null_str = nullptr;
|
const char* null_str = nullptr;
|
||||||
EXPECT_PRINTF("(nil)", "%p", null_str);
|
EXPECT_PRINTF("(nil)", "%p", null_str);
|
||||||
|
|
||||||
p = &n;
|
|
||||||
EXPECT_PRINTF(fmt::format(L"{}", p), L"%p", p);
|
|
||||||
p = nullptr;
|
|
||||||
EXPECT_PRINTF(L"(nil)", L"%p", p);
|
|
||||||
EXPECT_PRINTF(L" (nil)", L"%10p", p);
|
|
||||||
const wchar_t* w = L"test";
|
|
||||||
EXPECT_PRINTF(fmt::format(L"{:p}", w), L"%p", w);
|
|
||||||
const wchar_t* null_wstr = nullptr;
|
|
||||||
EXPECT_PRINTF(L"(nil)", L"%p", null_wstr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum test_enum { answer = 42 };
|
enum test_enum { answer = 42 };
|
||||||
@@ -531,10 +496,6 @@ TEST(printf_test, printf_error) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST(printf_test, wide_string) {
|
|
||||||
EXPECT_EQ(L"abc", fmt::sprintf(L"%s", L"abc"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(printf_test, vprintf) {
|
TEST(printf_test, vprintf) {
|
||||||
int n = 42;
|
int n = 42;
|
||||||
auto store = fmt::make_format_args<fmt::printf_context>(n);
|
auto store = fmt::make_format_args<fmt::printf_context>(n);
|
||||||
|
Reference in New Issue
Block a user