From b18b6fc7e6223075b4447d08323ba7e81728febe Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 2 Nov 2026 18:27:08 +0100 Subject: [PATCH] Build the parser's syntax error prefix with one concat() (#6013) Since #6004 made the "while parsing" part unconditional, the three appends at the start of exception_message() are one fixed string around the context. Review follow-up to #6004. Signed-off-by: Niels Lohmann --- include/nlohmann/detail/input/parser.hpp | 6 +----- single_include/nlohmann/json.hpp | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/include/nlohmann/detail/input/parser.hpp b/include/nlohmann/detail/input/parser.hpp index 1446f4524..9335542a0 100644 --- a/include/nlohmann/detail/input/parser.hpp +++ b/include/nlohmann/detail/input/parser.hpp @@ -573,11 +573,7 @@ class parser std::string exception_message(const token_type expected, const std::string& context) { - std::string error_msg = "syntax error "; - - error_msg += concat("while parsing ", context, ' '); - - error_msg += "- "; + std::string error_msg = concat("syntax error while parsing ", context, " - "); if (last_token == token_type::parse_error) { diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 7f58db2af..cf5a4d711 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -23802,11 +23802,7 @@ class parser std::string exception_message(const token_type expected, const std::string& context) { - std::string error_msg = "syntax error "; - - error_msg += concat("while parsing ", context, ' '); - - error_msg += "- "; + std::string error_msg = concat("syntax error while parsing ", context, " - "); if (last_token == token_type::parse_error) {