mirror of
https://github.com/fmtlib/fmt.git
synced 2025-08-03 12:44:49 +02:00
Move more parsing to core
This commit is contained in:
@@ -178,6 +178,14 @@
|
|||||||
# define FMT_NORETURN
|
# define FMT_NORETURN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef FMT_MAYBE_UNUSED
|
||||||
|
# if FMT_HAS_CPP17_ATTRIBUTE(maybe_unused)
|
||||||
|
# define FMT_MAYBE_UNUSED [[maybe_unused]]
|
||||||
|
# else
|
||||||
|
# define FMT_MAYBE_UNUSED
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef FMT_DEPRECATED
|
#ifndef FMT_DEPRECATED
|
||||||
# if FMT_HAS_CPP14_ATTRIBUTE(deprecated) || FMT_MSC_VER >= 1900
|
# if FMT_HAS_CPP14_ATTRIBUTE(deprecated) || FMT_MSC_VER >= 1900
|
||||||
# define FMT_DEPRECATED [[deprecated]]
|
# define FMT_DEPRECATED [[deprecated]]
|
||||||
@@ -258,6 +266,12 @@
|
|||||||
# define FMT_API
|
# define FMT_API
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if FMT_GCC_VERSION
|
||||||
|
# define FMT_GCC_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
|
||||||
|
#else
|
||||||
|
# define FMT_GCC_VISIBILITY_HIDDEN
|
||||||
|
#endif
|
||||||
|
|
||||||
// libc++ supports string_view in pre-c++17.
|
// libc++ supports string_view in pre-c++17.
|
||||||
#if (FMT_HAS_INCLUDE(<string_view>) && \
|
#if (FMT_HAS_INCLUDE(<string_view>) && \
|
||||||
(__cplusplus > 201402L || defined(_LIBCPP_VERSION))) || \
|
(__cplusplus > 201402L || defined(_LIBCPP_VERSION))) || \
|
||||||
@@ -1913,6 +1927,45 @@ FMT_CONSTEXPR const Char* parse_align(const Char* begin, const Char* end,
|
|||||||
|
|
||||||
struct auto_id {};
|
struct auto_id {};
|
||||||
|
|
||||||
|
template <typename Char, typename IDHandler>
|
||||||
|
FMT_CONSTEXPR const Char* do_parse_arg_id(const Char* begin, const Char* end,
|
||||||
|
IDHandler&& handler) {
|
||||||
|
FMT_ASSERT(begin != end, "");
|
||||||
|
Char c = *begin;
|
||||||
|
if (c >= '0' && c <= '9') {
|
||||||
|
int index = 0;
|
||||||
|
if (c != '0')
|
||||||
|
index = parse_nonnegative_int(begin, end, handler);
|
||||||
|
else
|
||||||
|
++begin;
|
||||||
|
if (begin == end || (*begin != '}' && *begin != ':'))
|
||||||
|
handler.on_error("invalid format string");
|
||||||
|
else
|
||||||
|
handler(index);
|
||||||
|
return begin;
|
||||||
|
}
|
||||||
|
if (!is_name_start(c)) {
|
||||||
|
handler.on_error("invalid format string");
|
||||||
|
return begin;
|
||||||
|
}
|
||||||
|
auto it = begin;
|
||||||
|
do {
|
||||||
|
++it;
|
||||||
|
} while (it != end && (is_name_start(c = *it) || ('0' <= c && c <= '9')));
|
||||||
|
handler(basic_string_view<Char>(begin, to_unsigned(it - begin)));
|
||||||
|
return it;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Char, typename IDHandler>
|
||||||
|
FMT_CONSTEXPR_DECL FMT_INLINE const Char* parse_arg_id(const Char* begin,
|
||||||
|
const Char* end,
|
||||||
|
IDHandler&& handler) {
|
||||||
|
Char c = *begin;
|
||||||
|
if (c != '}' && c != ':') return do_parse_arg_id(begin, end, handler);
|
||||||
|
handler();
|
||||||
|
return begin;
|
||||||
|
}
|
||||||
|
|
||||||
// Adapts SpecHandler to IDHandler API for dynamic width.
|
// Adapts SpecHandler to IDHandler API for dynamic width.
|
||||||
template <typename SpecHandler, typename Char> struct width_adapter {
|
template <typename SpecHandler, typename Char> struct width_adapter {
|
||||||
explicit FMT_CONSTEXPR width_adapter(SpecHandler& h) : handler(h) {}
|
explicit FMT_CONSTEXPR width_adapter(SpecHandler& h) : handler(h) {}
|
||||||
|
@@ -70,12 +70,6 @@
|
|||||||
# define FMT_NOINLINE
|
# define FMT_NOINLINE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if FMT_GCC_VERSION
|
|
||||||
# define FMT_GCC_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
|
|
||||||
#else
|
|
||||||
# define FMT_GCC_VISIBILITY_HIDDEN
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if FMT_MSC_VER
|
#if FMT_MSC_VER
|
||||||
# define FMT_MSC_DEFAULT = default
|
# define FMT_MSC_DEFAULT = default
|
||||||
#else
|
#else
|
||||||
@@ -100,14 +94,6 @@
|
|||||||
# define FMT_FALLTHROUGH
|
# define FMT_FALLTHROUGH
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FMT_MAYBE_UNUSED
|
|
||||||
# if FMT_HAS_CPP17_ATTRIBUTE(maybe_unused)
|
|
||||||
# define FMT_MAYBE_UNUSED [[maybe_unused]]
|
|
||||||
# else
|
|
||||||
# define FMT_MAYBE_UNUSED
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef FMT_THROW
|
#ifndef FMT_THROW
|
||||||
# if FMT_EXCEPTIONS
|
# if FMT_EXCEPTIONS
|
||||||
# if FMT_MSC_VER || FMT_NVCC
|
# if FMT_MSC_VER || FMT_NVCC
|
||||||
@@ -2615,45 +2601,6 @@ class dynamic_specs_handler
|
|||||||
ParseContext& context_;
|
ParseContext& context_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Char, typename IDHandler>
|
|
||||||
FMT_CONSTEXPR const Char* do_parse_arg_id(const Char* begin, const Char* end,
|
|
||||||
IDHandler&& handler) {
|
|
||||||
FMT_ASSERT(begin != end, "");
|
|
||||||
Char c = *begin;
|
|
||||||
if (c >= '0' && c <= '9') {
|
|
||||||
int index = 0;
|
|
||||||
if (c != '0')
|
|
||||||
index = parse_nonnegative_int(begin, end, handler);
|
|
||||||
else
|
|
||||||
++begin;
|
|
||||||
if (begin == end || (*begin != '}' && *begin != ':'))
|
|
||||||
handler.on_error("invalid format string");
|
|
||||||
else
|
|
||||||
handler(index);
|
|
||||||
return begin;
|
|
||||||
}
|
|
||||||
if (!is_name_start(c)) {
|
|
||||||
handler.on_error("invalid format string");
|
|
||||||
return begin;
|
|
||||||
}
|
|
||||||
auto it = begin;
|
|
||||||
do {
|
|
||||||
++it;
|
|
||||||
} while (it != end && (is_name_start(c = *it) || ('0' <= c && c <= '9')));
|
|
||||||
handler(basic_string_view<Char>(begin, to_unsigned(it - begin)));
|
|
||||||
return it;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Char, typename IDHandler>
|
|
||||||
FMT_CONSTEXPR_DECL FMT_INLINE const Char* parse_arg_id(const Char* begin,
|
|
||||||
const Char* end,
|
|
||||||
IDHandler&& handler) {
|
|
||||||
Char c = *begin;
|
|
||||||
if (c != '}' && c != ':') return do_parse_arg_id(begin, end, handler);
|
|
||||||
handler();
|
|
||||||
return begin;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename OutputIt, typename Char, typename Context>
|
template <typename OutputIt, typename Char, typename Context>
|
||||||
struct format_handler : detail::error_handler {
|
struct format_handler : detail::error_handler {
|
||||||
basic_format_parse_context<Char> parse_context;
|
basic_format_parse_context<Char> parse_context;
|
||||||
|
Reference in New Issue
Block a user