| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 void RangesToString(const std::vector<ChunkRange>& ranges, | 55 void RangesToString(const std::vector<ChunkRange>& ranges, |
| 56 std::string* result) { | 56 std::string* result) { |
| 57 DCHECK(result); | 57 DCHECK(result); |
| 58 result->clear(); | 58 result->clear(); |
| 59 std::vector<ChunkRange>::const_iterator it = ranges.begin(); | 59 std::vector<ChunkRange>::const_iterator it = ranges.begin(); |
| 60 for (; it != ranges.end(); ++it) { | 60 for (; it != ranges.end(); ++it) { |
| 61 if (!result->empty()) | 61 if (!result->empty()) |
| 62 result->append(","); | 62 result->append(","); |
| 63 if (it->start() == it->stop()) { | 63 if (it->start() == it->stop()) { |
| 64 char num_buf[11]; // One 32 bit positive integer + NULL. | 64 std::string num_buf = IntToString(it->start()); |
| 65 _itoa_s(it->start(), num_buf, sizeof(num_buf), 10); | |
| 66 result->append(num_buf); | 65 result->append(num_buf); |
| 67 } else { | 66 } else { |
| 68 result->append(StringPrintf("%d-%d", it->start(), it->stop())); | 67 result->append(StringPrintf("%d-%d", it->start(), it->stop())); |
| 69 } | 68 } |
| 70 } | 69 } |
| 71 } | 70 } |
| 72 | 71 |
| 73 bool StringToRanges(const std::string& input, | 72 bool StringToRanges(const std::string& input, |
| 74 std::vector<ChunkRange>* ranges) { | 73 std::vector<ChunkRange>* ranges) { |
| 75 DCHECK(ranges); | 74 DCHECK(ranges); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 88 if (start == 0 || stop == 0) { | 87 if (start == 0 || stop == 0) { |
| 89 // atoi error, since chunk numbers are guaranteed to never be 0. | 88 // atoi error, since chunk numbers are guaranteed to never be 0. |
| 90 ranges->clear(); | 89 ranges->clear(); |
| 91 return false; | 90 return false; |
| 92 } | 91 } |
| 93 ranges->push_back(ChunkRange(start, stop)); | 92 ranges->push_back(ChunkRange(start, stop)); |
| 94 } | 93 } |
| 95 | 94 |
| 96 return true; | 95 return true; |
| 97 } | 96 } |
| OLD | NEW |