Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Side by Side Diff: base/version.cc

Issue 952893003: Update from https://crrev.com/317530 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fix gn for nacl Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/trace_event/trace_event_synthetic_delay.cc ('k') | base/version_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « base/trace_event/trace_event_synthetic_delay.cc ('k') | base/version_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698