Small formatting changes
CI / build (debug, map[compiler:appleclang os:macos-latest]) (push) Canceled after 0s
CI / build (debug, map[compiler:clang os:ubuntu-latest]) (push) Canceled after 0s
CI / build (debug, map[compiler:gcc os:ubuntu-latest]) (push) Canceled after 0s
CI / build (debug, map[compiler:msvc os:windows-latest]) (push) Canceled after 0s
CI / build (release, map[compiler:appleclang os:macos-latest]) (push) Canceled after 0s
CI / build (release, map[compiler:clang os:ubuntu-latest]) (push) Canceled after 0s
CI / build (release, map[compiler:gcc os:ubuntu-latest]) (push) Canceled after 0s
CI / build (release, map[compiler:msvc os:windows-latest]) (push) Canceled after 0s
CI / build (sanitizers, map[compiler:appleclang os:macos-latest]) (push) Canceled after 0s
CI / build (sanitizers, map[compiler:clang os:ubuntu-latest]) (push) Canceled after 0s
CI / build (sanitizers, map[compiler:gcc os:ubuntu-latest]) (push) Canceled after 0s
CI / build (sanitizers, map[compiler:msvc os:windows-latest]) (push) Canceled after 0s

This commit is contained in:
wilmc committed 2026-10-09 13:15:45 +02:00
1 parent a0fbb9f50e
commit ae1146b975
1 file changed
+12 -2
+12 -2
View File
@@ -137,29 +137,34 @@ auto map_sections(const std::vector<std::string>& lines, std::string_view term)
{ {
const auto begin = boundaries[i - 1]; const auto begin = boundaries[i - 1];
const auto end = boundaries[i]; const auto end = boundaries[i];
if (begin == end) if (begin == end)
{ {
continue; continue;
} }
const bool title_match = heading(lines[begin]) && lower(lines[begin]).find(query) != std::string::npos; const bool title_match = heading(lines[begin]) && lower(lines[begin]).find(query) != std::string::npos;
bool body_match = false; bool body_match = false;
for (auto j = begin; j < end && !body_match; ++j) for (auto j = begin; j < end && !body_match; ++j)
{ {
body_match = lower(lines[j]).find(query) != std::string::npos; body_match = lower(lines[j]).find(query) != std::string::npos;
} }
if (body_match) if (body_match)
{ {
matches.push_back({begin, end, title_match}); matches.push_back({begin, end, title_match});
} }
} }
std::stable_sort(matches.begin(), matches.end(), [](const section& a, const section& b) std::stable_sort(matches.begin(), matches.end(), [](const section& a, const section& b){
{
return a.title_match > b.title_match; return a.title_match > b.title_match;
}); });
std::string output; std::string output;
std::size_t shown_lines = 0; std::size_t shown_lines = 0;
std::size_t shown_sections = 0; std::size_t shown_sections = 0;
bool truncated = false; bool truncated = false;
for (const auto& match : matches) for (const auto& match : matches)
{ {
if (shown_sections == 3) if (shown_sections == 3)
@@ -167,6 +172,7 @@ auto map_sections(const std::vector<std::string>& lines, std::string_view term)
truncated = true; truncated = true;
break; break;
} }
++shown_sections; ++shown_sections;
for (auto i = match.begin; i < match.end; ++i) for (auto i = match.begin; i < match.end; ++i)
{ {
@@ -178,19 +184,23 @@ auto map_sections(const std::vector<std::string>& lines, std::string_view term)
output += lines[i] + '\n'; output += lines[i] + '\n';
++shown_lines; ++shown_lines;
} }
if (truncated) if (truncated)
{ {
break; break;
} }
} }
if (matches.empty()) if (matches.empty())
{ {
return "No relevant project-map section found.\n"; return "No relevant project-map section found.\n";
} }
if (truncated) if (truncated)
{ {
output += "TRUNCATED (limit: 3 sections, 120 lines, 16384 bytes)\n"; output += "TRUNCATED (limit: 3 sections, 120 lines, 16384 bytes)\n";
} }
return output; return output;
} }
} // namespace rl } // namespace rl