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_BOOKMARK_MATCH_H_ | 5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_TITLED_URL_MATCH_H_ |
6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_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 namespace bookmarks { | 14 namespace bookmarks { |
15 | 15 |
16 class TitledUrlNode; | 16 class TitledUrlNode; |
17 | 17 |
18 struct BookmarkMatch { | 18 struct TitledUrlMatch { |
19 // Each MatchPosition is the [begin, end) positions of a match within a | 19 // Each MatchPosition is the [begin, end) positions of a match within a |
20 // string. | 20 // string. |
21 using MatchPosition = std::pair<size_t, size_t>; | 21 using MatchPosition = std::pair<size_t, size_t>; |
22 using MatchPositions = std::vector<MatchPosition>; | 22 using MatchPositions = std::vector<MatchPosition>; |
23 | 23 |
24 BookmarkMatch(); | 24 TitledUrlMatch(); |
25 BookmarkMatch(const BookmarkMatch& other); | 25 TitledUrlMatch(const TitledUrlMatch& other); |
26 ~BookmarkMatch(); | 26 ~TitledUrlMatch(); |
27 | 27 |
28 // Extracts and returns the offsets from |match_positions|. | 28 // Extracts and returns the offsets from |match_positions|. |
29 static std::vector<size_t> OffsetsFromMatchPositions( | 29 static std::vector<size_t> OffsetsFromMatchPositions( |
30 const MatchPositions& match_positions); | 30 const MatchPositions& match_positions); |
31 | 31 |
32 // Replaces the offsets in |match_positions| with those given in |offsets|, | 32 // Replaces the offsets in |match_positions| with those given in |offsets|, |
33 // deleting any which are npos, and returns the updated list of match | 33 // deleting any which are npos, and returns the updated list of match |
34 // positions. | 34 // positions. |
35 static MatchPositions ReplaceOffsetsInMatchPositions( | 35 static MatchPositions ReplaceOffsetsInMatchPositions( |
36 const MatchPositions& match_positions, | 36 const MatchPositions& match_positions, |
37 const std::vector<size_t>& offsets); | 37 const std::vector<size_t>& offsets); |
38 | 38 |
39 // The matching node of a query. | 39 // The matching node of a query. |
40 const TitledUrlNode* node; | 40 const TitledUrlNode* node; |
41 | 41 |
42 // Location of the matching words in the title of the node. | 42 // Location of the matching words in the title of the node. |
43 MatchPositions title_match_positions; | 43 MatchPositions title_match_positions; |
44 | 44 |
45 // Location of the matching words in the URL of the node. | 45 // Location of the matching words in the URL of the node. |
46 MatchPositions url_match_positions; | 46 MatchPositions url_match_positions; |
47 }; | 47 }; |
48 | 48 |
49 } // namespace bookmarks | 49 } // namespace bookmarks |
50 | 50 |
51 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MATCH_H_ | 51 #endif // COMPONENTS_BOOKMARKS_BROWSER_TITLED_URL_MATCH_H_ |
OLD | NEW |