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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/plugins/npapi/plugin_utils.cc
diff --git a/webkit/plugins/npapi/plugin_utils.cc b/webkit/plugins/npapi/plugin_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4cef347d7854b4e2831e2d44b754662956be3cb6
--- /dev/null
+++ b/webkit/plugins/npapi/plugin_utils.cc
@@ -0,0 +1,48 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/plugins/npapi/plugin_utils.h"
+
+#include <algorithm>
+
+#include "base/string_split.h"
+#include "base/string_util.h"
+#include "base/version.h"
+
+namespace webkit {
+namespace npapi {
+
+void CreateVersionFromString(const string16& version_string,
+ 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 npapi
+} // namespace webkit
« 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