| 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 15 matching lines...) Expand all Loading... |
| 26 // The information is encoded in the string as a set of matches, where each | 26 // The information is encoded in the string as a set of matches, where each |
| 27 // match consists of the column, term-number, location, and length of the | 27 // match consists of the column, term-number, location, and length of the |
| 28 // match. Each element of the match is separated by a space, as is each match | 28 // match. Each element of the match is separated by a space, as is each match |
| 29 // from other matches. | 29 // from other matches. |
| 30 // | 30 // |
| 31 // This method adds the start and end of each match whose column is | 31 // This method adds the start and end of each match whose column is |
| 32 // column_num to match_positions. The pairs are ordered based on first, | 32 // column_num to match_positions. The pairs are ordered based on first, |
| 33 // with no overlapping elements. | 33 // with no overlapping elements. |
| 34 // | 34 // |
| 35 // NOTE: the positions returned are in terms of UTF8 encoding. To convert the | 35 // NOTE: the positions returned are in terms of UTF8 encoding. To convert the |
| 36 // offsets to wide, use ConvertMatchPositionsToWide. | 36 // offsets to UTF-16, use ConvertMatchPositionsToWide |
| 37 static void ExtractMatchPositions(const std::string& offsets_str, | 37 static void ExtractMatchPositions(const std::string& offsets_str, |
| 38 const std::string& column_num, | 38 const std::string& column_num, |
| 39 MatchPositions* match_positions); | 39 MatchPositions* match_positions); |
| 40 | 40 |
| 41 // Converts match positions as returned from ExtractMatchPositions to be in | 41 // Converts match positions as returned from ExtractMatchPositions to be in |
| 42 // terms of a wide string. | 42 // terms of a UTF-16 2-byte code unit. |
| 43 static void ConvertMatchPositionsToWide( | 43 static void ConvertMatchPositionsToWide( |
| 44 const std::string& utf8_string, | 44 const std::string& utf8_string, |
| 45 Snippet::MatchPositions* match_positions); | 45 Snippet::MatchPositions* match_positions); |
| 46 | 46 |
| 47 Snippet(); | 47 Snippet(); |
| 48 ~Snippet(); | 48 ~Snippet(); |
| 49 | 49 |
| 50 // Given |matches|, the match positions within |document|, compute the snippet | 50 // Given |matches|, the match positions within |document|, compute the snippet |
| 51 // for the document. | 51 // for the document. |
| 52 // Note that |document| is UTF-8 and the offsets in |matches| are byte | 52 // Note that |document| is UTF-8 and the offsets in |matches| are byte |
| (...skipping 11 matching lines...) Expand all Loading... |
| 64 // The text of the snippet. | 64 // The text of the snippet. |
| 65 base::string16 text_; | 65 base::string16 text_; |
| 66 | 66 |
| 67 // The matches within text_. | 67 // The matches within text_. |
| 68 MatchPositions matches_; | 68 MatchPositions matches_; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 } // namespace query_parser | 71 } // namespace query_parser |
| 72 | 72 |
| 73 #endif // COMPONENTS_QUERY_PARSER_SNIPPET_H__ | 73 #endif // COMPONENTS_QUERY_PARSER_SNIPPET_H__ |
| OLD | NEW |