| 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 // This module computes snippets of queries based on hits in the documents | 5 // This module computes snippets of queries based on hits in the documents |
| 6 // for display in history search results. | 6 // for display in history search results. |
| 7 | 7 |
| 8 #ifndef COMPONENTS_QUERY_PARSER_SNIPPET_H__ | 8 #ifndef COMPONENTS_QUERY_PARSER_SNIPPET_H__ |
| 9 #define COMPONENTS_QUERY_PARSER_SNIPPET_H__ | 9 #define COMPONENTS_QUERY_PARSER_SNIPPET_H__ |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 const std::string& column_num, | 40 const std::string& column_num, |
| 41 MatchPositions* match_positions); | 41 MatchPositions* match_positions); |
| 42 | 42 |
| 43 // Converts match positions as returned from ExtractMatchPositions to be in | 43 // Converts match positions as returned from ExtractMatchPositions to be in |
| 44 // terms of a UTF-16 2-byte code unit. | 44 // terms of a UTF-16 2-byte code unit. |
| 45 static void ConvertMatchPositionsToWide( | 45 static void ConvertMatchPositionsToWide( |
| 46 const std::string& utf8_string, | 46 const std::string& utf8_string, |
| 47 Snippet::MatchPositions* match_positions); | 47 Snippet::MatchPositions* match_positions); |
| 48 | 48 |
| 49 Snippet(); | 49 Snippet(); |
| 50 Snippet(const Snippet& other); |
| 50 ~Snippet(); | 51 ~Snippet(); |
| 51 | 52 |
| 52 // Given |matches|, the match positions within |document|, compute the snippet | 53 // Given |matches|, the match positions within |document|, compute the snippet |
| 53 // for the document. | 54 // for the document. |
| 54 // Note that |document| is UTF-8 and the offsets in |matches| are byte | 55 // Note that |document| is UTF-8 and the offsets in |matches| are byte |
| 55 // offsets. | 56 // offsets. |
| 56 void ComputeSnippet(const MatchPositions& matches, | 57 void ComputeSnippet(const MatchPositions& matches, |
| 57 const std::string& document); | 58 const std::string& document); |
| 58 | 59 |
| 59 const base::string16& text() const { return text_; } | 60 const base::string16& text() const { return text_; } |
| 60 const MatchPositions& matches() const { return matches_; } | 61 const MatchPositions& matches() const { return matches_; } |
| 61 | 62 |
| 62 // Efficiently swaps the contents of this snippet with the other. | 63 // Efficiently swaps the contents of this snippet with the other. |
| 63 void Swap(Snippet* other); | 64 void Swap(Snippet* other); |
| 64 | 65 |
| 65 private: | 66 private: |
| 66 // The text of the snippet. | 67 // The text of the snippet. |
| 67 base::string16 text_; | 68 base::string16 text_; |
| 68 | 69 |
| 69 // The matches within text_. | 70 // The matches within text_. |
| 70 MatchPositions matches_; | 71 MatchPositions matches_; |
| 71 }; | 72 }; |
| 72 | 73 |
| 73 } // namespace query_parser | 74 } // namespace query_parser |
| 74 | 75 |
| 75 #endif // COMPONENTS_QUERY_PARSER_SNIPPET_H__ | 76 #endif // COMPONENTS_QUERY_PARSER_SNIPPET_H__ |
| OLD | NEW |