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

Side by Side Diff: chrome/browser/ui/app_list/search/tokenized_string_match.cc

Issue 24012002: Move Range code to gfx. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: d Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/app_list/search/tokenized_string_match.h" 5 #include "chrome/browser/ui/app_list/search/tokenized_string_match.h"
6 6
7 #include "chrome/browser/ui/app_list/search/tokenized_string_char_iterator.h" 7 #include "chrome/browser/ui/app_list/search/tokenized_string_char_iterator.h"
8 8
9 namespace app_list { 9 namespace app_list {
10 10
(...skipping 29 matching lines...) Expand all
40 TokenizedStringMatch::TokenizedStringMatch() 40 TokenizedStringMatch::TokenizedStringMatch()
41 : relevance_(kNoMatchScore) {} 41 : relevance_(kNoMatchScore) {}
42 42
43 TokenizedStringMatch::~TokenizedStringMatch() {} 43 TokenizedStringMatch::~TokenizedStringMatch() {}
44 44
45 bool TokenizedStringMatch::Calculate(const TokenizedString& query, 45 bool TokenizedStringMatch::Calculate(const TokenizedString& query,
46 const TokenizedString& text) { 46 const TokenizedString& text) {
47 relevance_ = kNoMatchScore; 47 relevance_ = kNoMatchScore;
48 hits_.clear(); 48 hits_.clear();
49 49
50 ui::Range hit = ui::Range::InvalidRange(); 50 gfx::Range hit = gfx::Range::InvalidRange();
51 51
52 TokenizedStringCharIterator query_iter(query); 52 TokenizedStringCharIterator query_iter(query);
53 TokenizedStringCharIterator text_iter(text); 53 TokenizedStringCharIterator text_iter(text);
54 54
55 while (!query_iter.end() && !text_iter.end()) { 55 while (!query_iter.end() && !text_iter.end()) {
56 if (query_iter.Get() == text_iter.Get()) { 56 if (query_iter.Get() == text_iter.Get()) {
57 if (query_iter.GetArrayPos() == text_iter.GetArrayPos()) 57 if (query_iter.GetArrayPos() == text_iter.GetArrayPos())
58 relevance_ += kIsPrefixMultiplier; 58 relevance_ += kIsPrefixMultiplier;
59 else if (text_iter.IsFirstCharOfToken()) 59 else if (text_iter.IsFirstCharOfToken())
60 relevance_ += kIsFrontOfWordMultipler; 60 relevance_ += kIsFrontOfWordMultipler;
61 else 61 else
62 relevance_ += kIsWeakHitMultiplier; 62 relevance_ += kIsWeakHitMultiplier;
63 63
64 if (!hit.IsValid()) 64 if (!hit.IsValid())
65 hit.set_start(text_iter.GetArrayPos()); 65 hit.set_start(text_iter.GetArrayPos());
66 hit.set_end(text_iter.GetArrayPos() + text_iter.GetCharSize()); 66 hit.set_end(text_iter.GetArrayPos() + text_iter.GetCharSize());
67 67
68 query_iter.NextChar(); 68 query_iter.NextChar();
69 text_iter.NextChar(); 69 text_iter.NextChar();
70 } else { 70 } else {
71 if (hit.IsValid()) { 71 if (hit.IsValid()) {
72 hits_.push_back(hit); 72 hits_.push_back(hit);
73 hit = ui::Range::InvalidRange(); 73 hit = gfx::Range::InvalidRange();
74 } 74 }
75 75
76 text_iter.NextToken(); 76 text_iter.NextToken();
77 } 77 }
78 } 78 }
79 79
80 // No match if query is not fully consumed. 80 // No match if query is not fully consumed.
81 if (!query_iter.end()) { 81 if (!query_iter.end()) {
82 relevance_ = kNoMatchScore; 82 relevance_ = kNoMatchScore;
83 hits_.clear(); 83 hits_.clear();
(...skipping 12 matching lines...) Expand all
96 } 96 }
97 97
98 bool TokenizedStringMatch::Calculate(const string16& query, 98 bool TokenizedStringMatch::Calculate(const string16& query,
99 const string16& text) { 99 const string16& text) {
100 const TokenizedString tokenized_query(query); 100 const TokenizedString tokenized_query(query);
101 const TokenizedString tokenized_text(text); 101 const TokenizedString tokenized_text(text);
102 return Calculate(tokenized_query, tokenized_text); 102 return Calculate(tokenized_query, tokenized_text);
103 } 103 }
104 104
105 } // namespace app_list 105 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698