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

Side by Side Diff: chrome/browser/safe_browsing/chunk_range.cc

Issue 1240183002: Update SplitString calls in chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 (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 // Implementation of ChunkRange class. 5 // Implementation of ChunkRange class.
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "chrome/browser/safe_browsing/chunk_range.h" 9 #include "chrome/browser/safe_browsing/chunk_range.h"
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 } 63 }
64 } 64 }
65 65
66 bool StringToRanges(const std::string& input, 66 bool StringToRanges(const std::string& input,
67 std::vector<ChunkRange>* ranges) { 67 std::vector<ChunkRange>* ranges) {
68 DCHECK(ranges); 68 DCHECK(ranges);
69 69
70 // Crack the string into chunk parts, then crack each part looking for a 70 // Crack the string into chunk parts, then crack each part looking for a
71 // range. 71 // range.
72 std::vector<std::string> chunk_parts; 72 for (const base::StringPiece& chunk : base::SplitStringPiece(
73 base::SplitString(input, ',', &chunk_parts); 73 input, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
74 74 std::vector<std::string> chunk_ranges = base::SplitString(
75 for (size_t i = 0; i < chunk_parts.size(); ++i) { 75 chunk, "-", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
76 std::vector<std::string> chunk_ranges;
77 base::SplitString(chunk_parts[i], '-', &chunk_ranges);
78 int start = atoi(chunk_ranges[0].c_str()); 76 int start = atoi(chunk_ranges[0].c_str());
79 int stop = start; 77 int stop = start;
80 if (chunk_ranges.size() == 2) 78 if (chunk_ranges.size() == 2)
81 stop = atoi(chunk_ranges[1].c_str()); 79 stop = atoi(chunk_ranges[1].c_str());
82 if (start == 0 || stop == 0) { 80 if (start == 0 || stop == 0) {
83 // atoi error, since chunk numbers are guaranteed to never be 0. 81 // atoi error, since chunk numbers are guaranteed to never be 0.
84 ranges->clear(); 82 ranges->clear();
85 return false; 83 return false;
86 } 84 }
87 ranges->push_back(ChunkRange(start, stop)); 85 ranges->push_back(ChunkRange(start, stop));
(...skipping 19 matching lines...) Expand all
107 105
108 // Adjust our mid point. 106 // Adjust our mid point.
109 if (chunk.stop() < chunk_number) 107 if (chunk.stop() < chunk_number)
110 low = mid + 1; 108 low = mid + 1;
111 else 109 else
112 high = mid - 1; 110 high = mid - 1;
113 } 111 }
114 112
115 return false; 113 return false;
116 } 114 }
OLDNEW
« no previous file with comments | « chrome/browser/push_messaging/push_messaging_app_identifier.cc ('k') | chrome/browser/safe_browsing/safe_browsing_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698