Index: webkit/plugins/webplugininfo.cc |
=================================================================== |
--- webkit/plugins/webplugininfo.cc (revision 212595) |
+++ webkit/plugins/webplugininfo.cc (working copy) |
@@ -4,8 +4,13 @@ |
#include "webkit/plugins/webplugininfo.h" |
+#include <algorithm> |
+ |
#include "base/logging.h" |
+#include "base/strings/string_split.h" |
+#include "base/strings/string_util.h" |
#include "base/strings/utf_string_conversions.h" |
+#include "base/version.h" |
namespace webkit { |
@@ -63,4 +68,36 @@ |
pepper_permissions(0) { |
} |
+void WebPluginInfo::CreateVersionFromString( |
+ const base::string16& version_string, |
+ base::Version* parsed_version) { |
+ // Remove spaces and ')' from the version string, |
+ // Replace any instances of 'r', ',' or '(' with a dot. |
+ std::string version = UTF16ToASCII(version_string); |
+ RemoveChars(version, ") ", &version); |
+ std::replace(version.begin(), version.end(), 'd', '.'); |
+ std::replace(version.begin(), version.end(), 'r', '.'); |
+ std::replace(version.begin(), version.end(), ',', '.'); |
+ std::replace(version.begin(), version.end(), '(', '.'); |
+ std::replace(version.begin(), version.end(), '_', '.'); |
+ |
+ // Remove leading zeros from each of the version components. |
+ std::string no_leading_zeros_version; |
+ std::vector<std::string> numbers; |
+ base::SplitString(version, '.', &numbers); |
+ for (size_t i = 0; i < numbers.size(); ++i) { |
+ size_t n = numbers[i].size(); |
+ size_t j = 0; |
+ while (j < n && numbers[i][j] == '0') { |
+ ++j; |
+ } |
+ no_leading_zeros_version += (j < n) ? numbers[i].substr(j) : "0"; |
+ if (i != numbers.size() - 1) { |
+ no_leading_zeros_version += "."; |
+ } |
+ } |
+ |
+ *parsed_version = Version(no_leading_zeros_version); |
+} |
+ |
} // namespace webkit |