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

Unified Diff: base/version.cc

Issue 1575523002: Comparison and streaming operators for base::Version (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes mistake in previous patch set. Created 4 years, 11 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 | « base/version.h ('k') | base/version_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/version.cc
diff --git a/base/version.cc b/base/version.cc
index 3677b731980beb8328a1b6b0633c791cd1dee44e..19b9922e6922f8880868b1a11cd67956844d3bc0 100644
--- a/base/version.cc
+++ b/base/version.cc
@@ -33,8 +33,6 @@ bool ParseVersionNumbers(const std::string& version_str,
if (StartsWith(*it, "+", CompareCase::SENSITIVE))
return false;
- // TODO(brettw) when we have a StringPiece version of StringToUint, delete
- // this string conversion.
unsigned int num;
if (!StringToUint(*it, &num))
return false;
@@ -107,13 +105,6 @@ bool Version::IsValidWildcardString(const std::string& wildcard_string) {
return version.IsValid();
}
-bool Version::IsOlderThan(const std::string& version_str) const {
- Version proposed_ver(version_str);
- if (!proposed_ver.IsValid())
- return false;
- return (CompareTo(proposed_ver) < 0);
-}
-
int Version::CompareToWildcardString(const std::string& wildcard_string) const {
DCHECK(IsValid());
DCHECK(Version::IsValidWildcardString(wildcard_string));
@@ -151,12 +142,6 @@ int Version::CompareToWildcardString(const std::string& wildcard_string) const {
return 0;
}
-bool Version::Equals(const Version& that) const {
- DCHECK(IsValid());
- DCHECK(that.IsValid());
- return (CompareTo(that) == 0);
-}
-
int Version::CompareTo(const Version& other) const {
DCHECK(IsValid());
DCHECK(other.IsValid());
@@ -175,4 +160,32 @@ const std::string Version::GetString() const {
return version_str;
}
+bool operator==(const Version& v1, const Version& v2) {
+ return v1.CompareTo(v2) == 0;
+}
+
+bool operator!=(const Version& v1, const Version& v2) {
+ return !(v1 == v2);
+}
+
+bool operator<(const Version& v1, const Version& v2) {
+ return v1.CompareTo(v2) < 0;
+}
+
+bool operator<=(const Version& v1, const Version& v2) {
+ return v1.CompareTo(v2) <= 0;
+}
+
+bool operator>(const Version& v1, const Version& v2) {
+ return v1.CompareTo(v2) > 0;
+}
+
+bool operator>=(const Version& v1, const Version& v2) {
+ return v1.CompareTo(v2) >= 0;
+}
+
+std::ostream& operator<<(std::ostream& stream, const Version& v) {
+ return stream << v.GetString();
+}
+
} // namespace base
« no previous file with comments | « base/version.h ('k') | base/version_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698