Chromium Code Reviews| Index: base/version.cc |
| =================================================================== |
| --- base/version.cc (revision 86383) |
| +++ base/version.cc (working copy) |
| @@ -10,40 +10,44 @@ |
| #include "base/string_number_conversions.h" |
| #include "base/string_split.h" |
| #include "base/string_util.h" |
| -#include "base/utf_string_conversions.h" |
| -Version::Version() : is_valid_(false) {} |
| +Version::Version() { |
| +} |
| -Version::~Version() {} |
| +Version::Version(const std::string& version_str) { |
| + InitFromString(version_str); |
| +} |
| -// static |
| +// TODO: remove this method. |
|
Evan Martin
2011/06/06 23:35:13
TODO(cpu) or file a bug :)
|
| Version* Version::GetVersionFromString(const std::string& version_str) { |
| Version* vers = new Version(); |
| if (vers->InitFromString(version_str)) { |
| - DCHECK(vers->is_valid_); |
| + DCHECK(vers->IsValid()); |
| return vers; |
| } |
| delete vers; |
| return NULL; |
| } |
| +// TODO: remove this method. |
| Version* Version::Clone() const { |
| - DCHECK(is_valid_); |
| - Version* copy = new Version(); |
| - copy->components_ = components_; |
| - copy->is_valid_ = true; |
| - return copy; |
| + DCHECK(IsValid()); |
| + return new Version(*this); |
| } |
| +bool Version::IsValid() const { |
| + return (!components_.empty()); |
| +} |
| + |
| bool Version::Equals(const Version& that) const { |
| - DCHECK(is_valid_); |
| - DCHECK(that.is_valid_); |
| - return CompareTo(that) == 0; |
| + DCHECK(IsValid()); |
| + DCHECK(that.IsValid()); |
| + return (CompareTo(that) == 0); |
| } |
| int Version::CompareTo(const Version& other) const { |
| - DCHECK(is_valid_); |
| - DCHECK(other.is_valid_); |
| + DCHECK(IsValid()); |
| + DCHECK(other.IsValid()); |
| size_t count = std::min(components_.size(), other.components_.size()); |
| for (size_t i = 0; i < count; ++i) { |
| if (components_[i] > other.components_[i]) |
| @@ -64,7 +68,7 @@ |
| } |
| const std::string Version::GetString() const { |
| - DCHECK(is_valid_); |
| + DCHECK(IsValid()); |
| std::string version_str; |
| size_t count = components_.size(); |
| for (size_t i = 0; i < count - 1; ++i) { |
| @@ -76,7 +80,6 @@ |
| } |
| bool Version::InitFromString(const std::string& version_str) { |
| - DCHECK(!is_valid_); |
| std::vector<std::string> numbers; |
| base::SplitString(version_str, '.', &numbers); |
| if (numbers.empty()) |
| @@ -97,6 +100,5 @@ |
| uint16 component = static_cast<uint16>(num); |
| components_.push_back(component); |
| } |
| - is_valid_ = true; |
| return true; |
| } |