Skip to content

Commit 1de7dbc

Browse files
committed
Begin simplified parser with better understanding of the context
1 parent 3ae8bdf commit 1de7dbc

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

include/boost/decimal/format.hpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
namespace boost::decimal::detail {
3131

32+
/*
3233
template <typename ParseContext>
3334
constexpr auto parse_impl(ParseContext &ctx)
3435
{
@@ -112,6 +113,57 @@ constexpr auto parse_impl(ParseContext &ctx)
112113
113114
return std::make_tuple(ctx_precision, fmt, is_upper, padding_digits, it);
114115
}
116+
*/
117+
118+
template <typename ParseContext>
119+
constexpr auto parse_impl(ParseContext &ctx)
120+
{
121+
auto it {ctx.begin()};
122+
int ctx_precision = 6;
123+
boost::decimal::chars_format fmt = boost::decimal::chars_format::general;
124+
bool is_upper = false;
125+
int padding_digits = 0;
126+
127+
if (*it != '}')
128+
{
129+
switch (*it)
130+
{
131+
case 'G':
132+
is_upper = true;
133+
[[fallthrough]];
134+
case 'g':
135+
fmt = chars_format::general;
136+
break;
137+
138+
case 'F':
139+
[[fallthrough]];
140+
case 'f':
141+
fmt = chars_format::fixed;
142+
break;
143+
144+
case 'E':
145+
is_upper = true;
146+
[[fallthrough]];
147+
case 'e':
148+
fmt = chars_format::scientific;
149+
break;
150+
151+
case 'A':
152+
is_upper = true;
153+
[[fallthrough]];
154+
case 'a':
155+
fmt = chars_format::hex;
156+
break;
157+
158+
default:
159+
throw std::format_error("Invalid format");
160+
}
161+
}
162+
163+
++it;
164+
165+
return std::make_tuple(ctx_precision, fmt, is_upper, padding_digits, it);
166+
}
115167

116168
} // Namespace boost::decimal::detail
117169

0 commit comments

Comments
 (0)