From bcb9ecb2cd2208d12b83c4e111be7c126b49dc7e Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 1 Feb 2020 17:04:58 +0100 Subject: patterns: Provide Node constructor, simplify error throwing By having a node constructor, we can construct a node inline for error reporting needs, simplifying the code a bit. --- apt-pkg/cachefilter-patterns.cc | 13 +++---------- apt-pkg/cachefilter-patterns.h | 2 ++ 2 files changed, 5 insertions(+), 10 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index a9f76ff1d..b21f70d6a 100644 --- a/apt-pkg/cachefilter-patterns.cc +++ b/apt-pkg/cachefilter-patterns.cc @@ -33,13 +33,7 @@ std::unique_ptr PatternTreeParser::parseTop() skipSpace(); if (node->end != sentence.size()) - { - Node node2; - - node2.start = node->end; - node2.end = sentence.size(); - throw Error{node2, "Expected end of file"}; - } + throw Error{Node{node->end, sentence.size()}, "Expected end of file"}; return node; } @@ -55,9 +49,8 @@ std::unique_ptr PatternTreeParser::parse() if ((node = parseWord()) != nullptr) return node; - Node eNode; - eNode.end = eNode.start = state.offset; - throw Error{eNode, "Expected pattern, quoted word, or word"}; + throw Error{Node{state.offset, sentence.size()}, + "Expected pattern, quoted word, or word"}; } // Parse a list pattern (or function call pattern) diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index 33595dde2..8317665bc 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -39,6 +39,8 @@ struct PatternTreeParser size_t start = 0; size_t end = 0; + explicit Node(size_t start = 0, size_t end = 0) : start(start), end(end) {} + virtual std::ostream &render(std::ostream &os) { return os; }; std::nullptr_t error(std::string message); }; -- cgit v1.2.3-70-g09d2