| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } // namespace | 160 } // namespace |
| 161 | 161 |
| 162 // static | 162 // static |
| 163 void Snippet::ExtractMatchPositions(const std::string& offsets_str, | 163 void Snippet::ExtractMatchPositions(const std::string& offsets_str, |
| 164 const std::string& column_num, | 164 const std::string& column_num, |
| 165 MatchPositions* match_positions) { | 165 MatchPositions* match_positions) { |
| 166 DCHECK(match_positions); | 166 DCHECK(match_positions); |
| 167 if (offsets_str.empty()) | 167 if (offsets_str.empty()) |
| 168 return; | 168 return; |
| 169 std::vector<std::string> offsets; | 169 std::vector<std::string> offsets; |
| 170 SplitString(offsets_str, ' ', &offsets); | 170 base::SplitString(offsets_str, ' ', &offsets); |
| 171 // SQLite offsets are sets of four integers: | 171 // SQLite offsets are sets of four integers: |
| 172 // column, query term, match offset, match length | 172 // column, query term, match offset, match length |
| 173 // Matches within a string are marked by (start, end) pairs. | 173 // Matches within a string are marked by (start, end) pairs. |
| 174 for (size_t i = 0; i < offsets.size() - 3; i += 4) { | 174 for (size_t i = 0; i < offsets.size() - 3; i += 4) { |
| 175 if (offsets[i] != column_num) | 175 if (offsets[i] != column_num) |
| 176 continue; | 176 continue; |
| 177 const size_t start = atoi(offsets[i + 2].c_str()); | 177 const size_t start = atoi(offsets[i + 2].c_str()); |
| 178 const size_t end = start + atoi(offsets[i + 3].c_str()); | 178 const size_t end = start + atoi(offsets[i + 3].c_str()); |
| 179 // Switch to DCHECK after debugging http://crbug.com/15261. | 179 // Switch to DCHECK after debugging http://crbug.com/15261. |
| 180 CHECK(end >= start); | 180 CHECK(end >= start); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 } | 288 } |
| 289 | 289 |
| 290 utext_close(document_utext); | 290 utext_close(document_utext); |
| 291 swap(text_, snippet); | 291 swap(text_, snippet); |
| 292 } | 292 } |
| 293 | 293 |
| 294 void Snippet::Swap(Snippet* other) { | 294 void Snippet::Swap(Snippet* other) { |
| 295 text_.swap(other->text_); | 295 text_.swap(other->text_); |
| 296 matches_.swap(other->matches_); | 296 matches_.swap(other->matches_); |
| 297 } | 297 } |
| OLD | NEW |