Skip to content

Commit

Permalink
Fix locale_flag_with_string and regex_no_presentation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eliaskosunen committed Jan 14, 2024
1 parent 6b50632 commit 46dcc69
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
6 changes: 5 additions & 1 deletion include/scn/detail/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ struct arg_mapper {
{
return {};
}
static unscannable_char map(basic_regex_matches<other_char_type>&)
{
return {};
}

template <typename T>
static std::enable_if_t<std::is_constructible_v<scanner<T, char_type>>,
Expand Down Expand Up @@ -331,7 +335,7 @@ constexpr auto make_value_impl(Arg&& arg)
!std::is_same_v<arg_nocvref_t, unscannable_char>;
static_assert(scannable_char,
"Cannot scan an argument of an unsupported character "
"type (char from a wchar_t source)");
"type (i.e. char from a wchar_t source)");

constexpr bool scannable_const =
!std::is_same_v<arg_nocvref_t, unscannable_const>;
Expand Down
8 changes: 8 additions & 0 deletions include/scn/detail/format_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,14 @@ class format_string_checker {
constexpr void on_replacement_field(size_t id, const CharT*)
{
set_arg_as_read(id);

if (m_types[id] == arg_type::narrow_regex_matches_type ||
m_types[id] == arg_type::wide_regex_matches_type) {
// clang-format off
return on_error("Regular expression needs to specified "
"when reading regex_matches");
// clang-format on
}
}

constexpr const CharT* on_format_specs(std::size_t id,
Expand Down
4 changes: 0 additions & 4 deletions include/scn/detail/format_string_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -1106,10 +1106,6 @@ template <typename CharT, typename Handler>
constexpr void check_regex_type_specs(const basic_format_specs<CharT>& specs,
Handler&& handler)
{
if (specs.type == presentation_type::regex ||
specs.type == presentation_type::regex_escaped) {
return;
}
if (SCN_UNLIKELY(specs.type == presentation_type::none ||
specs.charset_string.empty())) {
// clang-format off
Expand Down
5 changes: 3 additions & 2 deletions src/scn/impl/reader/regex_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,9 @@ struct regex_matches_reader
basic_regex_matches<DestCharT>&,
detail::locale_ref = {})
{
SCN_EXPECT(false);
SCN_UNREACHABLE;
return unexpected_scan_error(
scan_error::invalid_format_string,
"No regex given in format string for scanning regex_matches");
}

template <typename Range, typename DestCharT>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

int main()
{
// build error: 'L' specifier can only be used with arguments
// build error: 'L' specifier can only be used
auto result = scn::scan<std::string>("42", SCN_STRING("{:L}"));
return result && result->value() == "42";
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

int main()
{
// build error: Regular expression needs to be specified when reading
// build error: Regular expression needs to be specified
auto result = scn::scan<scn::regex_matches>("42", SCN_STRING("{}"));
return !result.has_value();
}

0 comments on commit 46dcc69

Please sign in to comment.