Commit 466128de authored by Victor Zverovich's avatar Victor Zverovich

Remove unused code and refactor

parent 22e98a5b
...@@ -805,10 +805,10 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> { ...@@ -805,10 +805,10 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
auto out = std::back_inserter(buf); auto out = std::back_inserter(buf);
using range = internal::output_range<decltype(ctx.out()), Char>; using range = internal::output_range<decltype(ctx.out()), Char>;
internal::basic_writer<range> w(range(ctx.out())); internal::basic_writer<range> w(range(ctx.out()));
internal::handle_dynamic_spec<internal::width_checker>( internal::handle_dynamic_spec<internal::width_checker>(specs.width,
specs.width, width_ref, ctx, format_str.begin()); width_ref, ctx);
internal::handle_dynamic_spec<internal::precision_checker>( internal::handle_dynamic_spec<internal::precision_checker>(
precision, precision_ref, ctx, format_str.begin()); precision, precision_ref, ctx);
if (begin == end || *begin == '}') { if (begin == end || *begin == '}') {
out = internal::format_chrono_duration_value(out, d.count(), precision); out = internal::format_chrono_duration_value(out, d.count(), precision);
internal::format_chrono_duration_unit<Period>(out); internal::format_chrono_duration_unit<Period>(out);
......
This diff is collapsed.
...@@ -2556,8 +2556,7 @@ void check_format_string(S format_str) { ...@@ -2556,8 +2556,7 @@ void check_format_string(S format_str) {
template <template <typename> class Handler, typename Spec, typename Context> template <template <typename> class Handler, typename Spec, typename Context>
void handle_dynamic_spec(Spec& value, arg_ref<typename Context::char_type> ref, void handle_dynamic_spec(Spec& value, arg_ref<typename Context::char_type> ref,
Context& ctx, Context& ctx) {
const typename Context::char_type* format_str) {
switch (ref.kind) { switch (ref.kind) {
case arg_id_kind::none: case arg_id_kind::none:
break; break;
...@@ -2935,13 +2934,12 @@ template <typename T, typename Char> ...@@ -2935,13 +2934,12 @@ template <typename T, typename Char>
struct formatter<T, Char, struct formatter<T, Char,
enable_if_t<internal::type_constant<T, Char>::value != enable_if_t<internal::type_constant<T, Char>::value !=
internal::custom_type>> { internal::custom_type>> {
FMT_CONSTEXPR formatter() : format_str_(nullptr) {} FMT_CONSTEXPR formatter() {}
// Parses format specifiers stopping either at the end of the range or at the // Parses format specifiers stopping either at the end of the range or at the
// terminating '}'. // terminating '}'.
template <typename ParseContext> template <typename ParseContext>
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
format_str_ = ctx.begin();
using handler_type = internal::dynamic_specs_handler<ParseContext>; using handler_type = internal::dynamic_specs_handler<ParseContext>;
auto type = internal::type_constant<T, Char>::value; auto type = internal::type_constant<T, Char>::value;
internal::specs_checker<handler_type> handler(handler_type(specs_, ctx), internal::specs_checker<handler_type> handler(handler_type(specs_, ctx),
...@@ -2991,9 +2989,9 @@ struct formatter<T, Char, ...@@ -2991,9 +2989,9 @@ struct formatter<T, Char,
template <typename FormatContext> template <typename FormatContext>
auto format(const T& val, FormatContext& ctx) -> decltype(ctx.out()) { auto format(const T& val, FormatContext& ctx) -> decltype(ctx.out()) {
internal::handle_dynamic_spec<internal::width_checker>( internal::handle_dynamic_spec<internal::width_checker>(
specs_.width, specs_.width_ref, ctx, format_str_); specs_.width, specs_.width_ref, ctx);
internal::handle_dynamic_spec<internal::precision_checker>( internal::handle_dynamic_spec<internal::precision_checker>(
specs_.precision, specs_.precision_ref, ctx, format_str_); specs_.precision, specs_.precision_ref, ctx);
using range_type = using range_type =
internal::output_range<typename FormatContext::iterator, internal::output_range<typename FormatContext::iterator,
typename FormatContext::char_type>; typename FormatContext::char_type>;
...@@ -3003,7 +3001,6 @@ struct formatter<T, Char, ...@@ -3003,7 +3001,6 @@ struct formatter<T, Char,
private: private:
internal::dynamic_format_specs<Char> specs_; internal::dynamic_format_specs<Char> specs_;
const Char* format_str_;
}; };
#define FMT_FORMAT_AS(Type, Base) \ #define FMT_FORMAT_AS(Type, Base) \
...@@ -3104,9 +3101,9 @@ template <typename Char = char> class dynamic_formatter { ...@@ -3104,9 +3101,9 @@ template <typename Char = char> class dynamic_formatter {
private: private:
template <typename Context> void handle_specs(Context& ctx) { template <typename Context> void handle_specs(Context& ctx) {
internal::handle_dynamic_spec<internal::width_checker>( internal::handle_dynamic_spec<internal::width_checker>(
specs_.width, specs_.width_ref, ctx, format_str_); specs_.width, specs_.width_ref, ctx);
internal::handle_dynamic_spec<internal::precision_checker>( internal::handle_dynamic_spec<internal::precision_checker>(
specs_.precision, specs_.precision_ref, ctx, format_str_); specs_.precision, specs_.precision_ref, ctx);
} }
internal::dynamic_format_specs<Char> specs_; internal::dynamic_format_specs<Char> specs_;
......
...@@ -67,40 +67,6 @@ TEST(CompileTest, CompileTimePreparedPartsTypeProvider) { ...@@ -67,40 +67,6 @@ TEST(CompileTest, CompileTimePreparedPartsTypeProvider) {
} }
#endif #endif
class custom_parts_container {
public:
typedef fmt::internal::format_part<char> format_part_type;
private:
typedef std::deque<format_part_type> parts;
public:
void add(format_part_type part) { parts_.push_back(std::move(part)); }
void substitute_last(format_part_type part) {
parts_.back() = std::move(part);
}
format_part_type last() { return parts_.back(); }
auto begin() -> decltype(std::declval<parts>().begin()) {
return parts_.begin();
}
auto begin() const -> decltype(std::declval<const parts>().begin()) {
return parts_.begin();
}
auto end() -> decltype(std::declval<parts>().begin()) { return parts_.end(); }
auto end() const -> decltype(std::declval<const parts>().begin()) {
return parts_.end();
}
private:
parts parts_;
};
TEST(CompileTest, PassStringLiteralFormat) { TEST(CompileTest, PassStringLiteralFormat) {
const auto prepared = fmt::compile<int>("test {}"); const auto prepared = fmt::compile<int>("test {}");
EXPECT_EQ("test 42", fmt::format(prepared, 42)); EXPECT_EQ("test 42", fmt::format(prepared, 42));
...@@ -155,12 +121,14 @@ TEST(CompileTest, FormattedSize) { ...@@ -155,12 +121,14 @@ TEST(CompileTest, FormattedSize) {
struct formattable {}; struct formattable {};
FMT_BEGIN_NAMESPACE
template <> template <>
struct fmt::formatter<formattable> : formatter<const char*> { struct formatter<formattable> : formatter<const char*> {
auto format(formattable, format_context& ctx) -> decltype(ctx.out()) { auto format(formattable, format_context& ctx) -> decltype(ctx.out()) {
return formatter<const char*>::format("foo", ctx); return formatter<const char*>::format("foo", ctx);
} }
}; };
FMT_END_NAMESPACE
TEST(CompileTest, FormatUserDefinedType) { TEST(CompileTest, FormatUserDefinedType) {
auto f = fmt::compile<formattable>("{}"); auto f = fmt::compile<formattable>("{}");
......
...@@ -690,9 +690,9 @@ struct formatter { ...@@ -690,9 +690,9 @@ struct formatter {
template <typename FormatContext> template <typename FormatContext>
auto format(const T& val, FormatContext& ctx) -> decltype(ctx.out()) { auto format(const T& val, FormatContext& ctx) -> decltype(ctx.out()) {
fmt::internal::handle_dynamic_spec<fmt::internal::width_checker>( fmt::internal::handle_dynamic_spec<fmt::internal::width_checker>(
specs_.width, specs_.width_ref, ctx, nullptr); specs_.width, specs_.width_ref, ctx);
fmt::internal::handle_dynamic_spec<fmt::internal::precision_checker>( fmt::internal::handle_dynamic_spec<fmt::internal::precision_checker>(
specs_.precision, specs_.precision_ref, ctx, nullptr); specs_.precision, specs_.precision_ref, ctx);
using range_type = fmt::internal::output_range<typename FormatContext::iterator, using range_type = fmt::internal::output_range<typename FormatContext::iterator,
typename FormatContext::char_type>; typename FormatContext::char_type>;
return visit_format_arg(arg_formatter<range_type>(ctx, nullptr, &specs_), return visit_format_arg(arg_formatter<range_type>(ctx, nullptr, &specs_),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment