OLD | NEW |
(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 |
OLD | NEW |