From 23892caf532f0e163d18025e845265c050c1a9c3 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 6 May 2021 07:37:40 -0700 Subject: [PATCH] Move more parsing to core --- include/fmt/core.h | 53 ++++++++++++++++++++++++++++++++++++++++++++ include/fmt/format.h | 53 -------------------------------------------- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index ece6c479..2ecb4db6 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -178,6 +178,14 @@ # define FMT_NORETURN #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 # if FMT_HAS_CPP14_ATTRIBUTE(deprecated) || FMT_MSC_VER >= 1900 # define FMT_DEPRECATED [[deprecated]] @@ -258,6 +266,12 @@ # define FMT_API #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. #if (FMT_HAS_INCLUDE() && \ (__cplusplus > 201402L || defined(_LIBCPP_VERSION))) || \ @@ -1913,6 +1927,45 @@ FMT_CONSTEXPR const Char* parse_align(const Char* begin, const Char* end, struct auto_id {}; +template +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(begin, to_unsigned(it - begin))); + return it; +} + +template +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. template struct width_adapter { explicit FMT_CONSTEXPR width_adapter(SpecHandler& h) : handler(h) {} diff --git a/include/fmt/format.h b/include/fmt/format.h index 628d7caf..45e8df26 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -70,12 +70,6 @@ # define FMT_NOINLINE #endif -#if FMT_GCC_VERSION -# define FMT_GCC_VISIBILITY_HIDDEN __attribute__((visibility("hidden"))) -#else -# define FMT_GCC_VISIBILITY_HIDDEN -#endif - #if FMT_MSC_VER # define FMT_MSC_DEFAULT = default #else @@ -100,14 +94,6 @@ # define FMT_FALLTHROUGH #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 # if FMT_EXCEPTIONS # if FMT_MSC_VER || FMT_NVCC @@ -2615,45 +2601,6 @@ class dynamic_specs_handler ParseContext& context_; }; -template -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(begin, to_unsigned(it - begin))); - return it; -} - -template -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 struct format_handler : detail::error_handler { basic_format_parse_context parse_context;