| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_BROWSER_HISTORY_SNIPPET_H__ | 8 #ifndef CHROME_BROWSER_HISTORY_SNIPPET_H__ |
| 9 #define CHROME_BROWSER_HISTORY_SNIPPET_H__ | 9 #define CHROME_BROWSER_HISTORY_SNIPPET_H__ |
| 10 #pragma once | 10 #pragma once |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 static void ExtractMatchPositions(const std::string& offsets_str, | 36 static void ExtractMatchPositions(const std::string& offsets_str, |
| 37 const std::string& column_num, | 37 const std::string& column_num, |
| 38 MatchPositions* match_positions); | 38 MatchPositions* match_positions); |
| 39 | 39 |
| 40 // Converts match positions as returned from ExtractMatchPositions to be in | 40 // Converts match positions as returned from ExtractMatchPositions to be in |
| 41 // terms of a wide string. | 41 // terms of a wide string. |
| 42 static void ConvertMatchPositionsToWide( | 42 static void ConvertMatchPositionsToWide( |
| 43 const std::string& utf8_string, | 43 const std::string& utf8_string, |
| 44 Snippet::MatchPositions* match_positions); | 44 Snippet::MatchPositions* match_positions); |
| 45 | 45 |
| 46 Snippet(); |
| 47 ~Snippet(); |
| 48 |
| 46 // Given |matches|, the match positions within |document|, compute the snippet | 49 // Given |matches|, the match positions within |document|, compute the snippet |
| 47 // for the document. | 50 // for the document. |
| 48 // Note that |document| is UTF-8 and the offsets in |matches| are byte | 51 // Note that |document| is UTF-8 and the offsets in |matches| are byte |
| 49 // offsets. | 52 // offsets. |
| 50 void ComputeSnippet(const MatchPositions& matches, | 53 void ComputeSnippet(const MatchPositions& matches, |
| 51 const std::string& document); | 54 const std::string& document); |
| 52 | 55 |
| 53 const string16& text() const { return text_; } | 56 const string16& text() const { return text_; } |
| 54 const MatchPositions& matches() const { return matches_; } | 57 const MatchPositions& matches() const { return matches_; } |
| 55 | 58 |
| 56 // Efficiently swaps the contents of this snippet with the other. | 59 // Efficiently swaps the contents of this snippet with the other. |
| 57 void Swap(Snippet* other) { | 60 void Swap(Snippet* other); |
| 58 text_.swap(other->text_); | |
| 59 matches_.swap(other->matches_); | |
| 60 } | |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 // The text of the snippet. | 63 // The text of the snippet. |
| 64 string16 text_; | 64 string16 text_; |
| 65 | 65 |
| 66 // The matches within text_. | 66 // The matches within text_. |
| 67 MatchPositions matches_; | 67 MatchPositions matches_; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 #endif // CHROME_BROWSER_HISTORY_SNIPPET_H__ | 70 #endif // CHROME_BROWSER_HISTORY_SNIPPET_H__ |
| OLD | NEW |