Skip to content

Commit

Permalink
Remove legacy StartsWithASCII function.
Browse files Browse the repository at this point in the history
This replaces it with base::StartsWith and the appropriate case flag. Since the existing version only ever did case-insensitive tests in ASCII, there should be no behavior change.

BUG=506255
TBR=jam

Review URL: https://codereview.chromium.org/1242023005

Cr-Commit-Position: refs/heads/master@{#339175}
  • Loading branch information
brettw authored and Commit bot committed Jul 16, 2015
1 parent 387e05a commit 9550931
Show file tree
Hide file tree
Showing 110 changed files with 323 additions and 218 deletions.
4 changes: 2 additions & 2 deletions android_webview/native/android_protocol_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ bool AssetFileRequestInterceptor::ShouldHandleRequest(
return false;

const std::string& url = request->url().spec();
if (!base::StartsWithASCII(url, asset_prefix_, /*case_sensitive=*/ true) &&
!base::StartsWithASCII(url, resource_prefix_, /*case_sensitive=*/ true)) {
if (!base::StartsWith(url, asset_prefix_, base::CompareCase::SENSITIVE) &&
!base::StartsWith(url, resource_prefix_, base::CompareCase::SENSITIVE)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion android_webview/native/aw_media_url_interceptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool AwMediaUrlInterceptor::Intercept(const std::string& url,
asset_file_prefix.append(url::kStandardSchemeSeparator);
asset_file_prefix.append(android_webview::kAndroidAssetPath);

if (base::StartsWithASCII(url, asset_file_prefix, true)) {
if (base::StartsWith(url, asset_file_prefix, base::CompareCase::SENSITIVE)) {
std::string filename(url);
base::ReplaceFirstSubstringAfterOffset(
&filename, 0, asset_file_prefix, "assets/");
Expand Down
6 changes: 3 additions & 3 deletions ash/wm/lock_state_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ void LockStateController::PreLockAnimationFinished(bool request_lock) {
// Increase lock timeout for slower hardware, see http://crbug.com/350628
const std::string board = base::SysInfo::GetLsbReleaseBoard();
if (board == "x86-mario" ||
base::StartsWithASCII(board, "x86-alex", true /* case_sensitive */) ||
base::StartsWithASCII(board, "x86-zgb", true /* case_sensitive */) ||
base::StartsWithASCII(board, "daisy", true /* case_sensitive */)) {
base::StartsWith(board, "x86-alex", base::CompareCase::SENSITIVE) ||
base::StartsWith(board, "x86-zgb", base::CompareCase::SENSITIVE) ||
base::StartsWith(board, "daisy", base::CompareCase::SENSITIVE)) {
timeout *= 2;
}
// Times out on ASAN bots.
Expand Down
2 changes: 1 addition & 1 deletion base/files/file_path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ FilePath FilePath::NormalizePathSeparatorsTo(CharType separator) const {

#if defined(OS_ANDROID)
bool FilePath::IsContentUri() const {
return StartsWithASCII(path_, "content://", false /*case_sensitive*/);
return StartsWith(path_, "content://", base::CompareCase::INSENSITIVE_ASCII);
}
#endif

Expand Down
10 changes: 0 additions & 10 deletions base/strings/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,6 @@ BASE_EXPORT bool EndsWith(StringPiece16 str,
StringPiece16 search_for,
CompareCase case_sensitivity);

// DEPRECATED. Returns true if str starts/ends with search, or false otherwise.
// TODO(brettw) remove in favor of the "enum" versions above.
inline bool StartsWithASCII(const std::string& str,
const std::string& search,
bool case_sensitive) {
return StartsWith(StringPiece(str), StringPiece(search),
case_sensitive ? CompareCase::SENSITIVE
: CompareCase::INSENSITIVE_ASCII);
}

// Determines the type of ASCII character, independent of locale (the C
// library versions will change based on locale).
template <typename Char>
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/ui/webui/interstitials/interstitial_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ void InterstitialHTMLSource::StartDataRequest(
interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents_));
}
#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
else if (base::StartsWithASCII(path, "captiveportal", true))
else if (base::StartsWith(path, "captiveportal",
base::CompareCase::SENSITIVE))
{
interstitial_delegate.reset(CreateCaptivePortalBlockingPage(web_contents_));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ class BluetoothGattCharacteristicServiceProviderImpl
DCHECK(!uuid_.empty());
DCHECK(object_path_.IsValid());
DCHECK(service_path_.IsValid());
DCHECK(base::StartsWithASCII(object_path_.value(),
service_path_.value() + "/", true));
DCHECK(base::StartsWith(object_path_.value(),
service_path_.value() + "/",
base::CompareCase::SENSITIVE));

exported_object_ = bus_->GetExportedObject(object_path_);

Expand Down
5 changes: 3 additions & 2 deletions chromeos/dbus/bluetooth_gatt_descriptor_service_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ class BluetoothGattDescriptorServiceProviderImpl
DCHECK(!uuid_.empty());
DCHECK(object_path_.IsValid());
DCHECK(characteristic_path_.IsValid());
DCHECK(base::StartsWithASCII(object_path_.value(),
characteristic_path_.value() + "/", true));
DCHECK(base::StartsWith(object_path_.value(),
characteristic_path_.value() + "/",
base::CompareCase::SENSITIVE));

exported_object_ = bus_->GetExportedObject(object_path_);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ FakeBluetoothGattCharacteristicServiceProvider::
DCHECK(service_path_.IsValid());
DCHECK(!uuid.empty());
DCHECK(delegate_);
DCHECK(base::StartsWithASCII(object_path_.value(),
service_path_.value() + "/", true));
DCHECK(base::StartsWith(object_path_.value(),
service_path_.value() + "/",
base::CompareCase::SENSITIVE));

// TODO(armansito): Do something with |flags| and |permissions|.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ FakeBluetoothGattDescriptorServiceProvider::
DCHECK(characteristic_path_.IsValid());
DCHECK(!uuid.empty());
DCHECK(delegate_);
DCHECK(base::StartsWithASCII(object_path_.value(),
characteristic_path_.value() + "/", true));
DCHECK(base::StartsWith(object_path_.value(),
characteristic_path_.value() + "/",
base::CompareCase::SENSITIVE));

// TODO(armansito): Do something with |permissions|.

Expand Down
10 changes: 5 additions & 5 deletions chromeos/dbus/fake_shill_service_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,16 @@ bool FakeShillServiceClient::SetServiceProperty(const std::string& service_path,

base::DictionaryValue new_properties;
std::string changed_property;
bool case_sensitive = true;
if (base::StartsWithASCII(property, "Provider.", case_sensitive) ||
base::StartsWithASCII(property, "OpenVPN.", case_sensitive) ||
base::StartsWithASCII(property, "L2TPIPsec.", case_sensitive)) {
base::CompareCase case_sensitive = base::CompareCase::SENSITIVE;
if (base::StartsWith(property, "Provider.", case_sensitive) ||
base::StartsWith(property, "OpenVPN.", case_sensitive) ||
base::StartsWith(property, "L2TPIPsec.", case_sensitive)) {
// These properties are only nested within the Provider dictionary if read
// from Shill. Properties that start with "Provider" need to have that
// stripped off, other properties are nested in the "Provider" dictionary
// as-is.
std::string key = property;
if (base::StartsWithASCII(property, "Provider.", case_sensitive))
if (base::StartsWith(property, "Provider.", case_sensitive))
key = property.substr(strlen("Provider."));
base::DictionaryValue* provider = new base::DictionaryValue;
provider->SetWithoutPathExpansion(key, value.DeepCopy());
Expand Down
6 changes: 4 additions & 2 deletions chromeos/dbus/session_manager_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,8 @@ class SessionManagerClientImpl : public SessionManagerClient {
LOG(ERROR) << "Invalid signal: " << signal->ToString();
return;
}
const bool success = base::StartsWithASCII(result_string, "success", false);
const bool success = base::StartsWith(result_string, "success",
base::CompareCase::INSENSITIVE_ASCII);
FOR_EACH_OBSERVER(Observer, observers_, OwnerKeySet(success));
}

Expand All @@ -577,7 +578,8 @@ class SessionManagerClientImpl : public SessionManagerClient {
LOG(ERROR) << "Invalid signal: " << signal->ToString();
return;
}
const bool success = base::StartsWithASCII(result_string, "success", false);
const bool success = base::StartsWith(result_string, "success",
base::CompareCase::INSENSITIVE_ASCII);
FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(success));
}

Expand Down
6 changes: 3 additions & 3 deletions chromeos/disks/disk_mount_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ class DiskMountManagerImpl : public DiskMountManager {
for (MountPointMap::iterator it = mount_points_.begin();
it != mount_points_.end();
++it) {
if (base::StartsWithASCII(it->second.source_path, mount_path,
true /*case sensitive*/)) {
if (base::StartsWith(it->second.source_path, mount_path,
base::CompareCase::SENSITIVE)) {
// TODO(tbarzic): Handle the case where this fails.
UnmountPath(it->second.mount_path,
UNMOUNT_OPTIONS_NONE,
Expand Down Expand Up @@ -606,7 +606,7 @@ class DiskMountManagerImpl : public DiskMountManager {
it != system_path_prefixes_.end();
++it) {
const std::string& prefix = *it;
if (base::StartsWithASCII(system_path, prefix, true))
if (base::StartsWith(system_path, prefix, base::CompareCase::SENSITIVE))
return prefix;
}
return base::EmptyString();
Expand Down
2 changes: 1 addition & 1 deletion chromeos/settings/cros_settings_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void CrosSettingsProvider::Set(const std::string& path,
// It should not reach here from UI in the guest mode, but just in case.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kGuestSession) &&
!::base::StartsWithASCII(path, "cros.session.", true)) {
!base::StartsWith(path, "cros.session.", base::CompareCase::SENSITIVE)) {
LOG(ERROR) << "Ignoring the guest request to change: " << path;
return;
}
Expand Down
3 changes: 2 additions & 1 deletion chromeos/system/version_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ std::string ParseFirmware(const std::string& contents) {
std::vector<std::string> lines;
base::SplitString(contents, '\n', &lines);
for (size_t i = 0; i < lines.size(); ++i) {
if (base::StartsWithASCII(lines[i], kFirmwarePrefix, false)) {
if (base::StartsWith(lines[i], kFirmwarePrefix,
base::CompareCase::INSENSITIVE_ASCII)) {
std::string str = lines[i].substr(std::string(kFirmwarePrefix).size());
size_t found = str.find_first_not_of("| ");
if (found != std::string::npos)
Expand Down
3 changes: 2 additions & 1 deletion components/autofill/content/renderer/form_autofill_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,8 @@ bool UnownedFormElementsAndFieldSetsToFormData(
std::string lang;
if (!html_element.isNull())
lang = html_element.getAttribute("lang").utf8();
if ((lang.empty() || base::StartsWithASCII(lang, "en", false)) &&
if ((lang.empty() ||
base::StartsWith(lang, "en", base::CompareCase::INSENSITIVE_ASCII)) &&
!MatchesPattern(document.title(),
base::UTF8ToUTF16("payment|checkout|address|delivery|shipping"))) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions components/autofill/core/browser/autofill_download_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ void AutofillDownloadManager::OnURLFetchComplete(
case kHttpBadGateway:
if (!source->GetResponseHeaders()->EnumerateHeader(NULL, "server",
&server_header) ||
base::StartsWithASCII(server_header.c_str(),
kAutofillQueryServerNameStartInHeader,
false) != 0)
base::StartsWith(server_header.c_str(),
kAutofillQueryServerNameStartInHeader,
base::CompareCase::INSENSITIVE_ASCII) != 0)
break;
// Bad gateway was received from Autofill servers. Fall through to back
// off.
Expand Down
5 changes: 3 additions & 2 deletions components/autofill/core/browser/form_structure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const int kNumberOfMismatchesThreshold = 3;
bool IsAutofillFieldMetadataEnabled() {
const std::string group_name =
base::FieldTrialList::FindFullName("AutofillFieldMetadata");
return base::StartsWithASCII(group_name, "Enabled", true);
return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE);
}

// Helper for |EncodeUploadRequest()| that creates a bit field corresponding to
Expand Down Expand Up @@ -1151,7 +1151,8 @@ void FormStructure::ParseFieldTypesFromAutocompleteAttributes(
// The preceding token, if any, may be a named section.
const std::string kSectionPrefix = "section-";
if (!tokens.empty() &&
base::StartsWithASCII(tokens.back(), kSectionPrefix, true)) {
base::StartsWith(tokens.back(), kSectionPrefix,
base::CompareCase::SENSITIVE)) {
// Prepend this section name to the suffix set in the preceding block.
section = tokens.back().substr(kSectionPrefix.size()) + section;
tokens.pop_back();
Expand Down
3 changes: 2 additions & 1 deletion components/cloud_devices/common/cloud_devices_urls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ bool IsCloudPrintURL(const GURL& url) {
GURL cloud_print_url = GetCloudPrintURL();
return url.host() == cloud_print_url.host() &&
url.scheme() == cloud_print_url.scheme() &&
base::StartsWithASCII(url.path(), cloud_print_url.path(), true);
base::StartsWith(url.path(), cloud_print_url.path(),
base::CompareCase::SENSITIVE);
}

GURL GetCloudPrintEnableURL(const std::string& proxy_id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ void PatternParser::Parse(const std::string& pattern_spec,
host_component.len);
if (host == kHostWildcard) {
builder->WithDomainWildcard();
} else if (base::StartsWithASCII(host, kDomainWildcard, true)) {
} else if (base::StartsWith(host, kDomainWildcard,
base::CompareCase::SENSITIVE)) {
host = host.substr(kDomainWildcardLength);
builder->WithDomainWildcard();
builder->WithHost(host);
Expand Down
9 changes: 6 additions & 3 deletions components/cronet/android/test/native_test_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ scoped_ptr<net::test_server::HttpResponse> NativeTestServerRequestHandler(
return response.Pass();
}

if (base::StartsWithASCII(request.relative_url, kEchoHeaderPath, true)) {
if (base::StartsWith(request.relative_url, kEchoHeaderPath,
base::CompareCase::SENSITIVE)) {
GURL url = g_test_server->GetURL(request.relative_url);
auto it = request.headers.find(url.query());
if (it != request.headers.end()) {
Expand Down Expand Up @@ -141,7 +142,8 @@ scoped_ptr<net::test_server::HttpResponse> SdchRequestHandler(
DCHECK(get_data_dir);
dir_path = dir_path.Append(FILE_PATH_LITERAL("test"));

if (base::StartsWithASCII(request.relative_url, kSdchPath, true)) {
if (base::StartsWith(request.relative_url, kSdchPath,
base::CompareCase::SENSITIVE)) {
base::FilePath file_path = dir_path.Append("sdch/index");
scoped_ptr<CustomHttpResponse> response =
ConstructResponseBasedOnFile(file_path).Pass();
Expand All @@ -162,7 +164,8 @@ scoped_ptr<net::test_server::HttpResponse> SdchRequestHandler(
return response.Pass();
}

if (base::StartsWithASCII(request.relative_url, kSdchTestPath, true)) {
if (base::StartsWith(request.relative_url, kSdchTestPath,
base::CompareCase::SENSITIVE)) {
auto avail_dictionary_header = request.headers.find("Avail-Dictionary");
if (avail_dictionary_header != request.headers.end()) {
base::FilePath file_path = dir_path.Append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ TEST_F(EnhancedBookmarkModelTest, TestDoubleEncodeDecode) {
TEST_F(EnhancedBookmarkModelTest, TestRemoteId) {
const BookmarkNode* node = AddBookmark();
// Verify that the remote id starts with the correct prefix.
EXPECT_TRUE(base::StartsWithASCII(model_->GetRemoteId(node), "ebc_", true));
EXPECT_TRUE(base::StartsWith(model_->GetRemoteId(node), "ebc_",
base::CompareCase::SENSITIVE));

// Getting the remote id for nodes that don't have them should return the
// empty string.
Expand Down
2 changes: 1 addition & 1 deletion components/favicon/core/favicon_driver_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool IsIconNTPEnabled() {
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableIconNtp))
return true;

return base::StartsWithASCII(group_name, "Enabled", true);
return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE);
}

#if defined(OS_ANDROID) || defined(OS_IOS)
Expand Down
8 changes: 4 additions & 4 deletions components/gcm_driver/registration_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ scoped_ptr<RegistrationInfo> RegistrationInfo::BuildFromString(
std::string* registration_id) {
scoped_ptr<RegistrationInfo> registration;

if (base::StartsWithASCII(serialzied_key, kInsanceIDSerializationPrefix,
true))
if (base::StartsWith(serialzied_key, kInsanceIDSerializationPrefix,
base::CompareCase::SENSITIVE))
registration.reset(new InstanceIDTokenInfo);
else
registration.reset(new GCMRegistrationInfo);
Expand Down Expand Up @@ -184,8 +184,8 @@ bool InstanceIDTokenInfo::Deserialize(
if (serialized_key.empty() || serialized_value.empty())
return false;

if (!base::StartsWithASCII(serialized_key, kInsanceIDSerializationPrefix,
true))
if (!base::StartsWith(serialized_key, kInsanceIDSerializationPrefix,
base::CompareCase::SENSITIVE))
return false;

std::vector<std::string> fields = base::SplitString(
Expand Down
3 changes: 2 additions & 1 deletion components/google/core/browser/google_url_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ void GoogleURLTracker::OnURLFetchComplete(const net::URLFetcher* source) {
std::string url_str;
source->GetResponseAsString(&url_str);
base::TrimWhitespace(url_str, base::TRIM_ALL, &url_str);
if (!base::StartsWithASCII(url_str, ".google.", false))
if (!base::StartsWith(url_str, ".google.",
base::CompareCase::INSENSITIVE_ASCII))
return;
GURL url("https://www" + url_str);
if (!url.is_valid() || (url.path().length() > 1) || url.has_query() ||
Expand Down
7 changes: 4 additions & 3 deletions components/google/core/browser/google_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ GURL CommandLineGoogleBaseURL() {
bool StartsWithCommandLineGoogleBaseURL(const GURL& url) {
GURL base_url(CommandLineGoogleBaseURL());
return base_url.is_valid() &&
base::StartsWithASCII(url.possibly_invalid_spec(), base_url.spec(),
true);
base::StartsWith(url.possibly_invalid_spec(), base_url.spec(),
base::CompareCase::SENSITIVE);
}

bool IsGoogleHostname(const std::string& host,
Expand All @@ -190,7 +190,8 @@ bool IsGoogleHomePageUrl(const GURL& url) {

// Make sure the path is a known home page path.
std::string path(url.path());
return IsPathHomePageBase(path) || base::StartsWithASCII(path, "/ig", false);
return IsPathHomePageBase(path) ||
base::StartsWith(path, "/ig", base::CompareCase::INSENSITIVE_ASCII);
}

bool IsGoogleSearchUrl(const GURL& url) {
Expand Down
3 changes: 2 additions & 1 deletion components/html_viewer/web_mime_registry_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ WebMimeRegistryImpl::supportsImagePrefixedMIMEType(
const blink::WebString& mime_type) {
std::string ascii_mime_type = ToASCIIOrEmpty(mime_type);
return (mime_util::IsSupportedImageMimeType(ascii_mime_type) ||
(base::StartsWithASCII(ascii_mime_type, "image/", true) &&
(base::StartsWith(ascii_mime_type, "image/",
base::CompareCase::SENSITIVE) &&
mime_util::IsSupportedNonImageMimeType(ascii_mime_type)))
? WebMimeRegistry::IsSupported
: WebMimeRegistry::IsNotSupported;
Expand Down
6 changes: 4 additions & 2 deletions components/html_viewer/web_url_loader_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ blink::WebURLResponse::HTTPVersion StatusLineToHTTPVersion(
if (status_line.is_null())
return blink::WebURLResponse::HTTP_0_9;

if (base::StartsWithASCII(status_line, "HTTP/1.0", true))
if (base::StartsWith(status_line.get(), "HTTP/1.0",
base::CompareCase::SENSITIVE))
return blink::WebURLResponse::HTTP_1_0;

if (base::StartsWithASCII(status_line, "HTTP/1.1", true))
if (base::StartsWith(status_line.get(), "HTTP/1.1",
base::CompareCase::SENSITIVE))
return blink::WebURLResponse::HTTP_1_1;

return blink::WebURLResponse::Unknown;
Expand Down
3 changes: 2 additions & 1 deletion components/invalidation/impl/gcm_network_channel_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ void TestNetworkChannelURLFetcher::AddExtraRequestHeader(
net::FakeURLFetcher::AddExtraRequestHeader(header_line);
std::string header_name("echo-token: ");
std::string echo_token;
if (base::StartsWithASCII(header_line, header_name, false)) {
if (base::StartsWith(header_line, header_name,
base::CompareCase::INSENSITIVE_ASCII)) {
echo_token = header_line;
base::ReplaceFirstSubstringAfterOffset(
&echo_token, 0, header_name, std::string());
Expand Down
Loading

0 comments on commit 9550931

Please sign in to comment.