Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: components/query_parser/snippet.cc

Issue 1234973004: Update SplitString calls in components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "components/query_parser/snippet.h" 5 #include "components/query_parser/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/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 } // namespace 161 } // namespace
162 162
163 // static 163 // static
164 void Snippet::ExtractMatchPositions(const std::string& offsets_str, 164 void Snippet::ExtractMatchPositions(const std::string& offsets_str,
165 const std::string& column_num, 165 const std::string& column_num,
166 MatchPositions* match_positions) { 166 MatchPositions* match_positions) {
167 DCHECK(match_positions); 167 DCHECK(match_positions);
168 if (offsets_str.empty()) 168 if (offsets_str.empty())
169 return; 169 return;
170 std::vector<std::string> offsets; 170 std::vector<std::string> offsets = base::SplitString(
171 base::SplitString(offsets_str, ' ', &offsets); 171 offsets_str, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
172 // SQLite offsets are sets of four integers: 172 // SQLite offsets are sets of four integers:
173 // column, query term, match offset, match length 173 // column, query term, match offset, match length
174 // Matches within a string are marked by (start, end) pairs. 174 // Matches within a string are marked by (start, end) pairs.
175 for (size_t i = 0; i < offsets.size() - 3; i += 4) { 175 for (size_t i = 0; i < offsets.size() - 3; i += 4) {
176 if (offsets[i] != column_num) 176 if (offsets[i] != column_num)
177 continue; 177 continue;
178 const size_t start = atoi(offsets[i + 2].c_str()); 178 const size_t start = atoi(offsets[i + 2].c_str());
179 const size_t end = start + atoi(offsets[i + 3].c_str()); 179 const size_t end = start + atoi(offsets[i + 3].c_str());
180 // Switch to DCHECK after debugging http://crbug.com/15261. 180 // Switch to DCHECK after debugging http://crbug.com/15261.
181 CHECK(end >= start); 181 CHECK(end >= start);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 utext_close(document_utext); 293 utext_close(document_utext);
294 swap(text_, snippet); 294 swap(text_, snippet);
295 } 295 }
296 296
297 void Snippet::Swap(Snippet* other) { 297 void Snippet::Swap(Snippet* other) {
298 text_.swap(other->text_); 298 text_.swap(other->text_);
299 matches_.swap(other->matches_); 299 matches_.swap(other->matches_);
300 } 300 }
301 301
302 } // namespace query_parser 302 } // namespace query_parser
OLDNEW
« no previous file with comments | « components/proximity_auth/bluetooth_util_chromeos.cc ('k') | components/query_parser/snippet_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698