| 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 // Implementation of ChunkRange class. | 5 // Implementation of ChunkRange class. |
| 6 | 6 |
| 7 #include "chrome/browser/safe_browsing/chunk_range.h" | 7 #include "chrome/browser/safe_browsing/chunk_range.h" |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } else { | 66 } else { |
| 67 result->append(StringPrintf("%d-%d", it->start(), it->stop())); | 67 result->append(StringPrintf("%d-%d", it->start(), it->stop())); |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 bool StringToRanges(const std::string& input, | 72 bool StringToRanges(const std::string& input, |
| 73 std::vector<ChunkRange>* ranges) { | 73 std::vector<ChunkRange>* ranges) { |
| 74 DCHECK(ranges); | 74 DCHECK(ranges); |
| 75 | 75 |
| 76 // Crack the string into chunk parts, then crack each part looking for a range
. | 76 // Crack the string into chunk parts, then crack each part looking for a |
| 77 // range. |
| 77 std::vector<std::string> chunk_parts; | 78 std::vector<std::string> chunk_parts; |
| 78 SplitString(input, ',', &chunk_parts); | 79 SplitString(input, ',', &chunk_parts); |
| 79 | 80 |
| 80 for (size_t i = 0; i < chunk_parts.size(); ++i) { | 81 for (size_t i = 0; i < chunk_parts.size(); ++i) { |
| 81 std::vector<std::string> chunk_ranges; | 82 std::vector<std::string> chunk_ranges; |
| 82 SplitString(chunk_parts[i], '-', &chunk_ranges); | 83 SplitString(chunk_parts[i], '-', &chunk_ranges); |
| 83 int start = atoi(chunk_ranges[0].c_str()); | 84 int start = atoi(chunk_ranges[0].c_str()); |
| 84 int stop = start; | 85 int stop = start; |
| 85 if (chunk_ranges.size() == 2) | 86 if (chunk_ranges.size() == 2) |
| 86 stop = atoi(chunk_ranges[1].c_str()); | 87 stop = atoi(chunk_ranges[1].c_str()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 113 // Adjust our mid point. | 114 // Adjust our mid point. |
| 114 if (chunk.stop() < chunk_number) | 115 if (chunk.stop() < chunk_number) |
| 115 low = mid + 1; | 116 low = mid + 1; |
| 116 else | 117 else |
| 117 high = mid - 1; | 118 high = mid - 1; |
| 118 } | 119 } |
| 119 | 120 |
| 120 return false; | 121 return false; |
| 121 } | 122 } |
| 122 | 123 |
| OLD | NEW |