| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/history/snippet.h" | 5 #include "chrome/browser/history/snippet.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 const int32_t utf8_length = static_cast<int32_t>(utf8_string.size()); | 193 const int32_t utf8_length = static_cast<int32_t>(utf8_string.size()); |
| 194 for (Snippet::MatchPositions::iterator i = match_positions->begin(); | 194 for (Snippet::MatchPositions::iterator i = match_positions->begin(); |
| 195 i != match_positions->end(); ++i) { | 195 i != match_positions->end(); ++i) { |
| 196 i->first = AdvanceAndReturnUTF16Pos(utf8_cstring, utf8_length, | 196 i->first = AdvanceAndReturnUTF16Pos(utf8_cstring, utf8_length, |
| 197 i->first, &utf8_pos, &utf16_pos); | 197 i->first, &utf8_pos, &utf16_pos); |
| 198 i->second = AdvanceAndReturnUTF16Pos(utf8_cstring, utf8_length, | 198 i->second = AdvanceAndReturnUTF16Pos(utf8_cstring, utf8_length, |
| 199 i->second, &utf8_pos, &utf16_pos); | 199 i->second, &utf8_pos, &utf16_pos); |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 Snippet::Snippet() { |
| 204 } |
| 205 |
| 206 Snippet::~Snippet() { |
| 207 } |
| 208 |
| 203 void Snippet::ComputeSnippet(const MatchPositions& match_positions, | 209 void Snippet::ComputeSnippet(const MatchPositions& match_positions, |
| 204 const std::string& document) { | 210 const std::string& document) { |
| 205 // The length of snippets we try to produce. | 211 // The length of snippets we try to produce. |
| 206 // We can generate longer snippets but stop once we cross kSnippetMaxLength. | 212 // We can generate longer snippets but stop once we cross kSnippetMaxLength. |
| 207 const size_t kSnippetMaxLength = 200; | 213 const size_t kSnippetMaxLength = 200; |
| 208 const string16 kEllipsis = ASCIIToUTF16(" ... "); | 214 const string16 kEllipsis = ASCIIToUTF16(" ... "); |
| 209 | 215 |
| 210 UText* document_utext = NULL; | 216 UText* document_utext = NULL; |
| 211 UErrorCode status = U_ZERO_ERROR; | 217 UErrorCode status = U_ZERO_ERROR; |
| 212 document_utext = utext_openUTF8(document_utext, document.data(), | 218 document_utext = utext_openUTF8(document_utext, document.data(), |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 start = end; | 283 start = end; |
| 278 | 284 |
| 279 // Stop here if we have enough snippet computed. | 285 // Stop here if we have enough snippet computed. |
| 280 if (snippet.size() >= kSnippetMaxLength) | 286 if (snippet.size() >= kSnippetMaxLength) |
| 281 break; | 287 break; |
| 282 } | 288 } |
| 283 | 289 |
| 284 utext_close(document_utext); | 290 utext_close(document_utext); |
| 285 swap(text_, snippet); | 291 swap(text_, snippet); |
| 286 } | 292 } |
| 293 |
| 294 void Snippet::Swap(Snippet* other) { |
| 295 text_.swap(other->text_); |
| 296 matches_.swap(other->matches_); |
| 297 } |
| OLD | NEW |