| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/version.h" | 5 #include "base/version.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // parsed successfully, false otherwise. | 24 // parsed successfully, false otherwise. |
| 25 bool ParseVersionNumbers(const std::string& version_str, | 25 bool ParseVersionNumbers(const std::string& version_str, |
| 26 std::vector<uint16>* parsed) { | 26 std::vector<uint16>* parsed) { |
| 27 std::vector<std::string> numbers; | 27 std::vector<std::string> numbers; |
| 28 SplitString(version_str, '.', &numbers); | 28 SplitString(version_str, '.', &numbers); |
| 29 if (numbers.empty()) | 29 if (numbers.empty()) |
| 30 return false; | 30 return false; |
| 31 | 31 |
| 32 for (std::vector<std::string>::const_iterator it = numbers.begin(); | 32 for (std::vector<std::string>::const_iterator it = numbers.begin(); |
| 33 it != numbers.end(); ++it) { | 33 it != numbers.end(); ++it) { |
| 34 if (StartsWithASCII(*it, "+", false)) |
| 35 return false; |
| 34 int num; | 36 int num; |
| 35 if (!StringToInt(*it, &num)) | 37 if (!StringToInt(*it, &num)) |
| 36 return false; | 38 return false; |
| 37 | 39 |
| 38 if (num < 0) | 40 if (num < 0) |
| 39 return false; | 41 return false; |
| 40 | 42 |
| 41 const uint16 max = 0xFFFF; | 43 const uint16 max = 0xFFFF; |
| 42 if (num > max) | 44 if (num > max) |
| 43 return false; | 45 return false; |
| 44 | 46 |
| 45 // This throws out things like +3, or 032. | 47 // This throws out leading zeros for the first item only. |
| 46 if (IntToString(num) != *it) | 48 if (it == numbers.begin() && IntToString(num) != *it) |
| 47 return false; | 49 return false; |
| 48 | 50 |
| 49 parsed->push_back(static_cast<uint16>(num)); | 51 parsed->push_back(static_cast<uint16>(num)); |
| 50 } | 52 } |
| 51 return true; | 53 return true; |
| 52 } | 54 } |
| 53 | 55 |
| 54 // Compares version components in |components1| with components in | 56 // Compares version components in |components1| with components in |
| 55 // |components2|. Returns -1, 0 or 1 if |components1| is less than, equal to, | 57 // |components2|. Returns -1, 0 or 1 if |components1| is less than, equal to, |
| 56 // or greater than |components2|, respectively. | 58 // or greater than |components2|, respectively. |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 size_t count = components_.size(); | 171 size_t count = components_.size(); |
| 170 for (size_t i = 0; i < count - 1; ++i) { | 172 for (size_t i = 0; i < count - 1; ++i) { |
| 171 version_str.append(IntToString(components_[i])); | 173 version_str.append(IntToString(components_[i])); |
| 172 version_str.append("."); | 174 version_str.append("."); |
| 173 } | 175 } |
| 174 version_str.append(IntToString(components_[count - 1])); | 176 version_str.append(IntToString(components_[count - 1])); |
| 175 return version_str; | 177 return version_str; |
| 176 } | 178 } |
| 177 | 179 |
| 178 } // namespace base | 180 } // namespace base |
| OLD | NEW |