OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_BOOKMARKS_BROWSER_TITLED_URL_MATCH_H_ | 5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_TITLED_URL_MATCH_H_ |
6 #define COMPONENTS_BOOKMARKS_BROWSER_TITLED_URL_MATCH_H_ | 6 #define COMPONENTS_BOOKMARKS_BROWSER_TITLED_URL_MATCH_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <cstddef> | 10 #include <cstddef> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/strings/string16.h" | |
15 | |
14 namespace bookmarks { | 16 namespace bookmarks { |
15 | 17 |
16 class TitledUrlNode; | 18 class TitledUrlNode; |
17 | 19 |
18 struct TitledUrlMatch { | 20 struct TitledUrlMatch { |
19 // Each MatchPosition is the [begin, end) positions of a match within a | 21 // Each MatchPosition is the [begin, end) positions of a match within a |
20 // string. | 22 // string. |
21 using MatchPosition = std::pair<size_t, size_t>; | 23 using MatchPosition = std::pair<size_t, size_t>; |
22 using MatchPositions = std::vector<MatchPosition>; | 24 using MatchPositions = std::vector<MatchPosition>; |
23 | 25 |
24 TitledUrlMatch(); | 26 TitledUrlMatch(); |
25 TitledUrlMatch(const TitledUrlMatch& other); | 27 TitledUrlMatch(const TitledUrlMatch& other); |
26 ~TitledUrlMatch(); | 28 ~TitledUrlMatch(); |
27 | 29 |
28 // Extracts and returns the offsets from |match_positions|. | 30 // Extracts and returns the offsets from |match_positions|. |
29 static std::vector<size_t> OffsetsFromMatchPositions( | 31 static std::vector<size_t> OffsetsFromMatchPositions( |
30 const MatchPositions& match_positions); | 32 const MatchPositions& match_positions); |
31 | 33 |
32 // Replaces the offsets in |match_positions| with those given in |offsets|, | 34 // Replaces the offsets in |match_positions| with those given in |offsets|, |
33 // deleting any which are npos, and returns the updated list of match | 35 // deleting any which are npos, and returns the updated list of match |
34 // positions. | 36 // positions. |
35 static MatchPositions ReplaceOffsetsInMatchPositions( | 37 static MatchPositions ReplaceOffsetsInMatchPositions( |
36 const MatchPositions& match_positions, | 38 const MatchPositions& match_positions, |
37 const std::vector<size_t>& offsets); | 39 const std::vector<size_t>& offsets); |
38 | 40 |
41 // Removes leading spaces from |title| before displaying, otherwise it looks | |
42 // funny. In the process, corrects |title_match_positions| so the correct | |
43 // characters are highlighted. | |
44 static void CorrectTitleAndMatchPositions( | |
45 base::string16* title, MatchPositions* title_match_positions); | |
Mark P
2016/12/23 22:38:49
nit: This parameter spacing looks odd to me. Did
mattreynolds
2017/01/04 00:58:02
Done.
| |
46 | |
39 // The matching node of a query. | 47 // The matching node of a query. |
40 const TitledUrlNode* node; | 48 const TitledUrlNode* node; |
41 | 49 |
42 // Location of the matching words in the title of the node. | 50 // Location of the matching words in the title of the node. |
43 MatchPositions title_match_positions; | 51 MatchPositions title_match_positions; |
44 | 52 |
45 // Location of the matching words in the URL of the node. | 53 // Location of the matching words in the URL of the node. |
46 MatchPositions url_match_positions; | 54 MatchPositions url_match_positions; |
47 }; | 55 }; |
48 | 56 |
49 } // namespace bookmarks | 57 } // namespace bookmarks |
50 | 58 |
51 #endif // COMPONENTS_BOOKMARKS_BROWSER_TITLED_URL_MATCH_H_ | 59 #endif // COMPONENTS_BOOKMARKS_BROWSER_TITLED_URL_MATCH_H_ |
OLD | NEW |