diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-03-08 10:28:10 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-03-20 13:40:30 +0000 |
commit | e733310db58160074f574c429d48f8308c0afe17 (patch) | |
tree | f8aef4b7e62a69928dbcf880620eece20f98c6df /chromium/components/query_parser | |
parent | 2f583e4aec1ae3a86fa047829c96b310dc12ecdf (diff) | |
download | qtwebengine-chromium-e733310db58160074f574c429d48f8308c0afe17.tar.gz |
BASELINE: Update Chromium to 56.0.2924.122
Change-Id: I4e04de8f47e47e501c46ed934c76a431c6337ced
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/components/query_parser')
-rw-r--r-- | chromium/components/query_parser/query_parser.cc | 39 | ||||
-rw-r--r-- | chromium/components/query_parser/query_parser.h | 11 | ||||
-rw-r--r-- | chromium/components/query_parser/query_parser_unittest.cc | 9 |
3 files changed, 28 insertions, 31 deletions
diff --git a/chromium/components/query_parser/query_parser.cc b/chromium/components/query_parser/query_parser.cc index 260a75afd9f..c65b06ee252 100644 --- a/chromium/components/query_parser/query_parser.cc +++ b/chromium/components/query_parser/query_parser.cc @@ -11,7 +11,7 @@ #include "base/i18n/case_conversion.h" #include "base/logging.h" #include "base/macros.h" -#include "base/stl_util.h" +#include "base/memory/ptr_util.h" #include "base/strings/utf_string_conversions.h" namespace query_parser { @@ -156,9 +156,9 @@ class QueryNodeList : public QueryNode { QueryNodeList(); ~QueryNodeList() override; - QueryNodeStarVector* children() { return &children_; } + QueryNodeVector* children() { return &children_; } - void AddChild(QueryNode* node); + void AddChild(std::unique_ptr<QueryNode> node); // Remove empty subnodes left over from other parsing. void RemoveEmptySubnodes(); @@ -175,7 +175,7 @@ class QueryNodeList : public QueryNode { protected: int AppendChildrenToString(base::string16* query) const; - QueryNodeStarVector children_; + QueryNodeVector children_; private: DISALLOW_COPY_AND_ASSIGN(QueryNodeList); @@ -184,11 +184,10 @@ class QueryNodeList : public QueryNode { QueryNodeList::QueryNodeList() {} QueryNodeList::~QueryNodeList() { - base::STLDeleteElements(&children_); } -void QueryNodeList::AddChild(QueryNode* node) { - children_.push_back(node); +void QueryNodeList::AddChild(std::unique_ptr<QueryNode> node) { + children_.push_back(std::move(node)); } void QueryNodeList::RemoveEmptySubnodes() { @@ -196,12 +195,11 @@ void QueryNodeList::RemoveEmptySubnodes() { if (children_[i]->IsWord()) continue; - QueryNodeList* list_node = static_cast<QueryNodeList*>(children_[i]); + QueryNodeList* list_node = static_cast<QueryNodeList*>(children_[i].get()); list_node->RemoveEmptySubnodes(); if (list_node->children()->empty()) { children_.erase(children_.begin() + i); --i; - delete list_node; } } } @@ -237,8 +235,7 @@ void QueryNodeList::AppendWords(std::vector<base::string16>* words) const { int QueryNodeList::AppendChildrenToString(base::string16* query) const { int num_words = 0; - for (QueryNodeStarVector::const_iterator node = children_.begin(); - node != children_.end(); ++node) { + for (auto node = children_.begin(); node != children_.end(); ++node) { if (node != children_.begin()) query->push_back(L' '); num_words += (*node)->AppendToSQLiteQuery(query); @@ -358,14 +355,14 @@ void QueryParser::ParseQueryWords(const base::string16& query, void QueryParser::ParseQueryNodes(const base::string16& query, MatchingAlgorithm matching_algorithm, - QueryNodeStarVector* nodes) { + QueryNodeVector* nodes) { QueryNodeList root; if (ParseQueryImpl(base::i18n::ToLower(query), matching_algorithm, &root)) nodes->swap(*root.children()); } bool QueryParser::DoesQueryMatch(const base::string16& text, - const QueryNodeStarVector& query_nodes, + const QueryNodeVector& query_nodes, Snippet::MatchPositions* match_positions) { if (query_nodes.empty()) return false; @@ -396,7 +393,7 @@ bool QueryParser::DoesQueryMatch(const base::string16& text, } bool QueryParser::DoesQueryMatch(const QueryWordVector& query_words, - const QueryNodeStarVector& query_nodes) { + const QueryNodeVector& query_nodes) { if (query_nodes.empty() || query_words.empty()) return false; @@ -426,17 +423,19 @@ bool QueryParser::ParseQueryImpl(const base::string16& query, // is not necessarily a word, but could also be a sequence of punctuation // or whitespace. if (iter.IsWord()) { - QueryNodeWord* word_node = new QueryNodeWord(iter.GetString(), - matching_algorithm); + std::unique_ptr<QueryNodeWord> word_node = + base::MakeUnique<QueryNodeWord>(iter.GetString(), matching_algorithm); if (in_quotes) word_node->set_literal(true); - query_stack.back()->AddChild(word_node); + query_stack.back()->AddChild(std::move(word_node)); } else { // Punctuation. if (IsQueryQuote(query[iter.prev()])) { if (!in_quotes) { - QueryNodeList* quotes_node = new QueryNodePhrase; - query_stack.back()->AddChild(quotes_node); - query_stack.push_back(quotes_node); + std::unique_ptr<QueryNodeList> quotes_node = + base::MakeUnique<QueryNodePhrase>(); + QueryNodeList* quotes_node_ptr = quotes_node.get(); + query_stack.back()->AddChild(std::move(quotes_node)); + query_stack.push_back(quotes_node_ptr); in_quotes = true; } else { query_stack.pop_back(); // Stop adding to the quoted phrase. diff --git a/chromium/components/query_parser/query_parser.h b/chromium/components/query_parser/query_parser.h index a6e2d229ea1..5e3f18b26e6 100644 --- a/chromium/components/query_parser/query_parser.h +++ b/chromium/components/query_parser/query_parser.h @@ -7,6 +7,7 @@ #include <stddef.h> +#include <memory> #include <vector> #include "base/macros.h" @@ -34,7 +35,7 @@ enum class MatchingAlgorithm { ALWAYS_PREFIX_SEARCH, }; -typedef std::vector<query_parser::QueryWord> QueryWordVector; +using QueryWordVector = std::vector<query_parser::QueryWord>; // QueryNode is used by QueryParser to represent the elements that constitute a // query. While QueryNode is exposed by way of ParseQuery, it really isn't meant @@ -67,7 +68,7 @@ class QueryNode { virtual void AppendWords(std::vector<base::string16>* words) const = 0; }; -typedef std::vector<query_parser::QueryNode*> QueryNodeStarVector; +using QueryNodeVector = std::vector<std::unique_ptr<query_parser::QueryNode>>; // This class is used to parse queries entered into the history search into more // normalized queries that can be passed to the SQLite backend. @@ -105,19 +106,19 @@ class QueryParser { // the nodes passes to the caller. void ParseQueryNodes(const base::string16& query, MatchingAlgorithm matching_algorithm, - QueryNodeStarVector* nodes); + QueryNodeVector* nodes); // Returns true if the string text matches the query nodes created by a call // to ParseQuery. If the query does match, each of the matching positions in // the text is added to |match_positions|. bool DoesQueryMatch(const base::string16& text, - const QueryNodeStarVector& nodes, + const QueryNodeVector& nodes, Snippet::MatchPositions* match_positions); // Returns true if all of the |words| match the query |nodes| created by a // call to ParseQuery. bool DoesQueryMatch(const QueryWordVector& words, - const QueryNodeStarVector& nodes); + const QueryNodeVector& nodes); // Extracts the words from |text|, placing each word into |words|. void ExtractQueryWords(const base::string16& text, diff --git a/chromium/components/query_parser/query_parser_unittest.cc b/chromium/components/query_parser/query_parser_unittest.cc index c99c639b964..e99bf5a1101 100644 --- a/chromium/components/query_parser/query_parser_unittest.cc +++ b/chromium/components/query_parser/query_parser_unittest.cc @@ -5,7 +5,6 @@ #include <stddef.h> #include "base/macros.h" -#include "base/memory/scoped_vector.h" #include "base/strings/utf_string_conversions.h" #include "components/query_parser/query_parser.h" #include "testing/gtest/include/gtest/gtest.h" @@ -123,15 +122,13 @@ TEST_F(QueryParserTest, ParseQueryNodesAndMatch) { }; for (size_t i = 0; i < arraysize(data); ++i) { QueryParser parser; - ScopedVector<QueryNode> query_nodes; + query_parser::QueryNodeVector query_nodes; parser.ParseQueryNodes(base::UTF8ToUTF16(data[i].query), - MatchingAlgorithm::DEFAULT, - &query_nodes.get()); + MatchingAlgorithm::DEFAULT, &query_nodes); Snippet::MatchPositions match_positions; ASSERT_EQ(data[i].matches, parser.DoesQueryMatch(base::UTF8ToUTF16(data[i].text), - query_nodes.get(), - &match_positions)); + query_nodes, &match_positions)); size_t offset = 0; if (data[i].m1_start != 0 || data[i].m1_end != 0) { ASSERT_TRUE(match_positions.size() >= 1); |