aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksei Vetrov <vvvvvv@google.com>2023-09-11 17:33:09 +0100
committerGiuliano Procida <gprocida@google.com>2023-09-12 09:31:53 +0100
commit87df700dd52f01f0d0627483915b7ca115992861 (patch)
tree12966a5e7612a3884a9c612e7d60aae2d4d101a8
parent7dabd08886f13897bff153fada69c2695d3fe3b9 (diff)
downloadstg-87df700dd52f01f0d0627483915b7ca115992861.tar.gz
Filtering: use "list" as prefix for symbol/file list section
This allows more options for section name that are more suitable for file filter lists. PiperOrigin-RevId: 564411168 Change-Id: I61691485fa5b99471e7ccc9c356bbc623829d2b2
-rw-r--r--filter.cc19
-rw-r--r--testdata/symbol_list2
2 files changed, 7 insertions, 14 deletions
diff --git a/filter.cc b/filter.cc
index fa67c15..d21dbcb 100644
--- a/filter.cc
+++ b/filter.cc
@@ -43,10 +43,7 @@ namespace {
using Items = std::unordered_set<std::string>;
Items ReadAbigail(const std::string& filename) {
- static constexpr std::array<std::string_view, 2> section_suffices = {
- "symbol_list",
- "whitelist",
- };
+ static constexpr std::string_view kSectionSuffix = "list";
Items items;
std::ifstream file(filename);
Check(file.good()) << "error opening filter file '" << filename << ": "
@@ -75,15 +72,11 @@ Items ReadAbigail(const std::string& filename) {
// See if we are entering a filter list section.
if (line[start] == '[' && line[limit - 1] == ']') {
std::string_view section(&line[start + 1], limit - start - 2);
- bool found = false;
- for (const auto& suffix : section_suffices) {
- if (section.size() >= suffix.size()
- && section.substr(section.size() - suffix.size()) == suffix) {
- found = true;
- break;
- }
- }
- in_filter_section = found;
+ // TODO: use std::string_view::ends_with
+ const auto section_size = section.size();
+ const auto suffix_size = kSectionSuffix.size();
+ in_filter_section = section_size >= suffix_size &&
+ section.substr(section_size - suffix_size) == kSectionSuffix;
continue;
}
// Add item.
diff --git a/testdata/symbol_list b/testdata/symbol_list
index 70343e9..6d062d2 100644
--- a/testdata/symbol_list
+++ b/testdata/symbol_list
@@ -9,7 +9,7 @@ one
# next is with leading and trailing spaces
two
# indented comment
-[not_a_list]
+[other_section]
bad
[symbol_list)
bad