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

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: Addressing jam@'s review comments 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
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 "base/string_split.h"
8 #include "base/string_util.h"
9 #include "base/version.h"
10
11 namespace webkit {
12 namespace npapi {
13
14 void CreateVersionFromString(const string16& version_string,
15 Version* parsed_version) {
16 // Remove spaces and ')' from the version string,
17 // Replace any instances of 'r', ',' or '(' with a dot.
18 std::string version = UTF16ToASCII(version_string);
19 RemoveChars(version, ") ", &version);
20 std::replace(version.begin(), version.end(), 'd', '.');
21 std::replace(version.begin(), version.end(), 'r', '.');
22 std::replace(version.begin(), version.end(), ',', '.');
23 std::replace(version.begin(), version.end(), '(', '.');
24 std::replace(version.begin(), version.end(), '_', '.');
25
26 // Remove leading zeros from each of the version components.
27 std::string no_leading_zeros_version;
28 std::vector<std::string> numbers;
29 base::SplitString(version, '.', &numbers);
30 for (size_t i = 0; i < numbers.size(); ++i) {
31 size_t n = numbers[i].size();
32 size_t j = 0;
33 while (j < n && numbers[i][j] == '0') {
34 ++j;
35 }
36 no_leading_zeros_version += (j < n) ? numbers[i].substr(j) : "0";
37 if (i != numbers.size() - 1) {
38 no_leading_zeros_version += ".";
39 }
40 }
41
42 *parsed_version = Version(no_leading_zeros_version);
43 }
44
45 } // namespace npapi
46 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698