| 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; | |
| 36 int num; | 34 int num; |
| 37 if (!StringToInt(*it, &num)) | 35 if (!StringToInt(*it, &num)) |
| 38 return false; | 36 return false; |
| 39 | 37 |
| 40 if (num < 0) | 38 if (num < 0) |
| 41 return false; | 39 return false; |
| 42 | 40 |
| 43 const uint16 max = 0xFFFF; | 41 const uint16 max = 0xFFFF; |
| 44 if (num > max) | 42 if (num > max) |
| 45 return false; | 43 return false; |
| 46 | 44 |
| 47 // This throws out leading zeros for the first item only. | 45 // This throws out things like +3, or 032. |
| 48 if (it == numbers.begin() && IntToString(num) != *it) | 46 if (IntToString(num) != *it) |
| 49 return false; | 47 return false; |
| 50 | 48 |
| 51 parsed->push_back(static_cast<uint16>(num)); | 49 parsed->push_back(static_cast<uint16>(num)); |
| 52 } | 50 } |
| 53 return true; | 51 return true; |
| 54 } | 52 } |
| 55 | 53 |
| 56 // Compares version components in |components1| with components in | 54 // Compares version components in |components1| with components in |
| 57 // |components2|. Returns -1, 0 or 1 if |components1| is less than, equal to, | 55 // |components2|. Returns -1, 0 or 1 if |components1| is less than, equal to, |
| 58 // or greater than |components2|, respectively. | 56 // or greater than |components2|, respectively. |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 size_t count = components_.size(); | 169 size_t count = components_.size(); |
| 172 for (size_t i = 0; i < count - 1; ++i) { | 170 for (size_t i = 0; i < count - 1; ++i) { |
| 173 version_str.append(IntToString(components_[i])); | 171 version_str.append(IntToString(components_[i])); |
| 174 version_str.append("."); | 172 version_str.append("."); |
| 175 } | 173 } |
| 176 version_str.append(IntToString(components_[count - 1])); | 174 version_str.append(IntToString(components_[count - 1])); |
| 177 return version_str; | 175 return version_str; |
| 178 } | 176 } |
| 179 | 177 |
| 180 } // namespace base | 178 } // namespace base |
| OLD | NEW |