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

Side by Side Diff: ui/app_list/search/tokenized_string_match.h

Issue 522683003: Move basic string operations to ui/app_list/search (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gn Created 6 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
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 #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_TOKENIZED_STRING_MATCH_H_ 5 #ifndef UI_APP_LIST_SEARCH_TOKENIZED_STRING_MATCH_H_
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_TOKENIZED_STRING_MATCH_H_ 6 #define UI_APP_LIST_SEARCH_TOKENIZED_STRING_MATCH_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "ui/app_list/app_list_export.h"
12 #include "ui/gfx/range/range.h" 13 #include "ui/gfx/range/range.h"
13 14
14 namespace app_list { 15 namespace app_list {
15 16
16 class TokenizedString; 17 class TokenizedString;
17 18
18 // TokenizedStringMatch takes two tokenized strings: one as the text and 19 // TokenizedStringMatch takes two tokenized strings: one as the text and
19 // the other one as the query. It matches the query against the text, 20 // the other one as the query. It matches the query against the text,
20 // calculates a relevance score between [0, 1] and marks the matched portions 21 // calculates a relevance score between [0, 1] and marks the matched portions
21 // of text. A relevance of zero means the two are completely different to each 22 // of text. A relevance of zero means the two are completely different to each
22 // other. The higher the relevance score, the better the two strings are 23 // other. The higher the relevance score, the better the two strings are
23 // matched. Matched portions of text are stored as index ranges. 24 // matched. Matched portions of text are stored as index ranges.
24 class TokenizedStringMatch { 25 class APP_LIST_EXPORT TokenizedStringMatch {
25 public: 26 public:
26 typedef std::vector<gfx::Range> Hits; 27 typedef std::vector<gfx::Range> Hits;
27 28
28 TokenizedStringMatch(); 29 TokenizedStringMatch();
29 ~TokenizedStringMatch(); 30 ~TokenizedStringMatch();
30 31
31 // Calculates the relevance and hits. Returns true if the two strings are 32 // Calculates the relevance and hits. Returns true if the two strings are
32 // somewhat matched, i.e. relevance score is not zero. 33 // somewhat matched, i.e. relevance score is not zero.
33 bool Calculate(const TokenizedString& query, const TokenizedString& text); 34 bool Calculate(const TokenizedString& query, const TokenizedString& text);
34 35
35 // Convenience wrapper to calculate match from raw string input. 36 // Convenience wrapper to calculate match from raw string input.
36 bool Calculate(const base::string16& query, const base::string16& text); 37 bool Calculate(const base::string16& query, const base::string16& text);
37 38
38 double relevance() const { return relevance_; } 39 double relevance() const { return relevance_; }
39 const Hits& hits() const { return hits_; } 40 const Hits& hits() const { return hits_; }
40 41
41 private: 42 private:
42 // Score in range of [0,1] representing how well the query matches the text. 43 // Score in range of [0,1] representing how well the query matches the text.
43 double relevance_; 44 double relevance_;
44 45
45 // Char index ranges in |text| of where matches are found. 46 // Char index ranges in |text| of where matches are found.
46 Hits hits_; 47 Hits hits_;
47 48
48 DISALLOW_COPY_AND_ASSIGN(TokenizedStringMatch); 49 DISALLOW_COPY_AND_ASSIGN(TokenizedStringMatch);
49 }; 50 };
50 51
51 } // namespace app_list 52 } // namespace app_list
52 53
53 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_TOKENIZED_STRING_MATCH_H_ 54 #endif // UI_APP_LIST_SEARCH_TOKENIZED_STRING_MATCH_H_
OLDNEW
« no previous file with comments | « ui/app_list/search/tokenized_string_char_iterator_unittest.cc ('k') | ui/app_list/search/tokenized_string_match.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698