From fbb5038105e26e07d34184544ea4c70892acef92 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 2 Jul 2026 15:46:25 +0100 Subject: Fixes to parseEscapedString Fix the warnings picked up by the latest clang-tidy. Add test cases lifted from the bad_lines log. Add missing support for \b in escaping. --- src/logTypes.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/logTypes.cpp b/src/logTypes.cpp index d8b3a7e..25fc193 100644 --- a/src/logTypes.cpp +++ b/src/logTypes.cpp @@ -3,18 +3,19 @@ namespace { namespace { constexpr auto BS_MAP = []() { - std::array map {}; - map['f'] = '\f'; - map['n'] = '\n'; - map['r'] = '\r'; - map['t'] = '\t'; - map['v'] = '\v'; - map['"'] = '"'; - map['\\'] = '\\'; + std::array map {}; + map.at('b') = '\b'; + map.at('f') = '\f'; + map.at('n') = '\n'; + map.at('r') = '\r'; + map.at('t') = '\t'; + map.at('v') = '\v'; + map.at('"') = '"'; + map.at('\\') = '\\'; return map; }(); - scn::scan_expected + scn::scan_expected parseEscapedString(std::string & value, scn::ContextType & ctx, const auto & start) { ctx.advance_to(start->begin()); @@ -30,8 +31,8 @@ namespace { value.append(1, static_cast(hex->value())); ctx.advance_to(hex->begin()); } - else if (auto escaped = scn::scan(ctx.range(), R"ESC(\{:.1[fnrtv"\]})ESC")) { - value.append(1, BS_MAP[static_cast(escaped->value().front())]); + else if (auto escaped = scn::scan(ctx.range(), R"ESC(\{:.1[bfnrtv"\]})ESC")) { + value.append(1, BS_MAP.at(static_cast(escaped->value().front()))); ctx.advance_to(escaped->begin()); } else { @@ -44,7 +45,7 @@ namespace { } namespace scn { - scan_expected + scan_expected scanner::scan(WebStat::QuotedString & value, ContextType & ctx) { if (auto empty = scn::scan<>(ctx.range(), R"("")")) { @@ -63,7 +64,7 @@ namespace scn { return unexpected(simple.error()); } - scan_expected + scan_expected scanner::scan(WebStat::QueryString & value, ContextType & ctx) { if (auto null = scn::scan<>(ctx.range(), R"("")")) { @@ -83,13 +84,13 @@ namespace scn { return unexpected(empty.error()); } - scan_expected + scan_expected scanner::scan(WebStat::CLFString & value, ContextType & ctx) { if (auto null = scn::scan<>(ctx.range(), R"("-")")) { return null->begin(); } - return scn::scanner {}.scan(value.emplace(), ctx); + return scn::scanner::scan(value.emplace(), ctx); } } -- cgit v1.3