Parses the |numbers| vector representing the different numbers inside the version string and constructs a vector of valid integers. It stops when it reaches an invalid item (including the wildcard character). |parsed| is the resulting integer vector. Function returns true if all numbers were parsed successfully, false otherwise.
| 23 | // is the resulting integer vector. Function returns true if all numbers were |
| 24 | // parsed successfully, false otherwise. |
| 25 | bool ParseVersionNumbers(const std::string& version_str, |
| 26 | std::vector<uint16_t>* parsed) { |
| 27 | std::vector<std::string> numbers; |
| 28 | SplitString(version_str, '.', &numbers); |
| 29 | if (numbers.empty()) |
| 30 | return false; |
| 31 | |
| 32 | for (std::vector<std::string>::const_iterator it = numbers.begin(); |
| 33 | it != numbers.end(); ++it) { |
| 34 | int num; |
| 35 | if (!StringToInt(*it, &num)) |
| 36 | return false; |
| 37 | |
| 38 | if (num < 0) |
| 39 | return false; |
| 40 | |
| 41 | const uint16_t max = 0xFFFF; |
| 42 | if (num > max) |
| 43 | return false; |
| 44 | |
| 45 | // This throws out things like +3, or 032. |
| 46 | if (IntToString(num) != *it) |
| 47 | return false; |
| 48 | |
| 49 | parsed->push_back(static_cast<uint16_t>(num)); |
| 50 | } |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | // Compares version components in |components1| with components in |
| 55 | // |components2|. Returns -1, 0 or 1 if |components1| is less than, equal to, |
no test coverage detected