Get rid of do_check_format_string
This commit is contained in:
parent
4a1d5931cb
commit
2b75bd7ce6
@ -2723,20 +2723,14 @@ FMT_CONSTEXPR basic_string_view<Char> compile_string_to_view(
|
|||||||
# define fmt(s) FMT_STRING_IMPL(s, [[deprecated]])
|
# define fmt(s) FMT_STRING_IMPL(s, [[deprecated]])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename Char, typename ErrorHandler, typename... Args>
|
|
||||||
FMT_CONSTEXPR bool do_check_format_string(basic_string_view<Char> s,
|
|
||||||
ErrorHandler eh = ErrorHandler()) {
|
|
||||||
format_string_checker<Char, ErrorHandler, Args...> checker(s, eh);
|
|
||||||
parse_format_string<true>(s, checker);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args, typename S,
|
template <typename... Args, typename S,
|
||||||
enable_if_t<(is_compile_string<S>::value), int>>
|
enable_if_t<(is_compile_string<S>::value), int>>
|
||||||
void check_format_string(S format_str) {
|
void check_format_string(S format_str) {
|
||||||
FMT_CONSTEXPR_DECL bool invalid_format = internal::do_check_format_string<
|
FMT_CONSTEXPR_DECL auto s = to_string_view(format_str);
|
||||||
typename S::char_type, internal::error_handler,
|
using checker = format_string_checker<typename S::char_type, error_handler,
|
||||||
remove_const_t<remove_reference_t<Args>>...>(to_string_view(format_str));
|
remove_cvref_t<Args>...>;
|
||||||
|
FMT_CONSTEXPR_DECL bool invalid_format =
|
||||||
|
(parse_format_string<true>(s, checker(s, {})), true);
|
||||||
(void)invalid_format;
|
(void)invalid_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -647,8 +647,7 @@ TEST(FormatterTest, ArgErrors) {
|
|||||||
safe_sprintf(format_str, "{%u", INT_MAX);
|
safe_sprintf(format_str, "{%u", INT_MAX);
|
||||||
EXPECT_THROW_MSG(format(format_str), format_error, "invalid format string");
|
EXPECT_THROW_MSG(format(format_str), format_error, "invalid format string");
|
||||||
safe_sprintf(format_str, "{%u}", INT_MAX);
|
safe_sprintf(format_str, "{%u}", INT_MAX);
|
||||||
EXPECT_THROW_MSG(format(format_str), format_error,
|
EXPECT_THROW_MSG(format(format_str), format_error, "argument not found");
|
||||||
"argument not found");
|
|
||||||
|
|
||||||
safe_sprintf(format_str, "{%u", INT_MAX + 1u);
|
safe_sprintf(format_str, "{%u", INT_MAX + 1u);
|
||||||
EXPECT_THROW_MSG(format(format_str), format_error, "number is too big");
|
EXPECT_THROW_MSG(format(format_str), format_error, "number is too big");
|
||||||
@ -1011,8 +1010,7 @@ TEST(FormatterTest, RuntimeWidth) {
|
|||||||
EXPECT_THROW_MSG(format("{0:{}", 0), format_error,
|
EXPECT_THROW_MSG(format("{0:{}", 0), format_error,
|
||||||
"cannot switch from manual to automatic argument indexing");
|
"cannot switch from manual to automatic argument indexing");
|
||||||
EXPECT_THROW_MSG(format("{0:{?}}", 0), format_error, "invalid format string");
|
EXPECT_THROW_MSG(format("{0:{?}}", 0), format_error, "invalid format string");
|
||||||
EXPECT_THROW_MSG(format("{0:{1}}", 0), format_error,
|
EXPECT_THROW_MSG(format("{0:{1}}", 0), format_error, "argument not found");
|
||||||
"argument not found");
|
|
||||||
|
|
||||||
EXPECT_THROW_MSG(format("{0:{0:}}", 0), format_error,
|
EXPECT_THROW_MSG(format("{0:{0:}}", 0), format_error,
|
||||||
"invalid format string");
|
"invalid format string");
|
||||||
@ -1160,8 +1158,7 @@ TEST(FormatterTest, RuntimePrecision) {
|
|||||||
"invalid format string");
|
"invalid format string");
|
||||||
EXPECT_THROW_MSG(format("{0:.{1}", 0, 0), format_error,
|
EXPECT_THROW_MSG(format("{0:.{1}", 0, 0), format_error,
|
||||||
"precision not allowed for this argument type");
|
"precision not allowed for this argument type");
|
||||||
EXPECT_THROW_MSG(format("{0:.{1}}", 0), format_error,
|
EXPECT_THROW_MSG(format("{0:.{1}}", 0), format_error, "argument not found");
|
||||||
"argument not found");
|
|
||||||
|
|
||||||
EXPECT_THROW_MSG(format("{0:.{0:}}", 0), format_error,
|
EXPECT_THROW_MSG(format("{0:.{0:}}", 0), format_error,
|
||||||
"invalid format string");
|
"invalid format string");
|
||||||
@ -2456,8 +2453,10 @@ FMT_CONSTEXPR bool equal(const char* s1, const char* s2) {
|
|||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
FMT_CONSTEXPR bool test_error(const char* fmt, const char* expected_error) {
|
FMT_CONSTEXPR bool test_error(const char* fmt, const char* expected_error) {
|
||||||
const char* actual_error = nullptr;
|
const char* actual_error = nullptr;
|
||||||
fmt::internal::do_check_format_string<char, test_error_handler, Args...>(
|
string_view s(fmt, len(fmt));
|
||||||
string_view(fmt, len(fmt)), test_error_handler(actual_error));
|
fmt::internal::format_string_checker<char, test_error_handler, Args...>
|
||||||
|
checker(s, test_error_handler(actual_error));
|
||||||
|
fmt::internal::parse_format_string<true>(s, checker);
|
||||||
return equal(actual_error, expected_error);
|
return equal(actual_error, expected_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user