Write new Starts/EndsWith and convert FilePath functions to StringPiece.
commit89365dc80aa9ea343cea0fe48fdeb702b23726a2
authorbrettw <brettw@chromium.org>
Tue, 16 Jun 2015 05:52:47 +0000 (15 22:52 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 16 Jun 2015 05:53:17 +0000 (16 05:53 +0000)
treeec0e0129c6e49294f97f1246a668384d9e7f517d
parent81b1f947db37a13298593bcd9e6754f9f5e6e78a
Write new Starts/EndsWith and convert FilePath functions to StringPiece.

When I moved StartsWith and EndsWith to the base namespace it became apparent that the bool parameter was frequently a source of confusion, and that the second argument is almost always a constant that we then convert to a string.

This adds new versions of StartsWith/EndsWith that takes an enum for case sensitivity and string pieces for the string inputs.

The existing functions used a locale-dependent case insensitive comparison that is marked with an old bug number that such comparisons are probably wrong. With this change, I moved the case insensitive comparisons to ASCII ones.

Only callers in base are updated. The rest of the calls go through a compatibility layer.

The compatibility layer keeps the local-dependent compares for the 16-bit string comparisons to avoid breaking things subtly. There are relatively few calls to the 16-bit version, and most use constants for the prefix/suffix (which wouldn't be affected by the locale), so there should be few callers to audit in a later pass to go to pure ASCII comparisons.

The 8-bit versions now always use the ASCII case-insensitive comparisons. This should be the only change in this patch that can affect the behavior of the program. Code doing locale-dependent 8-bit tolower() calls (what the old code ended up doing) is almost certainly wrong. UTF-8 strings will be mangled. The only 8-bit non-UTF-8 strings we have are typically Posix file paths and Posix file paths are case-sensitive. I'm not very concerned about regressions from this change.

Use StringPiece in FilePath for input arguments. This wasn't done before because we had no StringPiece16 until more recently. Constants are frequently passed as input to some of the functions, especially Append, so this will save some string allocations. Unfortunately, this is more likely to affect unit tests that the real browser. This is combined with the StartsWith/EndsWith changes because I started changing FilePath when updating its use of StartsWith.

The FilePath changes should have no observable effect on the product.

BUG=24917

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

Cr-Commit-Position: refs/heads/master@{#334555}
base/files/file_path.cc
base/files/file_path.h
base/strings/string_util.cc
base/strings/string_util.h
base/sys_info.cc
base/version.cc
base/win/win_util.cc
content/browser/download/save_package.h