mirror of
https://github.com/fmtlib/fmt.git
synced 2025-06-25 01:11:40 +02:00
Compare commits
25 Commits
10.1.0
...
esp-idf-re
Author | SHA1 | Date | |
---|---|---|---|
c43fe02f66 | |||
f5e54359df | |||
a003ab93cf | |||
9b74160817 | |||
a21690bdfa | |||
c9efd8968c | |||
e786824053 | |||
2b20d7be6f | |||
1f38ebbdb1 | |||
e418179694 | |||
0bffed8957 | |||
cc077a5e3b | |||
a992b3d1fc | |||
af1b768cc7 | |||
2a7c45b54e | |||
bd868f3a51 | |||
bbb784fb1b | |||
6c845f57e5 | |||
a379595c5f | |||
9dfde78714 | |||
e92a705bdc | |||
5a866fe852 | |||
e150ea0cc2 | |||
29ce2ff8a8 | |||
2e1362addb |
65
.github/workflows/scorecard.yml
vendored
Normal file
65
.github/workflows/scorecard.yml
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
# This workflow uses actions that are not certified by GitHub. They are provided
|
||||
# by a third-party and are governed by separate terms of service, privacy
|
||||
# policy, and support documentation.
|
||||
|
||||
name: Scorecard supply-chain security
|
||||
on:
|
||||
# For Branch-Protection check. Only the default branch is supported. See
|
||||
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
|
||||
branch_protection_rule:
|
||||
# To guarantee Maintained check is occasionally updated. See
|
||||
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
|
||||
schedule:
|
||||
- cron: '26 14 * * 5'
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
|
||||
# Declare default permissions as read only.
|
||||
permissions: read-all
|
||||
|
||||
jobs:
|
||||
analysis:
|
||||
name: Scorecard analysis
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
# Needed to upload the results to code-scanning dashboard.
|
||||
security-events: write
|
||||
# Needed to publish results and get a badge (see publish_results below).
|
||||
id-token: write
|
||||
|
||||
steps:
|
||||
- name: "Checkout code"
|
||||
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: "Run analysis"
|
||||
uses: ossf/scorecard-action@08b4669551908b1024bb425080c797723083c031 # v2.2.0
|
||||
with:
|
||||
results_file: results.sarif
|
||||
results_format: sarif
|
||||
# (Optional) "write" PAT token. Uncomment the `repo_token` line below if:
|
||||
# - you want to enable the Branch-Protection check on a *public* repository, or
|
||||
# To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat.
|
||||
# repo_token: ${{ secrets.SCORECARD_TOKEN }}
|
||||
|
||||
# Public repositories:
|
||||
# - Publish results to OpenSSF REST API for easy access by consumers
|
||||
# - Allows the repository to include the Scorecard badge.
|
||||
# - See https://github.com/ossf/scorecard-action#publishing-results.
|
||||
publish_results: true
|
||||
|
||||
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
|
||||
# format to the repository Actions tab.
|
||||
- name: "Upload artifact"
|
||||
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
|
||||
with:
|
||||
name: SARIF file
|
||||
path: results.sarif
|
||||
retention-days: 5
|
||||
|
||||
# Upload the results to GitHub's code scanning dashboard.
|
||||
- name: "Upload to code-scanning"
|
||||
uses: github/codeql-action/upload-sarif@a09933a12a80f87b87005513f0abb1494c27a716 # v2.21.4
|
||||
with:
|
||||
sarif_file: results.sarif
|
@ -1,3 +1,4 @@
|
||||
if(NOT DEFINED IDF_TARGET)
|
||||
cmake_minimum_required(VERSION 3.8...3.26)
|
||||
|
||||
# Fallback for using newer policies on CMake <3.12.
|
||||
@ -442,3 +443,12 @@ if (FMT_MASTER_PROJECT AND EXISTS ${gitignore})
|
||||
set(CPACK_RESOURCE_FILE_README ${PROJECT_SOURCE_DIR}/README.rst)
|
||||
include(CPack)
|
||||
endif ()
|
||||
else()
|
||||
idf_component_register(
|
||||
SRCS
|
||||
src/format.cc
|
||||
INCLUDE_DIRS
|
||||
include
|
||||
)
|
||||
set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 23)
|
||||
endif()
|
||||
|
@ -1,3 +1,50 @@
|
||||
10.1.1 - 2023-08-26
|
||||
-------------------
|
||||
|
||||
* Added formatters for ``std::atomic`` and ``atomic_flag``
|
||||
(`#3574 <https://github.com/fmtlib/fmt/pull/3574>`_,
|
||||
`#3594 <https://github.com/fmtlib/fmt/pull/3594>`_).
|
||||
Thanks `@wangzw (Zhanwei Wang) <https://github.com/wangzw>`_ and
|
||||
`@AlexGuteniev (Alex Guteniev) <https://github.com/AlexGuteniev>`_.
|
||||
|
||||
* Fixed an error about partial specialization of ``formatter<string>``
|
||||
after instantiation when compiled with gcc and C++20
|
||||
(`#3584 <https://github.com/fmtlib/fmt/issues/3584>`_).
|
||||
|
||||
* Fixed compilation as a C++20 module with gcc and clang
|
||||
(`#3587 <https://github.com/fmtlib/fmt/issues/3587>`_,
|
||||
`#3597 <https://github.com/fmtlib/fmt/pull/3597>`_,
|
||||
`#3605 <https://github.com/fmtlib/fmt/pull/3605>`_). Thanks
|
||||
`@MathewBensonCode (Mathew Benson) <https://github.com/MathewBensonCode>`_.
|
||||
|
||||
* Made ``fmt::to_string`` work with types that have ``format_as`` overloads
|
||||
(`#3575 <https://github.com/fmtlib/fmt/pull/3575>`_).
|
||||
Thanks `@phprus (Vladislav Shchapov) <https://github.com/phprus>`_.
|
||||
|
||||
* Made ``formatted_size`` work with integral format specifiers at compile time
|
||||
(`#3591 <https://github.com/fmtlib/fmt/pull/3591>`_).
|
||||
Thanks `@elbeno (Ben Deane) <https://github.com/elbeno>`_.
|
||||
|
||||
* Fixed a warning about the ``no_unique_address`` attribute on clang-cl
|
||||
(`#3599 <https://github.com/fmtlib/fmt/pull/3599>`_).
|
||||
Thanks `@lukester1975 <https://github.com/lukester1975>`_.
|
||||
|
||||
* Improved compatibility with the legacy GBK encoding
|
||||
(`#3598 <https://github.com/fmtlib/fmt/issues/3598>`_,
|
||||
`#3599 <https://github.com/fmtlib/fmt/pull/3599>`_).
|
||||
Thanks `@YuHuanTin <https://github.com/YuHuanTin>`_.
|
||||
|
||||
* Added OpenSSF Scorecard analysis
|
||||
(`#3530 <https://github.com/fmtlib/fmt/issues/3530>`_,
|
||||
`#3571 <https://github.com/fmtlib/fmt/pull/3571>`_).
|
||||
Thanks `@joycebrum (Joyce) <https://github.com/joycebrum>`_.
|
||||
|
||||
* Updated CI dependencies
|
||||
(`#3591 <https://github.com/fmtlib/fmt/pull/3591>`_,
|
||||
`#3592 <https://github.com/fmtlib/fmt/pull/3592>`_,
|
||||
`#3593 <https://github.com/fmtlib/fmt/pull/3593>`_,
|
||||
`#3602 <https://github.com/fmtlib/fmt/pull/3602>`_).
|
||||
|
||||
10.1.0 - 2023-08-12
|
||||
-------------------
|
||||
|
||||
@ -103,6 +150,9 @@
|
||||
Thanks `@gix (Nico Rieck) <https://github.com/gix>`_,
|
||||
`@hmbj (Hans-Martin B. Jensen) <https://github.com/hmbj>`_.
|
||||
|
||||
* Added support for the ``?`` format specifier to ``std::filesystem::path`` and
|
||||
made the default unescaped for consistency with strings.
|
||||
|
||||
* Deprecated the wide stream overload of ``printf``.
|
||||
|
||||
* Removed unused ``basic_printf_parse_context``.
|
||||
|
@ -22,6 +22,9 @@
|
||||
:alt: Ask questions at StackOverflow with the tag fmt
|
||||
:target: https://stackoverflow.com/questions/tagged/fmt
|
||||
|
||||
.. image:: https://api.securityscorecards.dev/projects/github.com/fmtlib/fmt/badge
|
||||
:target: https://securityscorecards.dev/viewer/?uri=github.com/fmtlib/fmt
|
||||
|
||||
**{fmt}** is an open-source formatting library providing a fast and safe
|
||||
alternative to C stdio and C++ iostreams.
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
import errno, os, re, sys
|
||||
from subprocess import check_call, CalledProcessError, Popen, PIPE, STDOUT
|
||||
|
||||
versions = ['1.0.0', '1.1.0', '2.0.0', '3.0.2', '4.0.0', '4.1.0', '5.0.0', '5.1.0', '5.2.0', '5.2.1', '5.3.0', '6.0.0', '6.1.0', '6.1.1', '6.1.2', '6.2.0', '6.2.1', '7.0.0', '7.0.1', '7.0.2', '7.0.3', '7.1.0', '7.1.1', '7.1.2', '7.1.3', '8.0.0', '8.0.1', '8.1.0', '8.1.1', '9.0.0', '9.1.0', '10.0.0', '10.1.0']
|
||||
versions = ['1.0.0', '1.1.0', '2.0.0', '3.0.2', '4.0.0', '4.1.0', '5.0.0', '5.1.0', '5.2.0', '5.2.1', '5.3.0', '6.0.0', '6.1.0', '6.1.1', '6.1.2', '6.2.0', '6.2.1', '7.0.0', '7.0.1', '7.0.2', '7.0.3', '7.1.0', '7.1.1', '7.1.2', '7.1.3', '8.0.0', '8.0.1', '8.1.0', '8.1.1', '9.0.0', '9.1.0', '10.0.0', '10.1.0', '10.1.1']
|
||||
|
||||
class Pip:
|
||||
def __init__(self, venv_dir):
|
||||
|
4
fmt_src.pri
Normal file
4
fmt_src.pri
Normal file
@ -0,0 +1,4 @@
|
||||
HEADERS +=
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/src/format.cc
|
@ -1420,9 +1420,8 @@ template <typename Context> struct arg_mapper {
|
||||
FMT_ENABLE_IF(
|
||||
std::is_pointer<T>::value || std::is_member_pointer<T>::value ||
|
||||
std::is_function<typename std::remove_pointer<T>::type>::value ||
|
||||
(std::is_convertible<const T&, const void*>::value &&
|
||||
!std::is_convertible<const T&, const char_type*>::value &&
|
||||
!has_formatter<T, Context>::value))>
|
||||
(std::is_array<T>::value &&
|
||||
!std::is_convertible<T, const char_type*>::value))>
|
||||
FMT_CONSTEXPR auto map(const T&) -> unformattable_pointer {
|
||||
return {};
|
||||
}
|
||||
@ -1662,7 +1661,6 @@ template <typename Context> class basic_format_arg {
|
||||
\endrst
|
||||
*/
|
||||
// DEPRECATED!
|
||||
FMT_EXPORT
|
||||
template <typename Visitor, typename Context>
|
||||
FMT_CONSTEXPR FMT_INLINE auto visit_format_arg(
|
||||
Visitor&& vis, const basic_format_arg<Context>& arg) -> decltype(vis(0)) {
|
||||
|
@ -83,7 +83,8 @@
|
||||
# if FMT_CPLUSPLUS >= 202002L
|
||||
# if FMT_HAS_CPP_ATTRIBUTE(no_unique_address)
|
||||
# define FMT_NO_UNIQUE_ADDRESS [[no_unique_address]]
|
||||
# elif FMT_MSC_VERSION >= 1929 // VS2019 v16.10 and later
|
||||
// VS2019 v16.10 and later except clang-cl (https://reviews.llvm.org/D110485)
|
||||
# elif (FMT_MSC_VERSION >= 1929) && !FMT_CLANG_VERSION
|
||||
# define FMT_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
|
||||
# endif
|
||||
# endif
|
||||
@ -368,8 +369,6 @@ class uint128_fallback {
|
||||
private:
|
||||
uint64_t lo_, hi_;
|
||||
|
||||
friend uint128_fallback umul128(uint64_t x, uint64_t y) noexcept;
|
||||
|
||||
public:
|
||||
constexpr uint128_fallback(uint64_t hi, uint64_t lo) : lo_(lo), hi_(hi) {}
|
||||
constexpr uint128_fallback(uint64_t value = 0) : lo_(value), hi_(0) {}
|
||||
@ -1038,6 +1037,7 @@ namespace detail {
|
||||
FMT_API bool write_console(std::FILE* f, string_view text);
|
||||
FMT_API void print(std::FILE*, string_view);
|
||||
} // namespace detail
|
||||
|
||||
FMT_BEGIN_EXPORT
|
||||
|
||||
// Suppress a misleading warning in older versions of clang.
|
||||
@ -1387,8 +1387,8 @@ FMT_CONSTEXPR auto format_uint(Char* buffer, UInt value, int num_digits,
|
||||
}
|
||||
|
||||
template <unsigned BASE_BITS, typename Char, typename It, typename UInt>
|
||||
inline auto format_uint(It out, UInt value, int num_digits, bool upper = false)
|
||||
-> It {
|
||||
FMT_CONSTEXPR inline auto format_uint(It out, UInt value, int num_digits,
|
||||
bool upper = false) -> It {
|
||||
if (auto ptr = to_pointer<Char>(out, to_unsigned(num_digits))) {
|
||||
format_uint<BASE_BITS>(ptr, value, num_digits, upper);
|
||||
return out;
|
||||
@ -1453,7 +1453,7 @@ template <typename WChar, typename Buffer = memory_buffer> class to_utf8 {
|
||||
++p;
|
||||
if (p == s.end() || (c & 0xfc00) != 0xd800 || (*p & 0xfc00) != 0xdc00) {
|
||||
if (policy == to_utf8_error_policy::abort) return false;
|
||||
buf.append(string_view("<EFBFBD>"));
|
||||
buf.append(string_view("\xEF\xBF\xBD"));
|
||||
--p;
|
||||
} else {
|
||||
c = (c << 10) + static_cast<uint32_t>(*p) - 0x35fdc00;
|
||||
@ -1486,9 +1486,9 @@ inline uint128_fallback umul128(uint64_t x, uint64_t y) noexcept {
|
||||
auto p = static_cast<uint128_opt>(x) * static_cast<uint128_opt>(y);
|
||||
return {static_cast<uint64_t>(p >> 64), static_cast<uint64_t>(p)};
|
||||
#elif defined(_MSC_VER) && defined(_M_X64)
|
||||
auto result = uint128_fallback();
|
||||
result.lo_ = _umul128(x, y, &result.hi_);
|
||||
return result;
|
||||
auto hi = uint64_t();
|
||||
auto lo = _umul128(x, y, &hi);
|
||||
return {hi, lo};
|
||||
#else
|
||||
const uint64_t mask = static_cast<uint64_t>(max_value<uint32_t>());
|
||||
|
||||
@ -4287,7 +4287,8 @@ auto join(Range&& range, string_view sep)
|
||||
std::string answer = fmt::to_string(42);
|
||||
\endrst
|
||||
*/
|
||||
template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
|
||||
template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value &&
|
||||
!detail::has_format_as<T>::value)>
|
||||
inline auto to_string(const T& value) -> std::string {
|
||||
auto buffer = memory_buffer();
|
||||
detail::write<char>(appender(buffer), value);
|
||||
@ -4312,6 +4313,14 @@ FMT_NODISCARD auto to_string(const basic_memory_buffer<Char, SIZE>& buf)
|
||||
return std::basic_string<Char>(buf.data(), size);
|
||||
}
|
||||
|
||||
template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value &&
|
||||
detail::has_format_as<T>::value)>
|
||||
inline auto to_string(const T& value) -> std::string {
|
||||
return to_string(format_as(value));
|
||||
}
|
||||
|
||||
FMT_END_EXPORT
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename Char>
|
||||
@ -4383,6 +4392,8 @@ void vformat_to(buffer<Char>& buf, basic_string_view<Char> fmt,
|
||||
detail::parse_format_string<false>(fmt, format_handler(out, fmt, args, loc));
|
||||
}
|
||||
|
||||
FMT_BEGIN_EXPORT
|
||||
|
||||
#ifndef FMT_HEADER_ONLY
|
||||
extern template FMT_API void vformat_to(buffer<char>&, string_view,
|
||||
typename vformat_args<>::type,
|
||||
|
@ -8,6 +8,7 @@
|
||||
#ifndef FMT_STD_H_
|
||||
#define FMT_STD_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <bitset>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
@ -435,6 +436,30 @@ struct formatter<BitRef, Char,
|
||||
}
|
||||
};
|
||||
|
||||
FMT_END_NAMESPACE
|
||||
FMT_EXPORT
|
||||
template <typename T, typename Char>
|
||||
struct formatter<std::atomic<T>, Char,
|
||||
enable_if_t<is_formattable<T, Char>::value>>
|
||||
: formatter<T, Char> {
|
||||
template <typename FormatContext>
|
||||
auto format(const std::atomic<T>& v, FormatContext& ctx) const
|
||||
-> decltype(ctx.out()) {
|
||||
return formatter<T, Char>::format(v.load(), ctx);
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef __cpp_lib_atomic_flag_test
|
||||
FMT_EXPORT
|
||||
template <typename Char>
|
||||
struct formatter<std::atomic_flag, Char>
|
||||
: formatter<bool, Char> {
|
||||
template <typename FormatContext>
|
||||
auto format(const std::atomic_flag& v, FormatContext& ctx) const
|
||||
-> decltype(ctx.out()) {
|
||||
return formatter<bool, Char>::format(v.test(), ctx);
|
||||
}
|
||||
};
|
||||
#endif // __cpp_lib_atomic_flag_test
|
||||
|
||||
FMT_END_NAMESPACE
|
||||
#endif // FMT_STD_H_
|
||||
|
@ -199,6 +199,21 @@ TEST(compile_test, format_to_n) {
|
||||
TEST(compile_test, constexpr_formatted_size) {
|
||||
FMT_CONSTEXPR20 size_t size = fmt::formatted_size(FMT_COMPILE("{}"), 42);
|
||||
EXPECT_EQ(size, 2);
|
||||
FMT_CONSTEXPR20 size_t hex_size =
|
||||
fmt::formatted_size(FMT_COMPILE("{:x}"), 15);
|
||||
EXPECT_EQ(hex_size, 1);
|
||||
FMT_CONSTEXPR20 size_t binary_size =
|
||||
fmt::formatted_size(FMT_COMPILE("{:b}"), 15);
|
||||
EXPECT_EQ(binary_size, 4);
|
||||
FMT_CONSTEXPR20 size_t padded_size =
|
||||
fmt::formatted_size(FMT_COMPILE("{:*^6}"), 42);
|
||||
EXPECT_EQ(padded_size, 6);
|
||||
FMT_CONSTEXPR20 size_t float_size =
|
||||
fmt::formatted_size(FMT_COMPILE("{:.3}"), 12.345);
|
||||
EXPECT_EQ(float_size, 4);
|
||||
FMT_CONSTEXPR20 size_t str_size =
|
||||
fmt::formatted_size(FMT_COMPILE("{:s}"), "abc");
|
||||
EXPECT_EQ(str_size, 3);
|
||||
}
|
||||
# endif
|
||||
|
||||
|
@ -2141,6 +2141,13 @@ TEST(format_test, format_as) {
|
||||
EXPECT_EQ(fmt::format("{}", test::struct_as_int()), "42");
|
||||
}
|
||||
|
||||
TEST(format_test, format_as_to_string) {
|
||||
EXPECT_EQ(fmt::to_string(test::scoped_enum_as_int()), "42");
|
||||
EXPECT_EQ(fmt::to_string(test::scoped_enum_as_string_view()), "foo");
|
||||
EXPECT_EQ(fmt::to_string(test::scoped_enum_as_string()), "foo");
|
||||
EXPECT_EQ(fmt::to_string(test::struct_as_int()), "42");
|
||||
}
|
||||
|
||||
template <typename Char, typename T> bool check_enabled_formatter() {
|
||||
static_assert(std::is_default_constructible<fmt::formatter<T, Char>>::value,
|
||||
"");
|
||||
|
@ -236,3 +236,22 @@ TEST(std_test, format_const_bit_reference) {
|
||||
const std::vector<bool> v = {true, false};
|
||||
EXPECT_EQ(fmt::format("{} {}", v[0], v[1]), "true false");
|
||||
}
|
||||
|
||||
TEST(std_test, format_atomic) {
|
||||
std::atomic<bool> b(false);
|
||||
EXPECT_EQ(fmt::format("{}", b), "false");
|
||||
|
||||
const std::atomic<bool> cb(true);
|
||||
EXPECT_EQ(fmt::format("{}", cb), "true");
|
||||
}
|
||||
|
||||
#ifdef __cpp_lib_atomic_flag_test
|
||||
TEST(std_test, format_atomic_flag) {
|
||||
std::atomic_flag f = ATOMIC_FLAG_INIT;
|
||||
(void) f.test_and_set();
|
||||
EXPECT_EQ(fmt::format("{}", f), "true");
|
||||
|
||||
const std::atomic_flag cf = ATOMIC_FLAG_INIT;
|
||||
EXPECT_EQ(fmt::format("{}", cf), "false");
|
||||
}
|
||||
#endif // __cpp_lib_atomic_flag_test
|
||||
|
Reference in New Issue
Block a user