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

Side by Side Diff: webkit/plugins/npapi/plugin_utils.cc

Issue 10823434: [6] Moves CreateVersionFromString to plugin_utils and updates the callers. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added missing include <algorithm> Created 8 years, 3 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 | « webkit/plugins/npapi/plugin_utils.h ('k') | webkit/plugins/npapi/plugin_utils_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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "webkit/plugins/npapi/plugin_utils.h"
6
7 #include <algorithm>
8
9 #include "base/string_split.h"
10 #include "base/string_util.h"
11 #include "base/version.h"
12
13 namespace webkit {
14 namespace npapi {
15
16 void CreateVersionFromString(const string16& version_string,
17 Version* parsed_version) {
18 // Remove spaces and ')' from the version string,
19 // Replace any instances of 'r', ',' or '(' with a dot.
20 std::string version = UTF16ToASCII(version_string);
21 RemoveChars(version, ") ", &version);
22 std::replace(version.begin(), version.end(), 'd', '.');
23 std::replace(version.begin(), version.end(), 'r', '.');
24 std::replace(version.begin(), version.end(), ',', '.');
25 std::replace(version.begin(), version.end(), '(', '.');
26 std::replace(version.begin(), version.end(), '_', '.');
27
28 // Remove leading zeros from each of the version components.
29 std::string no_leading_zeros_version;
30 std::vector<std::string> numbers;
31 base::SplitString(version, '.', &numbers);
32 for (size_t i = 0; i < numbers.size(); ++i) {
33 size_t n = numbers[i].size();
34 size_t j = 0;
35 while (j < n && numbers[i][j] == '0') {
36 ++j;
37 }
38 no_leading_zeros_version += (j < n) ? numbers[i].substr(j) : "0";
39 if (i != numbers.size() - 1) {
40 no_leading_zeros_version += ".";
41 }
42 }
43
44 *parsed_version = Version(no_leading_zeros_version);
45 }
46
47 } // namespace npapi
48 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/npapi/plugin_utils.h ('k') | webkit/plugins/npapi/plugin_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698