Skip to content

Commit 98c4a6d

Browse files
committed
Simplify validation of non-specified presentation types
If presentation type was not specified, the format string parser can blindly accept the format parameter type.
1 parent 9a3e71d commit 98c4a6d

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

fly/types/string/detail/string_formatter_types.hpp

+11-17
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,10 @@ constexpr bool BasicFormatString<StringType, ParameterTypes...>::validate_specif
11791179
}
11801180

11811181
// Validate the presentation type.
1182-
validate_type(*type, specifier);
1182+
if (specifier.m_type != FormatSpecifier::Type::None)
1183+
{
1184+
validate_type(*type, specifier);
1185+
}
11831186

11841187
return !has_error();
11851188
}
@@ -1193,15 +1196,11 @@ constexpr void BasicFormatString<StringType, ParameterTypes...>::validate_type(
11931196
switch (type)
11941197
{
11951198
case ParameterType::Generic:
1196-
if (specifier.m_type != FormatSpecifier::Type::None)
1197-
{
1198-
on_error("Generic types must be formatted with {}");
1199-
}
1199+
on_error("Generic types must be formatted with {}");
12001200
break;
12011201

12021202
case ParameterType::Character:
1203-
if ((specifier.m_type != FormatSpecifier::Type::None) &&
1204-
(specifier.m_type != FormatSpecifier::Type::Character) &&
1203+
if ((specifier.m_type != FormatSpecifier::Type::Character) &&
12051204
(specifier.m_type != FormatSpecifier::Type::Binary) &&
12061205
(specifier.m_type != FormatSpecifier::Type::Octal) &&
12071206
(specifier.m_type != FormatSpecifier::Type::Decimal) &&
@@ -1212,24 +1211,21 @@ constexpr void BasicFormatString<StringType, ParameterTypes...>::validate_type(
12121211
break;
12131212

12141213
case ParameterType::String:
1215-
if ((specifier.m_type != FormatSpecifier::Type::None) &&
1216-
(specifier.m_type != FormatSpecifier::Type::String))
1214+
if (specifier.m_type != FormatSpecifier::Type::String)
12171215
{
12181216
on_error("String types must be formatted with {} or {:s}");
12191217
}
12201218
break;
12211219

12221220
case ParameterType::Pointer:
1223-
if ((specifier.m_type != FormatSpecifier::Type::None) &&
1224-
(specifier.m_type != FormatSpecifier::Type::Pointer))
1221+
if (specifier.m_type != FormatSpecifier::Type::Pointer)
12251222
{
12261223
on_error("Pointer types must be formatted with {} or {:p}");
12271224
}
12281225
break;
12291226

12301227
case ParameterType::Integral:
1231-
if ((specifier.m_type != FormatSpecifier::Type::None) &&
1232-
(specifier.m_type != FormatSpecifier::Type::Character) &&
1228+
if ((specifier.m_type != FormatSpecifier::Type::Character) &&
12331229
(specifier.m_type != FormatSpecifier::Type::Binary) &&
12341230
(specifier.m_type != FormatSpecifier::Type::Octal) &&
12351231
(specifier.m_type != FormatSpecifier::Type::Decimal) &&
@@ -1240,8 +1236,7 @@ constexpr void BasicFormatString<StringType, ParameterTypes...>::validate_type(
12401236
break;
12411237

12421238
case ParameterType::FloatingPoint:
1243-
if ((specifier.m_type != FormatSpecifier::Type::None) &&
1244-
(specifier.m_type != FormatSpecifier::Type::HexFloat) &&
1239+
if ((specifier.m_type != FormatSpecifier::Type::HexFloat) &&
12451240
(specifier.m_type != FormatSpecifier::Type::Scientific) &&
12461241
(specifier.m_type != FormatSpecifier::Type::Fixed) &&
12471242
(specifier.m_type != FormatSpecifier::Type::General))
@@ -1251,8 +1246,7 @@ constexpr void BasicFormatString<StringType, ParameterTypes...>::validate_type(
12511246
break;
12521247

12531248
case ParameterType::Boolean:
1254-
if ((specifier.m_type != FormatSpecifier::Type::None) &&
1255-
(specifier.m_type != FormatSpecifier::Type::Character) &&
1249+
if ((specifier.m_type != FormatSpecifier::Type::Character) &&
12561250
(specifier.m_type != FormatSpecifier::Type::String) &&
12571251
(specifier.m_type != FormatSpecifier::Type::Binary) &&
12581252
(specifier.m_type != FormatSpecifier::Type::Octal) &&

0 commit comments

Comments
 (0)