Do not use string_view_utils.h or stringpiece_ssize_type in balsa_headers.cc. Neither string_view_utils.h nor stringpiece_ssize_type are part of public Abseil. This CL copies necessary helper functions to balsa_headers.cc. stringpiece_ssize_type is typedefed to std::string::difference_type, which, just like absl::string_piece::difference_type, is an alias to ptrdiff_t. Also include absl/strings/str_format.h for absl::StrAppendFormat(). PiperOrigin-RevId: 445194088
diff --git a/quiche/common/balsa/balsa_headers.cc b/quiche/common/balsa/balsa_headers.cc index d96b5a8..e024e1a 100644 --- a/quiche/common/balsa/balsa_headers.cc +++ b/quiche/common/balsa/balsa_headers.cc
@@ -16,9 +16,9 @@ #include "absl/strings/ascii.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" +#include "absl/strings/str_format.h" #include "absl/strings/str_join.h" #include "absl/strings/string_view.h" -#include "absl/strings/string_view_utils.h" #include "quiche/common/balsa/balsa_enums.h" #include "quiche/common/balsa/header_properties.h" #include "quiche/common/platform/api/quiche_header_policy.h" @@ -118,6 +118,49 @@ // HEADER_FUNC to insert "name" into the MultivaluedHeadersSet of Envoy headers. #define MULTIVALUE_ENVOY_HEADER(name) {name}, +absl::string_view::difference_type FindIgnoreCase(absl::string_view haystack, + absl::string_view needle) { + absl::string_view::difference_type pos = 0; + while (haystack.size() >= needle.size()) { + if (absl::StartsWithIgnoreCase(haystack, needle)) { + return pos; + } + ++pos; + haystack.remove_prefix(1); + } + + return absl::string_view::npos; +} + +absl::string_view::difference_type RemoveLeadingWhitespace( + absl::string_view* text) { + size_t count = 0; + const char* ptr = text->data(); + while (count < text->size() && absl::ascii_isspace(*ptr)) { + count++; + ptr++; + } + text->remove_prefix(count); + return count; +} + +absl::string_view::difference_type RemoveTrailingWhitespace( + absl::string_view* text) { + size_t count = 0; + const char* ptr = text->data() + text->size() - 1; + while (count < text->size() && absl::ascii_isspace(*ptr)) { + ++count; + --ptr; + } + text->remove_suffix(count); + return count; +} + +absl::string_view::difference_type RemoveWhitespaceContext( + absl::string_view* text) { + return RemoveLeadingWhitespace(text) + RemoveTrailingWhitespace(text); +} + } // namespace namespace quiche { @@ -505,8 +548,8 @@ // Helper function for HeaderHasValue that checks that the specified region // within line is preceded by whitespace and a comma or beginning of line, // and followed by whitespace and a comma or end of line. -bool SurroundedOnlyBySpacesAndCommas(stringpiece_ssize_type idx, - stringpiece_ssize_type end_idx, +bool SurroundedOnlyBySpacesAndCommas(absl::string_view::difference_type idx, + absl::string_view::difference_type end_idx, absl::string_view line) { for (idx = idx - 1; idx >= 0; --idx) { if (line[idx] == ',') { @@ -537,10 +580,9 @@ it != lines().end(); ++it) { absl::string_view line = it->second; absl::string_view::size_type idx = - case_sensitive ? line.find(value, 0) - : strings::FindIgnoreCase(line, value); + case_sensitive ? line.find(value, 0) : FindIgnoreCase(line, value); while (idx != absl::string_view::npos) { - stringpiece_ssize_type end_idx = idx + value.size(); + absl::string_view::difference_type end_idx = idx + value.size(); if (SurroundedOnlyBySpacesAndCommas(idx, end_idx, line)) { return true; } @@ -693,7 +735,7 @@ absl::string_view search_value) { // Remove whitespace around search value. absl::string_view needle = search_value; - strings::RemoveWhitespaceContext(&needle); + RemoveWhitespaceContext(&needle); QUICHE_BUG_IF(bug_22783_2, needle != search_value) << "Search value should not be surrounded by spaces."; @@ -723,7 +765,7 @@ // this stringpiece will continually move forward, and its tail // (head+length) will always remain the same. absl::string_view values(value_begin, line->ValuesLength()); - strings::RemoveWhitespaceContext(&values); + RemoveWhitespaceContext(&values); if (values.size() == needle.size()) { if (values == needle) { line->skip = true; @@ -736,8 +778,7 @@ char* insertion = value_begin; while (values.size() >= needle.size()) { // Strip leading whitespace. - ssize_t cur_leading_whitespace = - strings::RemoveLeadingWhitespace(&values); + ssize_t cur_leading_whitespace = RemoveLeadingWhitespace(&values); // See if we've got a match (at least as a prefix). bool found = absl::StartsWith(values, needle); @@ -757,7 +798,7 @@ if (comma_found) { cur.remove_suffix(1); } - strings::RemoveTrailingWhitespace(&cur); + RemoveTrailingWhitespace(&cur); found = (cur.size() == needle.size()); }