| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "content/public/common/webplugininfo.h" | 5 #include "content/public/common/webplugininfo.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 type(PLUGIN_TYPE_NPAPI), | 67 type(PLUGIN_TYPE_NPAPI), |
| 68 pepper_permissions(0) { | 68 pepper_permissions(0) { |
| 69 } | 69 } |
| 70 | 70 |
| 71 void WebPluginInfo::CreateVersionFromString( | 71 void WebPluginInfo::CreateVersionFromString( |
| 72 const base::string16& version_string, | 72 const base::string16& version_string, |
| 73 base::Version* parsed_version) { | 73 base::Version* parsed_version) { |
| 74 // Remove spaces and ')' from the version string, | 74 // Remove spaces and ')' from the version string, |
| 75 // Replace any instances of 'r', ',' or '(' with a dot. | 75 // Replace any instances of 'r', ',' or '(' with a dot. |
| 76 std::string version = UTF16ToASCII(version_string); | 76 std::string version = UTF16ToASCII(version_string); |
| 77 RemoveChars(version, ") ", &version); | 77 base::RemoveChars(version, ") ", &version); |
| 78 std::replace(version.begin(), version.end(), 'd', '.'); | 78 std::replace(version.begin(), version.end(), 'd', '.'); |
| 79 std::replace(version.begin(), version.end(), 'r', '.'); | 79 std::replace(version.begin(), version.end(), 'r', '.'); |
| 80 std::replace(version.begin(), version.end(), ',', '.'); | 80 std::replace(version.begin(), version.end(), ',', '.'); |
| 81 std::replace(version.begin(), version.end(), '(', '.'); | 81 std::replace(version.begin(), version.end(), '(', '.'); |
| 82 std::replace(version.begin(), version.end(), '_', '.'); | 82 std::replace(version.begin(), version.end(), '_', '.'); |
| 83 | 83 |
| 84 // Remove leading zeros from each of the version components. | 84 // Remove leading zeros from each of the version components. |
| 85 std::string no_leading_zeros_version; | 85 std::string no_leading_zeros_version; |
| 86 std::vector<std::string> numbers; | 86 std::vector<std::string> numbers; |
| 87 base::SplitString(version, '.', &numbers); | 87 base::SplitString(version, '.', &numbers); |
| 88 for (size_t i = 0; i < numbers.size(); ++i) { | 88 for (size_t i = 0; i < numbers.size(); ++i) { |
| 89 size_t n = numbers[i].size(); | 89 size_t n = numbers[i].size(); |
| 90 size_t j = 0; | 90 size_t j = 0; |
| 91 while (j < n && numbers[i][j] == '0') { | 91 while (j < n && numbers[i][j] == '0') { |
| 92 ++j; | 92 ++j; |
| 93 } | 93 } |
| 94 no_leading_zeros_version += (j < n) ? numbers[i].substr(j) : "0"; | 94 no_leading_zeros_version += (j < n) ? numbers[i].substr(j) : "0"; |
| 95 if (i != numbers.size() - 1) { | 95 if (i != numbers.size() - 1) { |
| 96 no_leading_zeros_version += "."; | 96 no_leading_zeros_version += "."; |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 *parsed_version = Version(no_leading_zeros_version); | 100 *parsed_version = Version(no_leading_zeros_version); |
| 101 } | 101 } |
| 102 | 102 |
| 103 } // namespace content | 103 } // namespace content |
| OLD | NEW |