Replace quiche::QuicheStringPiece with absl::string_view.
PiperOrigin-RevId: 336380679
Change-Id: Ib7b99bfe16215b15258d1ca67cd097e28c9b1289
diff --git a/common/platform/api/quiche_str_cat_test.cc b/common/platform/api/quiche_str_cat_test.cc
index 7085b8a..c9a5bfc 100644
--- a/common/platform/api/quiche_str_cat_test.cc
+++ b/common/platform/api/quiche_str_cat_test.cc
@@ -6,7 +6,7 @@
#include <string>
-#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
+#include "absl/strings/string_view.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_test.h"
namespace quiche {
@@ -46,7 +46,7 @@
std::string strs[] = {"Hello", "Cruel", "World"};
- QuicheStringPiece pieces[] = {"Hello", "Cruel", "World"};
+ absl::string_view pieces[] = {"Hello", "Cruel", "World"};
const char* c_strs[] = {"Hello", "Cruel", "World"};
diff --git a/common/platform/api/quiche_text_utils.h b/common/platform/api/quiche_text_utils.h
index 2cf920f..0aab251 100644
--- a/common/platform/api/quiche_text_utils.h
+++ b/common/platform/api/quiche_text_utils.h
@@ -7,9 +7,9 @@
#include <string>
+#include "absl/strings/string_view.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_export.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_optional.h"
-#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
#include "net/quiche/common/platform/impl/quiche_text_utils_impl.h"
namespace quiche {
@@ -18,55 +18,52 @@
class QUICHE_EXPORT QuicheTextUtils {
public:
// Returns true if |data| starts with |prefix|, case sensitively.
- static bool StartsWith(quiche::QuicheStringPiece data,
- quiche::QuicheStringPiece prefix) {
+ static bool StartsWith(absl::string_view data, absl::string_view prefix) {
return quiche::QuicheTextUtilsImpl::StartsWith(data, prefix);
}
// Returns true if |data| ends with |suffix|, case sensitively.
- static bool EndsWith(quiche::QuicheStringPiece data,
- quiche::QuicheStringPiece suffix) {
+ static bool EndsWith(absl::string_view data, absl::string_view suffix) {
return quiche::QuicheTextUtilsImpl::EndsWith(data, suffix);
}
// Returns true if |data| ends with |suffix|, case insensitively.
- static bool EndsWithIgnoreCase(quiche::QuicheStringPiece data,
- quiche::QuicheStringPiece suffix) {
+ static bool EndsWithIgnoreCase(absl::string_view data,
+ absl::string_view suffix) {
return quiche::QuicheTextUtilsImpl::EndsWithIgnoreCase(data, suffix);
}
// Returns a new string in which |data| has been converted to lower case.
- static std::string ToLower(quiche::QuicheStringPiece data) {
+ static std::string ToLower(absl::string_view data) {
return quiche::QuicheTextUtilsImpl::ToLower(data);
}
// Removes leading and trailing whitespace from |data|.
- static void RemoveLeadingAndTrailingWhitespace(
- quiche::QuicheStringPiece* data) {
+ static void RemoveLeadingAndTrailingWhitespace(absl::string_view* data) {
quiche::QuicheTextUtilsImpl::RemoveLeadingAndTrailingWhitespace(data);
}
// Returns true if |in| represents a valid uint64, and stores that value in
// |out|.
- static bool StringToUint64(quiche::QuicheStringPiece in, uint64_t* out) {
+ static bool StringToUint64(absl::string_view in, uint64_t* out) {
return quiche::QuicheTextUtilsImpl::StringToUint64(in, out);
}
// Returns true if |in| represents a valid int, and stores that value in
// |out|.
- static bool StringToInt(quiche::QuicheStringPiece in, int* out) {
+ static bool StringToInt(absl::string_view in, int* out) {
return quiche::QuicheTextUtilsImpl::StringToInt(in, out);
}
// Returns true if |in| represents a valid uint32, and stores that value in
// |out|.
- static bool StringToUint32(quiche::QuicheStringPiece in, uint32_t* out) {
+ static bool StringToUint32(absl::string_view in, uint32_t* out) {
return quiche::QuicheTextUtilsImpl::StringToUint32(in, out);
}
// Returns true if |in| represents a valid size_t, and stores that value in
// |out|.
- static bool StringToSizeT(quiche::QuicheStringPiece in, size_t* out) {
+ static bool StringToSizeT(absl::string_view in, size_t* out) {
return quiche::QuicheTextUtilsImpl::StringToSizeT(in, out);
}
@@ -79,13 +76,13 @@
// hexadecimal representation.
// Return value: 2*|length| characters of ASCII string.
static std::string HexEncode(const char* data, size_t length) {
- return HexEncode(quiche::QuicheStringPiece(data, length));
+ return HexEncode(absl::string_view(data, length));
}
// This converts |data.length()| bytes of binary to a
// 2*|data.length()|-character hexadecimal representation.
// Return value: 2*|data.length()| characters of ASCII string.
- static std::string HexEncode(quiche::QuicheStringPiece data) {
+ static std::string HexEncode(absl::string_view data) {
return quiche::QuicheTextUtilsImpl::HexEncode(data);
}
@@ -97,7 +94,7 @@
// Converts |data| from a hexadecimal ASCII string to a binary string
// that is |data.length()/2| bytes long.
- static std::string HexDecode(quiche::QuicheStringPiece data) {
+ static std::string HexDecode(absl::string_view data) {
return quiche::QuicheTextUtilsImpl::HexDecode(data);
}
@@ -110,7 +107,7 @@
// Decodes a base64-encoded |input|. Returns nullopt when the input is
// invalid.
- static QuicheOptional<std::string> Base64Decode(QuicheStringPiece input) {
+ static QuicheOptional<std::string> Base64Decode(absl::string_view input) {
return quiche::QuicheTextUtilsImpl::Base64Decode(input);
}
@@ -119,24 +116,23 @@
// printed as '.' in the ASCII output.
// For example, given the input "Hello, QUIC!\01\02\03\04", returns:
// "0x0000: 4865 6c6c 6f2c 2051 5549 4321 0102 0304 Hello,.QUIC!...."
- static std::string HexDump(quiche::QuicheStringPiece binary_data) {
+ static std::string HexDump(absl::string_view binary_data) {
return quiche::QuicheTextUtilsImpl::HexDump(binary_data);
}
// Returns true if |data| contains any uppercase characters.
- static bool ContainsUpperCase(quiche::QuicheStringPiece data) {
+ static bool ContainsUpperCase(absl::string_view data) {
return quiche::QuicheTextUtilsImpl::ContainsUpperCase(data);
}
// Returns true if |data| contains only decimal digits.
- static bool IsAllDigits(quiche::QuicheStringPiece data) {
+ static bool IsAllDigits(absl::string_view data) {
return quiche::QuicheTextUtilsImpl::IsAllDigits(data);
}
// Splits |data| into a vector of pieces delimited by |delim|.
- static std::vector<quiche::QuicheStringPiece> Split(
- quiche::QuicheStringPiece data,
- char delim) {
+ static std::vector<absl::string_view> Split(absl::string_view data,
+ char delim) {
return quiche::QuicheTextUtilsImpl::Split(data, delim);
}
};
diff --git a/common/platform/api/quiche_text_utils_test.cc b/common/platform/api/quiche_text_utils_test.cc
index 1ca75d2..c2f302d 100644
--- a/common/platform/api/quiche_text_utils_test.cc
+++ b/common/platform/api/quiche_text_utils_test.cc
@@ -48,7 +48,7 @@
for (auto* input : {"text", " text", " text", "text ", "text ", " text ",
" text ", "\r\n\ttext", "text\n\r\t"}) {
- quiche::QuicheStringPiece piece(input);
+ absl::string_view piece(input);
quiche::QuicheTextUtils::RemoveLeadingAndTrailingWhitespace(&piece);
EXPECT_EQ("text", piece);
}
@@ -214,16 +214,16 @@
}
TEST_F(QuicheTextUtilsTest, Split) {
- EXPECT_EQ(std::vector<quiche::QuicheStringPiece>({"a", "b", "c"}),
+ EXPECT_EQ(std::vector<absl::string_view>({"a", "b", "c"}),
quiche::QuicheTextUtils::Split("a,b,c", ','));
- EXPECT_EQ(std::vector<quiche::QuicheStringPiece>({"a", "b", "c"}),
+ EXPECT_EQ(std::vector<absl::string_view>({"a", "b", "c"}),
quiche::QuicheTextUtils::Split("a:b:c", ':'));
- EXPECT_EQ(std::vector<quiche::QuicheStringPiece>({"a:b:c"}),
+ EXPECT_EQ(std::vector<absl::string_view>({"a:b:c"}),
quiche::QuicheTextUtils::Split("a:b:c", ','));
// Leading and trailing whitespace is preserved.
- EXPECT_EQ(std::vector<quiche::QuicheStringPiece>({"a", "b", "c"}),
+ EXPECT_EQ(std::vector<absl::string_view>({"a", "b", "c"}),
quiche::QuicheTextUtils::Split("a,b,c", ','));
- EXPECT_EQ(std::vector<quiche::QuicheStringPiece>({" a", "b ", " c "}),
+ EXPECT_EQ(std::vector<absl::string_view>({" a", "b ", " c "}),
quiche::QuicheTextUtils::Split(" a:b : c ", ':'));
}
diff --git a/common/quiche_data_reader.cc b/common/quiche_data_reader.cc
index 2242fea..9d76e05 100644
--- a/common/quiche_data_reader.cc
+++ b/common/quiche_data_reader.cc
@@ -6,15 +6,15 @@
#include <cstring>
+#include "absl/strings/string_view.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_endian.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_logging.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_str_cat.h"
-#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_text_utils.h"
namespace quiche {
-QuicheDataReader::QuicheDataReader(quiche::QuicheStringPiece data)
+QuicheDataReader::QuicheDataReader(absl::string_view data)
: QuicheDataReader(data.data(), data.length(), quiche::NETWORK_BYTE_ORDER) {
}
@@ -77,7 +77,7 @@
return true;
}
-bool QuicheDataReader::ReadStringPiece16(quiche::QuicheStringPiece* result) {
+bool QuicheDataReader::ReadStringPiece16(absl::string_view* result) {
// Read resultant length.
uint16_t result_len;
if (!ReadUInt16(&result_len)) {
@@ -88,7 +88,7 @@
return ReadStringPiece(result, result_len);
}
-bool QuicheDataReader::ReadStringPiece8(quiche::QuicheStringPiece* result) {
+bool QuicheDataReader::ReadStringPiece8(absl::string_view* result) {
// Read resultant length.
uint8_t result_len;
if (!ReadUInt8(&result_len)) {
@@ -99,8 +99,7 @@
return ReadStringPiece(result, result_len);
}
-bool QuicheDataReader::ReadStringPiece(quiche::QuicheStringPiece* result,
- size_t size) {
+bool QuicheDataReader::ReadStringPiece(absl::string_view* result, size_t size) {
// Make sure that we have enough data to read.
if (!CanRead(size)) {
OnFailure();
@@ -108,7 +107,7 @@
}
// Set result.
- *result = quiche::QuicheStringPiece(data_ + pos_, size);
+ *result = absl::string_view(data_ + pos_, size);
// Iterate.
pos_ += size;
@@ -121,7 +120,7 @@
}
bool QuicheDataReader::ReadDecimal64(size_t num_digits, uint64_t* result) {
- quiche::QuicheStringPiece digits;
+ absl::string_view digits;
if (!ReadStringPiece(&digits, num_digits)) {
return false;
}
@@ -129,22 +128,22 @@
return QuicheTextUtils::StringToUint64(digits, result);
}
-quiche::QuicheStringPiece QuicheDataReader::ReadRemainingPayload() {
- quiche::QuicheStringPiece payload = PeekRemainingPayload();
+absl::string_view QuicheDataReader::ReadRemainingPayload() {
+ absl::string_view payload = PeekRemainingPayload();
pos_ = len_;
return payload;
}
-quiche::QuicheStringPiece QuicheDataReader::PeekRemainingPayload() const {
- return quiche::QuicheStringPiece(data_ + pos_, len_ - pos_);
+absl::string_view QuicheDataReader::PeekRemainingPayload() const {
+ return absl::string_view(data_ + pos_, len_ - pos_);
}
-quiche::QuicheStringPiece QuicheDataReader::FullPayload() const {
- return quiche::QuicheStringPiece(data_, len_);
+absl::string_view QuicheDataReader::FullPayload() const {
+ return absl::string_view(data_, len_);
}
-quiche::QuicheStringPiece QuicheDataReader::PreviouslyReadPayload() const {
- return quiche::QuicheStringPiece(data_, pos_);
+absl::string_view QuicheDataReader::PreviouslyReadPayload() const {
+ return absl::string_view(data_, pos_);
}
bool QuicheDataReader::ReadBytes(void* result, size_t size) {
diff --git a/common/quiche_data_reader.h b/common/quiche_data_reader.h
index f74f90d..f3911c5 100644
--- a/common/quiche_data_reader.h
+++ b/common/quiche_data_reader.h
@@ -9,10 +9,10 @@
#include <cstdint>
#include <limits>
+#include "absl/strings/string_view.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_endian.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_export.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_logging.h"
-#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
namespace quiche {
@@ -30,7 +30,7 @@
public:
// Constructs a reader using NETWORK_BYTE_ORDER endianness.
// Caller must provide an underlying buffer to work on.
- explicit QuicheDataReader(quiche::QuicheStringPiece data);
+ explicit QuicheDataReader(absl::string_view data);
// Constructs a reader using NETWORK_BYTE_ORDER endianness.
// Caller must provide an underlying buffer to work on.
QuicheDataReader(const char* data, const size_t len);
@@ -64,7 +64,7 @@
//
// Forwards the internal iterator on success.
// Returns true on success, false otherwise.
- bool ReadStringPiece16(quiche::QuicheStringPiece* result);
+ bool ReadStringPiece16(absl::string_view* result);
// Reads a string prefixed with 8-bit length into the given output parameter.
//
@@ -73,13 +73,13 @@
//
// Forwards the internal iterator on success.
// Returns true on success, false otherwise.
- bool ReadStringPiece8(quiche::QuicheStringPiece* result);
+ bool ReadStringPiece8(absl::string_view* result);
// Reads a given number of bytes into the given buffer. The buffer
// must be of adequate size.
// Forwards the internal iterator on success.
// Returns true on success, false otherwise.
- bool ReadStringPiece(quiche::QuicheStringPiece* result, size_t size);
+ bool ReadStringPiece(absl::string_view* result, size_t size);
// Reads tag represented as 32-bit unsigned integer into given output
// parameter. Tags are in big endian on the wire (e.g., CHLO is
@@ -92,38 +92,38 @@
// iterator on success, may forward it even in case of failure.
bool ReadDecimal64(size_t num_digits, uint64_t* result);
- // Returns the remaining payload as a quiche::QuicheStringPiece.
+ // Returns the remaining payload as a absl::string_view.
//
// NOTE: Does not copy but rather references strings in the underlying buffer.
// This should be kept in mind when handling memory management!
//
// Forwards the internal iterator.
- quiche::QuicheStringPiece ReadRemainingPayload();
+ absl::string_view ReadRemainingPayload();
- // Returns the remaining payload as a quiche::QuicheStringPiece.
+ // Returns the remaining payload as a absl::string_view.
//
// NOTE: Does not copy but rather references strings in the underlying buffer.
// This should be kept in mind when handling memory management!
//
// DOES NOT forward the internal iterator.
- quiche::QuicheStringPiece PeekRemainingPayload() const;
+ absl::string_view PeekRemainingPayload() const;
- // Returns the entire payload as a quiche::QuicheStringPiece.
+ // Returns the entire payload as a absl::string_view.
//
// NOTE: Does not copy but rather references strings in the underlying buffer.
// This should be kept in mind when handling memory management!
//
// DOES NOT forward the internal iterator.
- quiche::QuicheStringPiece FullPayload() const;
+ absl::string_view FullPayload() const;
// Returns the part of the payload that has been already read as a
- // quiche::QuicheStringPiece.
+ // absl::string_view.
//
// NOTE: Does not copy but rather references strings in the underlying buffer.
// This should be kept in mind when handling memory management!
//
// DOES NOT forward the internal iterator.
- quiche::QuicheStringPiece PreviouslyReadPayload() const;
+ absl::string_view PreviouslyReadPayload() const;
// Reads a given number of bytes into the given buffer. The buffer
// must be of adequate size.
diff --git a/common/quiche_data_writer.cc b/common/quiche_data_writer.cc
index 4488f72..d24a594 100644
--- a/common/quiche_data_writer.cc
+++ b/common/quiche_data_writer.cc
@@ -7,9 +7,9 @@
#include <algorithm>
#include <limits>
+#include "absl/strings/string_view.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_endian.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_str_cat.h"
-#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
namespace quiche {
@@ -65,7 +65,7 @@
num_bytes);
}
-bool QuicheDataWriter::WriteStringPiece16(quiche::QuicheStringPiece val) {
+bool QuicheDataWriter::WriteStringPiece16(absl::string_view val) {
if (val.size() > std::numeric_limits<uint16_t>::max()) {
return false;
}
@@ -75,7 +75,7 @@
return WriteBytes(val.data(), val.size());
}
-bool QuicheDataWriter::WriteStringPiece(quiche::QuicheStringPiece val) {
+bool QuicheDataWriter::WriteStringPiece(absl::string_view val) {
return WriteBytes(val.data(), val.size());
}
diff --git a/common/quiche_data_writer.h b/common/quiche_data_writer.h
index cded0fa..150657e 100644
--- a/common/quiche_data_writer.h
+++ b/common/quiche_data_writer.h
@@ -10,10 +10,10 @@
#include <cstring>
#include <limits>
+#include "absl/strings/string_view.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_endian.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_export.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_logging.h"
-#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
namespace quiche {
@@ -54,8 +54,8 @@
// correct byte order.
bool WriteBytesToUInt64(size_t num_bytes, uint64_t value);
- bool WriteStringPiece(quiche::QuicheStringPiece val);
- bool WriteStringPiece16(quiche::QuicheStringPiece val);
+ bool WriteStringPiece(absl::string_view val);
+ bool WriteStringPiece16(absl::string_view val);
bool WriteBytes(const void* data, size_t data_len);
bool WriteRepeatedByte(uint8_t byte, size_t count);
// Fills the remaining buffer with null characters.
diff --git a/common/quiche_data_writer_test.cc b/common/quiche_data_writer_test.cc
index 343e6ea..72ce2c9 100644
--- a/common/quiche_data_writer_test.cc
+++ b/common/quiche_data_writer_test.cc
@@ -7,10 +7,10 @@
#include <cstdint>
#include <cstring>
+#include "absl/strings/string_view.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_arraysize.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_endian.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_str_cat.h"
-#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_test.h"
#include "net/third_party/quiche/src/common/quiche_data_reader.h"
#include "net/third_party/quiche/src/common/test_tools/quiche_test_utils.h"
@@ -386,43 +386,38 @@
char expected_first_read[4] = {1, 2, 3, 4};
char expected_remaining[12] = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
QuicheDataReader reader(buffer, sizeof(buffer));
- quiche::QuicheStringPiece previously_read_payload1 =
- reader.PreviouslyReadPayload();
+ absl::string_view previously_read_payload1 = reader.PreviouslyReadPayload();
EXPECT_TRUE(previously_read_payload1.empty());
char first_read_buffer[4] = {};
EXPECT_TRUE(reader.ReadBytes(first_read_buffer, sizeof(first_read_buffer)));
test::CompareCharArraysWithHexError(
"first read", first_read_buffer, sizeof(first_read_buffer),
expected_first_read, sizeof(expected_first_read));
- quiche::QuicheStringPiece peeked_remaining_payload =
- reader.PeekRemainingPayload();
+ absl::string_view peeked_remaining_payload = reader.PeekRemainingPayload();
test::CompareCharArraysWithHexError(
"peeked_remaining_payload", peeked_remaining_payload.data(),
peeked_remaining_payload.length(), expected_remaining,
sizeof(expected_remaining));
- quiche::QuicheStringPiece full_payload = reader.FullPayload();
+ absl::string_view full_payload = reader.FullPayload();
test::CompareCharArraysWithHexError("full_payload", full_payload.data(),
full_payload.length(), buffer,
sizeof(buffer));
- quiche::QuicheStringPiece previously_read_payload2 =
- reader.PreviouslyReadPayload();
+ absl::string_view previously_read_payload2 = reader.PreviouslyReadPayload();
test::CompareCharArraysWithHexError(
"previously_read_payload2", previously_read_payload2.data(),
previously_read_payload2.length(), first_read_buffer,
sizeof(first_read_buffer));
- quiche::QuicheStringPiece read_remaining_payload =
- reader.ReadRemainingPayload();
+ absl::string_view read_remaining_payload = reader.ReadRemainingPayload();
test::CompareCharArraysWithHexError(
"read_remaining_payload", read_remaining_payload.data(),
read_remaining_payload.length(), expected_remaining,
sizeof(expected_remaining));
EXPECT_TRUE(reader.IsDoneReading());
- quiche::QuicheStringPiece full_payload2 = reader.FullPayload();
+ absl::string_view full_payload2 = reader.FullPayload();
test::CompareCharArraysWithHexError("full_payload2", full_payload2.data(),
full_payload2.length(), buffer,
sizeof(buffer));
- quiche::QuicheStringPiece previously_read_payload3 =
- reader.PreviouslyReadPayload();
+ absl::string_view previously_read_payload3 = reader.PreviouslyReadPayload();
test::CompareCharArraysWithHexError(
"previously_read_payload3", previously_read_payload3.data(),
previously_read_payload3.length(), buffer, sizeof(buffer));