Skip to content

Commit

Permalink
revert and address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zivshek committed Mar 30, 2024
1 parent ea3cff9 commit 6a24da0
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -2105,19 +2105,20 @@ class year_month_day {
template <typename Char>
struct formatter<weekday, Char> : formatter<std::tm, Char> {
private:
bool localized{false};
bool localized_{false};
bool use_tm_formatter_{false};

public:
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx)
-> decltype(ctx.begin()) {
auto begin = ctx.begin(), end = ctx.end();
if (begin != end && *begin == 'L') {
++begin;
localized = true;
auto it = ctx.begin(), end = ctx.end();
if (it != end && *it == 'L') {
++it;
localized_ = true;
}
use_tm_formatter_ = !localized && (begin != nullptr);
return use_tm_formatter_ ? formatter<std::tm, Char>::parse(ctx) : begin;
auto empty = (it == end || *it == '}');
use_tm_formatter_ = !empty && !localized_;
return use_tm_formatter_ ? formatter<std::tm, Char>::parse(ctx) : it;
}

template <typename FormatContext>
Expand All @@ -2127,7 +2128,7 @@ struct formatter<weekday, Char> : formatter<std::tm, Char> {
if (use_tm_formatter_) {
return formatter<std::tm, Char>::format(time, ctx);
}
detail::get_locale loc(localized, ctx.locale());
detail::get_locale loc(localized_, ctx.locale());
auto w = detail::tm_writer<decltype(ctx.out()), Char>(loc, ctx.out(), time);
w.on_abbr_weekday();
return w.out();
Expand All @@ -2142,8 +2143,9 @@ struct formatter<day, Char> : formatter<std::tm, Char> {
public:
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx)
-> decltype(ctx.begin()) {
use_tm_formatter_ = ctx.begin() != nullptr;
return formatter<std::tm, Char>::parse(ctx);
auto it = ctx.begin(), end = ctx.end();
use_tm_formatter_ = !(it == end || *it == '}');
return use_tm_formatter_ ? formatter<std::tm, Char>::parse(ctx) : it;
}

template <typename FormatContext>
Expand All @@ -2163,19 +2165,20 @@ struct formatter<day, Char> : formatter<std::tm, Char> {
template <typename Char>
struct formatter<month, Char> : formatter<std::tm, Char> {
private:
bool localized{false};
bool localized_{false};
bool use_tm_formatter_{false};

public:
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx)
-> decltype(ctx.begin()) {
auto begin = ctx.begin(), end = ctx.end();
if (begin != end && *begin == 'L') {
++begin;
localized = true;
auto it = ctx.begin(), end = ctx.end();
if (it != end && *it == 'L') {
++it;
localized_ = true;
}
use_tm_formatter_ = !localized && (begin != nullptr);
return use_tm_formatter_ ? formatter<std::tm, Char>::parse(ctx) : begin;
auto empty = (it == end || *it == '}');
use_tm_formatter_ = !empty && !localized_;
return use_tm_formatter_ ? formatter<std::tm, Char>::parse(ctx) : it;
}

template <typename FormatContext>
Expand All @@ -2185,7 +2188,7 @@ struct formatter<month, Char> : formatter<std::tm, Char> {
if (use_tm_formatter_) {
return formatter<std::tm, Char>::format(time, ctx);
}
detail::get_locale loc(localized, ctx.locale());
detail::get_locale loc(localized_, ctx.locale());
auto w = detail::tm_writer<decltype(ctx.out()), Char>(loc, ctx.out(), time);
w.on_abbr_month();
return w.out();
Expand All @@ -2200,8 +2203,9 @@ struct formatter<year, Char> : formatter<std::tm, Char> {
public:
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx)
-> decltype(ctx.begin()) {
use_tm_formatter_ = ctx.begin() != nullptr;
return formatter<std::tm, Char>::parse(ctx);
auto it = ctx.begin(), end = ctx.end();
use_tm_formatter_ = !(it == end || *it == '}');
return use_tm_formatter_ ? formatter<std::tm, Char>::parse(ctx) : it;
}

template <typename FormatContext>
Expand All @@ -2226,8 +2230,9 @@ struct formatter<year_month_day, Char> : formatter<std::tm, Char> {
public:
FMT_CONSTEXPR auto parse(basic_format_parse_context<Char>& ctx)
-> decltype(ctx.begin()) {
use_tm_formatter_ = ctx.begin() != nullptr;
return formatter<std::tm, Char>::parse(ctx);
auto it = ctx.begin(), end = ctx.end();
use_tm_formatter_ = !(it == end || *it == '}');
return use_tm_formatter_ ? formatter<std::tm, Char>::parse(ctx) : it;
}

template <typename FormatContext>
Expand Down

0 comments on commit 6a24da0

Please sign in to comment.