Start migrating off of StringPiece::ends_with/starts_with and using our
new standard functions strings::StartsWith and strings::EndsWith.
This commit is contained in:
@@ -27,7 +27,7 @@ bool StripUtf8Bom(StringPiece* contents) {
|
||||
bool result = false;
|
||||
StringPiece bom;
|
||||
bom.set(kUtf8Bom, STATIC_STRLEN(kUtf8Bom));
|
||||
if (contents->starts_with(bom)) {
|
||||
if (strings::StartsWith(*contents, bom)) {
|
||||
contents->remove_prefix(bom.length());
|
||||
result = true;
|
||||
}
|
||||
@@ -50,25 +50,25 @@ const StringPiece GetCharsetForBom(const StringPiece contents) {
|
||||
// to use STATIC_STRLEN and manual StringPiece construction.
|
||||
StringPiece bom;
|
||||
bom.set(kUtf8Bom, STATIC_STRLEN(kUtf8Bom));
|
||||
if (contents.starts_with(bom)) {
|
||||
if (strings::StartsWith(contents, bom)) {
|
||||
return kUtf8Charset;
|
||||
}
|
||||
bom.set(kUtf16BigEndianBom, STATIC_STRLEN(kUtf16BigEndianBom));
|
||||
if (contents.starts_with(bom)) {
|
||||
if (strings::StartsWith(contents, bom)) {
|
||||
return kUtf16BigEndianCharset;
|
||||
}
|
||||
// UTF-16LE's BOM is a leading substring of UTF-32LE's BOM, so we must
|
||||
// check the longer one first. All the others have unique prefixes.
|
||||
bom.set(kUtf32LittleEndianBom, STATIC_STRLEN(kUtf32LittleEndianBom));
|
||||
if (contents.starts_with(bom)) {
|
||||
if (strings::StartsWith(contents, bom)) {
|
||||
return kUtf32LittleEndianCharset;
|
||||
}
|
||||
bom.set(kUtf16LittleEndianBom, STATIC_STRLEN(kUtf16LittleEndianBom));
|
||||
if (contents.starts_with(bom)) {
|
||||
if (strings::StartsWith(contents, bom)) {
|
||||
return kUtf16LittleEndianCharset;
|
||||
}
|
||||
bom.set(kUtf32BigEndianBom, STATIC_STRLEN(kUtf32BigEndianBom));
|
||||
if (contents.starts_with(bom)) {
|
||||
if (strings::StartsWith(contents, bom)) {
|
||||
return kUtf32BigEndianCharset;
|
||||
}
|
||||
|
||||
|
||||
@@ -437,7 +437,7 @@ bool StringCaseEndsWith(StringPiece str, StringPiece suffix) {
|
||||
|
||||
bool StringEqualConcat(StringPiece str, StringPiece first, StringPiece second) {
|
||||
return (str.size() == first.size() + second.size()) &&
|
||||
str.starts_with(first) && str.ends_with(second);
|
||||
strings::StartsWith(str, first) && strings::EndsWith(str, second);
|
||||
}
|
||||
|
||||
StringPiece PieceAfterEquals(StringPiece piece) {
|
||||
@@ -573,10 +573,10 @@ bool TrimCasePattern(StringPiece pattern, StringPiece* str) {
|
||||
|
||||
void TrimQuote(StringPiece* str) {
|
||||
TrimWhitespace(str);
|
||||
if (str->starts_with("\"") || str->starts_with("'")) {
|
||||
if (strings::StartsWith(*str, "\"") || strings::StartsWith(*str, "'")) {
|
||||
str->remove_prefix(1);
|
||||
}
|
||||
if (str->ends_with("\"") || str->ends_with("'")) {
|
||||
if (strings::EndsWith(*str, "\"") || strings::EndsWith(*str, "'")) {
|
||||
str->remove_suffix(1);
|
||||
}
|
||||
TrimWhitespace(str);
|
||||
|
||||
@@ -52,6 +52,16 @@ using base::StringPrintf;
|
||||
|
||||
typedef StringPiece::size_type stringpiece_ssize_type;
|
||||
|
||||
namespace strings {
|
||||
inline bool StartsWith(StringPiece a, StringPiece b) {
|
||||
return a.starts_with(b);
|
||||
}
|
||||
inline bool EndsWith(StringPiece a, StringPiece b) {
|
||||
return a.ends_with(b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Quick macro to get the size of a static char[] without trailing '\0'.
|
||||
// Note: Cannot be used for char*, std::string, etc.
|
||||
#define STATIC_STRLEN(static_string) (arraysize(static_string) - 1)
|
||||
@@ -662,7 +672,9 @@ bool SplitStringPieceToIntegerVector(StringPiece src, StringPiece separators,
|
||||
std::vector<int>* ints);
|
||||
|
||||
// Does a path end in slash?
|
||||
inline bool EndsInSlash(StringPiece path) { return path.ends_with("/"); }
|
||||
inline bool EndsInSlash(StringPiece path) {
|
||||
return strings::EndsWith(path, "/");
|
||||
}
|
||||
|
||||
// Make sure directory's path ends in '/'.
|
||||
inline void EnsureEndsInSlash(GoogleString* dir) {
|
||||
|
||||
Reference in New Issue
Block a user