Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1635)

Unified Diff: chrome/browser/history/query_parser.cc

Issue 9316129: Don't strip punctuation inside quotes in history search queries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add unit tests to verify fix. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/history/text_database_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/history/query_parser.cc
diff --git a/chrome/browser/history/query_parser.cc b/chrome/browser/history/query_parser.cc
index 782c708010cf2b9b8ef0ed7216f6740a95c8b4aa..181dc2135a04345d4ec534ecc3ed0b843ddd0fbc 100644
--- a/chrome/browser/history/query_parser.cc
+++ b/chrome/browser/history/query_parser.cc
@@ -80,6 +80,7 @@ class QueryNodeWord : public QueryNode {
const string16& word() const { return word_; }
void set_literal(bool literal) { literal_ = literal; }
+ void AppendText(const string16& text) { word_ += text; }
mrossetti 2012/02/07 01:05:57 We generally only inline simple getters and setter
// QueryNode:
virtual int AppendToSQLiteQuery(string16* query) const OVERRIDE;
@@ -365,27 +366,32 @@ bool QueryParser::ParseQueryImpl(const string16& query, QueryNodeList* root) {
query_stack.push_back(root);
bool in_quotes = false; // whether we're currently in a quoted phrase
+ QueryNodeWord* current_word = NULL;
while (iter.Advance()) {
// Just found a span between 'prev' (inclusive) and 'pos' (exclusive). It
// 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());
- if (in_quotes)
- word_node->set_literal(true);
- query_stack.back()->AddChild(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);
- in_quotes = true;
- } else {
- query_stack.pop_back(); // Stop adding to the quoted phrase.
- in_quotes = false;
- }
+ 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);
+ in_quotes = true;
+ } else {
+ query_stack.pop_back(); // Stop adding to the quoted phrase.
+ in_quotes = false;
}
+ current_word = NULL;
+ } else if (iter.IsWord() || in_quotes) {
mrossetti 2012/02/07 01:05:57 Okay, as you can see from the unit tests, trying t
+ if (current_word) {
+ current_word->AppendText(iter.GetString());
+ } else {
+ current_word = new QueryNodeWord(iter.GetString());
+ query_stack.back()->AddChild(current_word);
mrossetti 2012/02/07 01:05:57 Do the set_literal here...
+ }
+ if (in_quotes)
mrossetti 2012/02/07 01:05:57 ...not here.
+ current_word->set_literal(true);
+ } else { // Punctuation or whitespace outside quotes.
mrossetti 2012/02/07 01:05:57 These empty braces are just screaming for somethin
}
}
« no previous file with comments | « no previous file | chrome/browser/history/text_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698