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

Unified Diff: base/version.cc

Issue 1182453004: Write new Starts/EndsWith and convert FilePath functions to StringPiece. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@string_util
Patch Set: Fix save_package using Created 5 years, 6 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
Index: base/version.cc
diff --git a/base/version.cc b/base/version.cc
index ede8a4586eb9bb8685b05a00939772cd7eaaefdb..4e71310aff5dba082d7937a725e8039738e63f80 100644
--- a/base/version.cc
+++ b/base/version.cc
@@ -24,15 +24,17 @@ namespace {
// parsed successfully, false otherwise.
bool ParseVersionNumbers(const std::string& version_str,
std::vector<uint32_t>* parsed) {
- std::vector<std::string> numbers;
- SplitString(version_str, '.', &numbers);
+ std::vector<StringPiece> numbers =
+ SplitStringPiece(version_str, ".", KEEP_WHITESPACE, SPLIT_WANT_ALL);
if (numbers.empty())
return false;
- for (std::vector<std::string>::const_iterator it = numbers.begin();
- it != numbers.end(); ++it) {
- if (StartsWithASCII(*it, "+", false))
+ for (auto it = numbers.begin(); it != numbers.end(); ++it) {
+ 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;
@@ -97,9 +99,11 @@ bool Version::IsValid() const {
// static
bool Version::IsValidWildcardString(const std::string& wildcard_string) {
- std::string version_string = wildcard_string;
- if (EndsWith(wildcard_string.c_str(), ".*", false))
+ std::string version_string;
+ if (EndsWith(wildcard_string, ".*", CompareCase::SENSITIVE))
version_string = wildcard_string.substr(0, wildcard_string.size() - 2);
Peter Kasting 2015/06/15 20:41:40 Nit: Hmm... I think it might be more efficient to
brettw 2015/06/15 23:00:48 You're right. I'm going to do resize(version_strin
Peter Kasting 2015/06/16 00:08:18 OK... I actually find it a bit less clear semantic
+ else
+ version_string = wildcard_string;
Version version(version_string);
return version.IsValid();
@@ -117,7 +121,7 @@ int Version::CompareToWildcardString(const std::string& wildcard_string) const {
DCHECK(Version::IsValidWildcardString(wildcard_string));
// Default behavior if the string doesn't end with a wildcard.
- if (!EndsWith(wildcard_string.c_str(), ".*", false)) {
+ if (!EndsWith(wildcard_string, ".*", CompareCase::SENSITIVE)) {
Version version(wildcard_string);
DCHECK(version.IsValid());
return CompareTo(version);
« base/strings/string_util.cc ('K') | « base/sys_info.cc ('k') | base/win/win_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698