Rename string's raw_span() method to unsigned_span().
Prevent confusion with a forthcoming raw_span<> type.
Then do the same for raw_str() to unsigned_str(),
Then put the word "unterminated" into the view methods.
-- Fully automated change for raw_span() and raw_str().
-- Manual change for unterminated_unsigned_span().
Change-Id: I0a2d08f3f3d0ed8b7dbb45fb8bd6ff24975b66e6
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/117152
Reviewed-by: Thomas Sepez <tsepez@google.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_cmap.cpp b/core/fpdfapi/font/cpdf_cmap.cpp
index 0eee5a0..b6e5ead 100644
--- a/core/fpdfapi/font/cpdf_cmap.cpp
+++ b/core/fpdfapi/font/cpdf_cmap.cpp
@@ -361,7 +361,7 @@
uint32_t CPDF_CMap::GetNextChar(ByteStringView pString, size_t* pOffset) const {
size_t& offset = *pOffset;
- auto pBytes = pString.raw_span();
+ auto pBytes = pString.unsigned_span();
switch (m_CodingScheme) {
case OneByte: {
return offset < pBytes.size() ? pBytes[offset++] : 0;
diff --git a/core/fpdfapi/page/cpdf_indexedcs.cpp b/core/fpdfapi/page/cpdf_indexedcs.cpp
index 1c0b77b..79ffc5e 100644
--- a/core/fpdfapi/page/cpdf_indexedcs.cpp
+++ b/core/fpdfapi/page/cpdf_indexedcs.cpp
@@ -99,7 +99,7 @@
}
std::vector<float> comps(m_nBaseComponents);
- const uint8_t* pTable = m_Table.raw_str();
+ const uint8_t* pTable = m_Table.unsigned_str();
for (uint32_t i = 0; i < m_nBaseComponents; ++i) {
comps[i] =
m_pCompMinMax[i * 2] +
diff --git a/core/fpdfapi/parser/cpdf_crypto_handler.cpp b/core/fpdfapi/parser/cpdf_crypto_handler.cpp
index 61dac42..8d73916 100644
--- a/core/fpdfapi/parser/cpdf_crypto_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_crypto_handler.cpp
@@ -214,7 +214,7 @@
const ByteString& str) {
BinaryBuffer dest_buf;
void* context = DecryptStart(objnum, gennum);
- DecryptStream(context, str.raw_span(), dest_buf);
+ DecryptStream(context, str.unsigned_span(), dest_buf);
DecryptFinish(context, dest_buf);
return ByteString(dest_buf.GetSpan());
}
diff --git a/core/fpdfapi/parser/cpdf_name.cpp b/core/fpdfapi/parser/cpdf_name.cpp
index 6236ef4..37ef20f 100644
--- a/core/fpdfapi/parser/cpdf_name.cpp
+++ b/core/fpdfapi/parser/cpdf_name.cpp
@@ -39,7 +39,7 @@
}
WideString CPDF_Name::GetUnicodeText() const {
- return PDF_DecodeText(m_Name.raw_span());
+ return PDF_DecodeText(m_Name.unsigned_span());
}
bool CPDF_Name::WriteTo(IFX_ArchiveStream* archive,
diff --git a/core/fpdfapi/parser/cpdf_security_handler.cpp b/core/fpdfapi/parser/cpdf_security_handler.cpp
index 3155999..005ebe5 100644
--- a/core/fpdfapi/parser/cpdf_security_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_security_handler.cpp
@@ -38,7 +38,7 @@
DCHECK_EQ(sizeof(kDefaultPasscode), output.size());
size_t len = std::min(password.GetLength(), output.size());
size_t remaining = output.size() - len;
- FXSYS_memcpy(output.data(), password.raw_str(), len);
+ FXSYS_memcpy(output.data(), password.unsigned_str(), len);
if (remaining) {
memcpy(&output[len], kDefaultPasscode, remaining);
}
@@ -55,11 +55,11 @@
CRYPT_md5_context md5 = CRYPT_MD5Start();
CRYPT_MD5Update(&md5, passcode);
ByteString okey = pEncrypt->GetByteStringFor("O");
- CRYPT_MD5Update(&md5, okey.raw_span());
+ CRYPT_MD5Update(&md5, okey.unsigned_span());
uint32_t perm = pEncrypt->GetIntegerFor("P");
CRYPT_MD5Update(&md5, pdfium::as_bytes(pdfium::span_from_ref(perm)));
if (!file_id.IsEmpty())
- CRYPT_MD5Update(&md5, file_id.raw_span());
+ CRYPT_MD5Update(&md5, file_id.unsigned_span());
const bool is_revision_3_or_greater = pEncrypt->GetIntegerFor("R") >= 3;
if (!ignore_metadata && is_revision_3_or_greater &&
!pEncrypt->GetBooleanFor("EncryptMetadata", true)) {
@@ -108,7 +108,7 @@
uint8_t* hash) {
CRYPT_sha2_context sha;
CRYPT_SHA256Start(&sha);
- CRYPT_SHA256Update(&sha, password.raw_str(), password.GetLength());
+ CRYPT_SHA256Update(&sha, password.unsigned_str(), password.GetLength());
CRYPT_SHA256Update(&sha, salt, 8);
if (vector)
CRYPT_SHA256Update(&sha, vector, 48);
@@ -133,8 +133,8 @@
auto encrypted_output_span = pdfium::make_span(encrypted_output);
DataVector<uint8_t> content;
for (int j = 0; j < 64; ++j) {
- content.insert(std::end(content), password.raw_str(),
- password.raw_str() + password.GetLength());
+ content.insert(std::end(content), password.unsigned_str(),
+ password.unsigned_str() + password.GetLength());
content.insert(std::end(content), input, input + block_size);
if (vector) {
content.insert(std::end(content), vector, vector + 48);
@@ -332,18 +332,18 @@
if (ukey.GetLength() < 48)
return false;
- const uint8_t* pkey = bOwner ? okey.raw_str() : ukey.raw_str();
+ const uint8_t* pkey = bOwner ? okey.unsigned_str() : ukey.unsigned_str();
CRYPT_sha2_context sha;
uint8_t digest[32];
if (m_Revision >= 6) {
Revision6_Hash(password, (const uint8_t*)pkey + 32,
- bOwner ? ukey.raw_str() : nullptr, digest);
+ bOwner ? ukey.unsigned_str() : nullptr, digest);
} else {
CRYPT_SHA256Start(&sha);
- CRYPT_SHA256Update(&sha, password.raw_str(), password.GetLength());
+ CRYPT_SHA256Update(&sha, password.unsigned_str(), password.GetLength());
CRYPT_SHA256Update(&sha, pkey + 32, 8);
if (bOwner)
- CRYPT_SHA256Update(&sha, ukey.raw_str(), 48);
+ CRYPT_SHA256Update(&sha, ukey.unsigned_str(), 48);
CRYPT_SHA256Finish(&sha, digest);
}
if (memcmp(digest, pkey, 32) != 0)
@@ -351,13 +351,13 @@
if (m_Revision >= 6) {
Revision6_Hash(password, (const uint8_t*)pkey + 40,
- bOwner ? ukey.raw_str() : nullptr, digest);
+ bOwner ? ukey.unsigned_str() : nullptr, digest);
} else {
CRYPT_SHA256Start(&sha);
- CRYPT_SHA256Update(&sha, password.raw_str(), password.GetLength());
+ CRYPT_SHA256Update(&sha, password.unsigned_str(), password.GetLength());
CRYPT_SHA256Update(&sha, pkey + 40, 8);
if (bOwner)
- CRYPT_SHA256Update(&sha, ukey.raw_str(), 48);
+ CRYPT_SHA256Update(&sha, ukey.unsigned_str(), 48);
CRYPT_SHA256Finish(&sha, digest);
}
ByteString ekey = m_pEncryptDict->GetByteStringFor(bOwner ? "OE" : "UE");
@@ -368,7 +368,7 @@
CRYPT_AESSetKey(&aes, digest, sizeof(digest));
uint8_t iv[16] = {};
CRYPT_AESSetIV(&aes, iv);
- CRYPT_AESDecrypt(&aes, m_EncryptKey.data(), ekey.raw_str(), 32);
+ CRYPT_AESDecrypt(&aes, m_EncryptKey.data(), ekey.unsigned_str(), 32);
CRYPT_AESSetKey(&aes, m_EncryptKey.data(), m_EncryptKey.size());
CRYPT_AESSetIV(&aes, iv);
ByteString perms = m_pEncryptDict->GetByteStringFor("Perms");
@@ -378,7 +378,7 @@
uint8_t perms_buf[16] = {};
size_t copy_len =
std::min(sizeof(perms_buf), static_cast<size_t>(perms.GetLength()));
- memcpy(perms_buf, perms.raw_str(), copy_len);
+ memcpy(perms_buf, perms.unsigned_str(), copy_len);
uint8_t buf[16];
CRYPT_AESDecrypt(&aes, buf, perms_buf, 16);
if (buf[9] != 'a' || buf[10] != 'd' || buf[11] != 'b')
@@ -467,7 +467,7 @@
CRYPT_md5_context md5 = CRYPT_MD5Start();
CRYPT_MD5Update(&md5, kDefaultPasscode);
if (!m_FileId.IsEmpty())
- CRYPT_MD5Update(&md5, m_FileId.raw_span());
+ CRYPT_MD5Update(&md5, m_FileId.unsigned_span());
CRYPT_MD5Finish(&md5, ukeybuf);
return memcmp(test, ukeybuf, 16) == 0;
}
@@ -578,7 +578,7 @@
CRYPT_md5_context md5 = CRYPT_MD5Start();
CRYPT_MD5Update(&md5, kDefaultPasscode);
if (!file_id.IsEmpty())
- CRYPT_MD5Update(&md5, file_id.raw_span());
+ CRYPT_MD5Update(&md5, file_id.unsigned_span());
uint8_t digest[32];
CRYPT_MD5Finish(&md5, digest);
@@ -614,7 +614,7 @@
Revision6_Hash(password, digest, nullptr, digest1);
} else {
CRYPT_SHA256Start(&sha2);
- CRYPT_SHA256Update(&sha2, password.raw_str(), password.GetLength());
+ CRYPT_SHA256Update(&sha2, password.unsigned_str(), password.GetLength());
CRYPT_SHA256Update(&sha2, digest, 8);
CRYPT_SHA256Finish(&sha2, digest1);
}
@@ -624,7 +624,7 @@
Revision6_Hash(password, digest + 8, nullptr, digest1);
} else {
CRYPT_SHA256Start(&sha2);
- CRYPT_SHA256Update(&sha2, password.raw_str(), password.GetLength());
+ CRYPT_SHA256Update(&sha2, password.unsigned_str(), password.GetLength());
CRYPT_SHA256Update(&sha2, digest + 8, 8);
CRYPT_SHA256Finish(&sha2, digest1);
}
diff --git a/core/fpdfapi/parser/cpdf_seekablemultistream_unittest.cpp b/core/fpdfapi/parser/cpdf_seekablemultistream_unittest.cpp
index 040d6e6..95427a5 100644
--- a/core/fpdfapi/parser/cpdf_seekablemultistream_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_seekablemultistream_unittest.cpp
@@ -45,9 +45,9 @@
ByteStringView one_view(kOne);
ByteStringView two_view(kTwo);
ByteStringView three_view(kThree);
- auto stream1 = pdfium::MakeRetain<CPDF_Stream>(one_view.raw_span());
- auto stream2 = pdfium::MakeRetain<CPDF_Stream>(two_view.raw_span());
- auto stream3 = pdfium::MakeRetain<CPDF_Stream>(three_view.raw_span());
+ auto stream1 = pdfium::MakeRetain<CPDF_Stream>(one_view.unsigned_span());
+ auto stream2 = pdfium::MakeRetain<CPDF_Stream>(two_view.unsigned_span());
+ auto stream3 = pdfium::MakeRetain<CPDF_Stream>(three_view.unsigned_span());
std::vector<RetainPtr<const CPDF_Stream>> streams;
streams.push_back(std::move(stream1));
diff --git a/core/fpdfapi/parser/cpdf_string.cpp b/core/fpdfapi/parser/cpdf_string.cpp
index 25eedbf..f699eb5 100644
--- a/core/fpdfapi/parser/cpdf_string.cpp
+++ b/core/fpdfapi/parser/cpdf_string.cpp
@@ -57,13 +57,13 @@
}
WideString CPDF_String::GetUnicodeText() const {
- return PDF_DecodeText(m_String.raw_span());
+ return PDF_DecodeText(m_String.unsigned_span());
}
bool CPDF_String::WriteTo(IFX_ArchiveStream* archive,
const CPDF_Encryptor* encryptor) const {
DataVector<uint8_t> encrypted_data;
- pdfium::span<const uint8_t> data = m_String.raw_span();
+ pdfium::span<const uint8_t> data = m_String.unsigned_span();
if (encryptor) {
encrypted_data = encryptor->Encrypt(data);
data = encrypted_data;
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 7425aa4..52400c1 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -756,7 +756,7 @@
// Earlier version of PDF specification doesn't require EOL marker before
// 'endstream' keyword. If keyword 'endstream' follows the bytes in
// specified length, it signals the end of stream.
- if (memcmp(m_WordBuffer.data(), kEndStreamStr.raw_str(),
+ if (memcmp(m_WordBuffer.data(), kEndStreamStr.unterminated_unsigned_str(),
kEndStreamStr.GetLength()) != 0) {
substream.Reset();
len = -1;
@@ -821,7 +821,7 @@
int numMarkers = ReadEOLMarkers(GetPos());
if (m_WordSize == static_cast<unsigned int>(kEndObjStr.GetLength()) &&
numMarkers != 0 &&
- memcmp(m_WordBuffer.data(), kEndObjStr.raw_str(),
+ memcmp(m_WordBuffer.data(), kEndObjStr.unterminated_unsigned_str(),
kEndObjStr.GetLength()) == 0) {
SetPos(end_stream_offset);
}
diff --git a/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp b/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp
index e32b6aa..c724b2b 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp
@@ -429,7 +429,7 @@
for (int pdf_code_point = 0; pdf_code_point < 256; ++pdf_code_point) {
ByteString original(static_cast<char>(pdf_code_point));
ByteString reencoded =
- PDF_EncodeText(PDF_DecodeText(original.raw_span()).AsStringView());
+ PDF_EncodeText(PDF_DecodeText(original.unsigned_span()).AsStringView());
switch (pdf_code_point) {
case 0x7F:
diff --git a/core/fpdfapi/parser/fpdf_parser_utility.cpp b/core/fpdfapi/parser/fpdf_parser_utility.cpp
index 29d3df0..db94e36 100644
--- a/core/fpdfapi/parser/fpdf_parser_utility.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_utility.cpp
@@ -111,7 +111,7 @@
}
ByteString PDF_NameEncode(const ByteString& orig) {
- pdfium::span<const uint8_t> src_span = orig.raw_span();
+ pdfium::span<const uint8_t> src_span = orig.unsigned_span();
size_t dest_len = 0;
for (const auto ch : src_span) {
if (ch >= 0x80 || PDFCharIsWhitespace(ch) || ch == '#' ||
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
index ff3ed81..f662e54 100644
--- a/core/fpdfdoc/cpdf_annotlist.cpp
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -83,7 +83,7 @@
// /Contents is empty or not. If so, optimize decoding for empty check.
ByteString contents =
pParentDict->GetByteStringFor(pdfium::annotation::kContents);
- if (PDF_DecodeText(contents.raw_span()).IsEmpty()) {
+ if (PDF_DecodeText(contents.unsigned_span()).IsEmpty()) {
return nullptr;
}
diff --git a/core/fpdfdoc/cpdf_defaultappearance.cpp b/core/fpdfdoc/cpdf_defaultappearance.cpp
index 7536f1e..a0abdad 100644
--- a/core/fpdfdoc/cpdf_defaultappearance.cpp
+++ b/core/fpdfdoc/cpdf_defaultappearance.cpp
@@ -71,7 +71,7 @@
return std::nullopt;
ByteString csFontNameTag;
- CPDF_SimpleParser syntax(m_csDA.AsStringView().raw_span());
+ CPDF_SimpleParser syntax(m_csDA.AsStringView().unsigned_span());
if (FindTagParamFromStart(&syntax, "Tf", 2)) {
csFontNameTag = ByteString(syntax.GetWord());
csFontNameTag.Delete(0, 1);
@@ -84,7 +84,7 @@
if (m_csDA.IsEmpty())
return std::nullopt;
- CPDF_SimpleParser syntax(m_csDA.AsStringView().raw_span());
+ CPDF_SimpleParser syntax(m_csDA.AsStringView().unsigned_span());
if (FindTagParamFromStart(&syntax, "g", 1)) {
float gray = StringToFloat(syntax.GetWord());
return CFX_Color(CFX_Color::Type::kGray, gray);
diff --git a/core/fpdfdoc/cpdf_formcontrol.cpp b/core/fpdfdoc/cpdf_formcontrol.cpp
index f069178..4d9d653 100644
--- a/core/fpdfdoc/cpdf_formcontrol.cpp
+++ b/core/fpdfdoc/cpdf_formcontrol.cpp
@@ -91,7 +91,7 @@
csOn = pArray->GetByteStringAt(m_pField->GetControlIndex(this));
if (csOn.IsEmpty())
csOn = "Yes";
- return PDF_DecodeText(csOn.raw_span());
+ return PDF_DecodeText(csOn.unsigned_span());
}
bool CPDF_FormControl::IsChecked() const {
diff --git a/core/fpdfdoc/cpdf_metadata_unittest.cpp b/core/fpdfdoc/cpdf_metadata_unittest.cpp
index 0618fba..ab71dc2 100644
--- a/core/fpdfdoc/cpdf_metadata_unittest.cpp
+++ b/core/fpdfdoc/cpdf_metadata_unittest.cpp
@@ -16,7 +16,7 @@
"</node>";
auto stream =
- pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).raw_span());
+ pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).unsigned_span());
CPDF_Metadata metadata(stream);
auto results = metadata.CheckForSharedForm();
@@ -33,7 +33,7 @@
"</node>";
auto stream =
- pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).raw_span());
+ pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).unsigned_span());
CPDF_Metadata metadata(stream);
auto results = metadata.CheckForSharedForm();
@@ -50,7 +50,7 @@
"</node>";
auto stream =
- pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).raw_span());
+ pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).unsigned_span());
CPDF_Metadata metadata(stream);
auto results = metadata.CheckForSharedForm();
@@ -67,7 +67,7 @@
"</node>";
auto stream =
- pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).raw_span());
+ pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).unsigned_span());
CPDF_Metadata metadata(stream);
auto results = metadata.CheckForSharedForm();
@@ -85,7 +85,7 @@
"</parent></grandparent>";
auto stream =
- pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).raw_span());
+ pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).unsigned_span());
CPDF_Metadata metadata(stream);
auto results = metadata.CheckForSharedForm();
@@ -99,7 +99,7 @@
"<node></node>";
auto stream =
- pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).raw_span());
+ pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).unsigned_span());
CPDF_Metadata metadata(stream);
auto results = metadata.CheckForSharedForm();
@@ -132,7 +132,7 @@
"</parent>";
auto stream =
- pdfium::MakeRetain<CPDF_Stream>(ByteStringView(kData).raw_span());
+ pdfium::MakeRetain<CPDF_Stream>(ByteStringView(kData).unsigned_span());
CPDF_Metadata metadata(stream);
auto results = metadata.CheckForSharedForm();
@@ -148,7 +148,7 @@
"</node>";
auto stream =
- pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).raw_span());
+ pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).unsigned_span());
CPDF_Metadata metadata(stream);
auto results = metadata.CheckForSharedForm();
@@ -178,7 +178,7 @@
"</grandparent>";
auto stream =
- pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).raw_span());
+ pdfium::MakeRetain<CPDF_Stream>(ByteStringView(data).unsigned_span());
CPDF_Metadata metadata(stream);
auto results = metadata.CheckForSharedForm();
diff --git a/core/fpdfdoc/cpdf_nametree.cpp b/core/fpdfdoc/cpdf_nametree.cpp
index f07aa62..55c8a0d 100644
--- a/core/fpdfdoc/cpdf_nametree.cpp
+++ b/core/fpdfdoc/cpdf_nametree.cpp
@@ -580,5 +580,6 @@
RetainPtr<const CPDF_Array> CPDF_NameTree::LookupNewStyleNamedDest(
const ByteString& sName) {
- return GetNamedDestFromObject(LookupValue(PDF_DecodeText(sName.raw_span())));
+ return GetNamedDestFromObject(
+ LookupValue(PDF_DecodeText(sName.unsigned_span())));
}
diff --git a/core/fxcrt/binary_buffer.cpp b/core/fxcrt/binary_buffer.cpp
index 1fa8bc7..4272cd2 100644
--- a/core/fxcrt/binary_buffer.cpp
+++ b/core/fxcrt/binary_buffer.cpp
@@ -100,7 +100,7 @@
}
void BinaryBuffer::AppendString(const ByteString& str) {
- AppendSpan(str.raw_span());
+ AppendSpan(str.unsigned_span());
}
void BinaryBuffer::AppendUint8(uint8_t value) {
diff --git a/core/fxcrt/bytestring.cpp b/core/fxcrt/bytestring.cpp
index de5ddb5..875968d 100644
--- a/core/fxcrt/bytestring.cpp
+++ b/core/fxcrt/bytestring.cpp
@@ -278,7 +278,7 @@
return false;
}
pdfium::span<const uint8_t> this_span = pdfium::as_bytes(m_pData->span());
- pdfium::span<const uint8_t> that_span = str.raw_span();
+ pdfium::span<const uint8_t> that_span = str.unsigned_span();
while (!this_span.empty()) {
uint8_t this_char = this_span.front();
uint8_t that_char = that_span.front();
diff --git a/core/fxcrt/bytestring_unittest.cpp b/core/fxcrt/bytestring_unittest.cpp
index 7c2a665..470cd98 100644
--- a/core/fxcrt/bytestring_unittest.cpp
+++ b/core/fxcrt/bytestring_unittest.cpp
@@ -32,7 +32,7 @@
EXPECT_EQ(3u, abc_span.size());
EXPECT_EQ(0, memcmp(abc_span.data(), "abc", 3));
- pdfium::span<const uint8_t> abc_raw_span = abc.raw_span();
+ pdfium::span<const uint8_t> abc_raw_span = abc.unsigned_span();
EXPECT_EQ(3u, abc_raw_span.size());
EXPECT_EQ(0, memcmp(abc_raw_span.data(), "abc", 3));
@@ -1150,7 +1150,7 @@
TEST(ByteStringView, Null) {
ByteStringView null_string;
- EXPECT_FALSE(null_string.raw_str());
+ EXPECT_FALSE(null_string.unterminated_unsigned_str());
EXPECT_EQ(0u, null_string.GetLength());
EXPECT_TRUE(null_string.IsEmpty());
@@ -1158,40 +1158,40 @@
EXPECT_EQ(null_string, another_null_string);
ByteStringView copied_null_string(null_string);
- EXPECT_FALSE(copied_null_string.raw_str());
+ EXPECT_FALSE(copied_null_string.unterminated_unsigned_str());
EXPECT_EQ(0u, copied_null_string.GetLength());
EXPECT_TRUE(copied_null_string.IsEmpty());
EXPECT_EQ(null_string, copied_null_string);
ByteStringView span_null_string = pdfium::span<const uint8_t>();
- EXPECT_FALSE(span_null_string.raw_str());
+ EXPECT_FALSE(span_null_string.unterminated_unsigned_str());
EXPECT_EQ(0u, span_null_string.GetLength());
EXPECT_TRUE(span_null_string.IsEmpty());
EXPECT_EQ(null_string, span_null_string);
ByteStringView empty_string(""); // Pointer to NUL, not NULL pointer.
- EXPECT_TRUE(empty_string.raw_str());
+ EXPECT_TRUE(empty_string.unterminated_unsigned_str());
EXPECT_EQ(0u, empty_string.GetLength());
EXPECT_TRUE(empty_string.IsEmpty());
EXPECT_EQ(null_string, empty_string);
ByteStringView assigned_null_string("initially not nullptr");
assigned_null_string = null_string;
- EXPECT_FALSE(assigned_null_string.raw_str());
+ EXPECT_FALSE(assigned_null_string.unterminated_unsigned_str());
EXPECT_EQ(0u, assigned_null_string.GetLength());
EXPECT_TRUE(assigned_null_string.IsEmpty());
EXPECT_EQ(null_string, assigned_null_string);
ByteStringView assigned_nullptr_string("initially not nullptr");
assigned_nullptr_string = nullptr;
- EXPECT_FALSE(assigned_nullptr_string.raw_str());
+ EXPECT_FALSE(assigned_nullptr_string.unterminated_unsigned_str());
EXPECT_EQ(0u, assigned_nullptr_string.GetLength());
EXPECT_TRUE(assigned_nullptr_string.IsEmpty());
EXPECT_EQ(null_string, assigned_nullptr_string);
ByteStringView assigned_span_null_string("initially not null span");
assigned_span_null_string = pdfium::span<const uint8_t>();
- EXPECT_FALSE(assigned_span_null_string.raw_str());
+ EXPECT_FALSE(assigned_span_null_string.unterminated_unsigned_str());
EXPECT_EQ(0u, assigned_span_null_string.GetLength());
EXPECT_TRUE(assigned_span_null_string.IsEmpty());
EXPECT_EQ(null_string, assigned_span_null_string);
@@ -1286,7 +1286,7 @@
cleared_vec.pop_back();
ByteStringView cleared_string(cleared_vec);
EXPECT_EQ(0u, cleared_string.GetLength());
- EXPECT_FALSE(cleared_string.raw_str());
+ EXPECT_FALSE(cleared_string.unterminated_unsigned_str());
}
TEST(ByteStringView, GetID) {
@@ -1520,7 +1520,7 @@
pdfium::span<const uint8_t> span5(
pdfium::as_bytes(pdfium::make_span("hello", 5u)));
- auto raw_span = byte_string_c.raw_span();
+ auto raw_span = byte_string_c.unsigned_span();
EXPECT_TRUE(
std::equal(raw_span.begin(), raw_span.end(), span5.begin(), span5.end()));
}
@@ -1733,14 +1733,14 @@
EXPECT_TRUE(cstr);
EXPECT_EQ(0u, strlen(cstr));
- const uint8_t* rstr = empty_str.raw_str();
+ const uint8_t* rstr = empty_str.unsigned_str();
EXPECT_FALSE(rstr);
pdfium::span<const char> cspan = empty_str.span();
EXPECT_TRUE(cspan.empty());
EXPECT_FALSE(cspan.data());
- pdfium::span<const uint8_t> rspan = empty_str.raw_span();
+ pdfium::span<const uint8_t> rspan = empty_str.unsigned_span();
EXPECT_TRUE(rspan.empty());
EXPECT_FALSE(rspan.data());
}
diff --git a/core/fxcrt/cfx_read_only_string_stream.cpp b/core/fxcrt/cfx_read_only_string_stream.cpp
index 5967ed8..74d9344 100644
--- a/core/fxcrt/cfx_read_only_string_stream.cpp
+++ b/core/fxcrt/cfx_read_only_string_stream.cpp
@@ -11,7 +11,8 @@
CFX_ReadOnlyStringStream::CFX_ReadOnlyStringStream(ByteString data)
: data_(std::move(data)),
- stream_(pdfium::MakeRetain<CFX_ReadOnlySpanStream>(data_.raw_span())) {}
+ stream_(
+ pdfium::MakeRetain<CFX_ReadOnlySpanStream>(data_.unsigned_span())) {}
CFX_ReadOnlyStringStream::~CFX_ReadOnlyStringStream() = default;
diff --git a/core/fxcrt/fx_stream.cpp b/core/fxcrt/fx_stream.cpp
index 63ce068..f63c14b 100644
--- a/core/fxcrt/fx_stream.cpp
+++ b/core/fxcrt/fx_stream.cpp
@@ -45,7 +45,7 @@
} // namespace
bool IFX_WriteStream::WriteString(ByteStringView str) {
- return WriteBlock(str.raw_span());
+ return WriteBlock(str.unsigned_span());
}
bool IFX_WriteStream::WriteByte(uint8_t byte) {
diff --git a/core/fxcrt/string_template.h b/core/fxcrt/string_template.h
index 9c9ec84..373a5b2 100644
--- a/core/fxcrt/string_template.h
+++ b/core/fxcrt/string_template.h
@@ -33,14 +33,16 @@
// Explicit conversion to UnsignedType*. May return nullptr.
// Note: Any subsequent modification of |this| will invalidate the result.
- const UnsignedType* raw_str() const {
+ const UnsignedType* unsigned_str() const {
return m_pData ? reinterpret_cast<const UnsignedType*>(m_pData->m_String)
: nullptr;
}
// Explicit conversion to StringView.
// Note: Any subsequent modification of |this| will invalidate the result.
- StringView AsStringView() const { return StringView(raw_str(), GetLength()); }
+ StringView AsStringView() const {
+ return StringView(unsigned_str(), GetLength());
+ }
// Explicit conversion to span.
// Note: Any subsequent modification of |this| will invalidate the result.
@@ -51,8 +53,8 @@
// Explicit conversion to spans of unsigned types.
// Note: Any subsequent modification of |this| will invalidate the result.
- pdfium::span<const UnsignedType> raw_span() const {
- return pdfium::make_span(raw_str(), GetLength());
+ pdfium::span<const UnsignedType> unsigned_span() const {
+ return pdfium::make_span(unsigned_str(), GetLength());
}
// Note: Any subsequent modification of |this| will invalidate iterators.
diff --git a/core/fxcrt/string_view_template.h b/core/fxcrt/string_view_template.h
index 09a529b..341b34a 100644
--- a/core/fxcrt/string_view_template.h
+++ b/core/fxcrt/string_view_template.h
@@ -159,12 +159,14 @@
return strid << ((4 - size) * 8);
}
- pdfium::span<const UnsignedType> raw_span() const { return m_Span; }
+ pdfium::span<const UnsignedType> unsigned_span() const { return m_Span; }
pdfium::span<const CharType> span() const {
return pdfium::make_span(reinterpret_cast<const CharType*>(m_Span.data()),
m_Span.size());
}
- const UnsignedType* raw_str() const { return m_Span.data(); }
+ const UnsignedType* unterminated_unsigned_str() const {
+ return m_Span.data();
+ }
const CharType* unterminated_c_str() const {
return reinterpret_cast<const CharType*>(m_Span.data());
}
diff --git a/core/fxcrt/widestring_unittest.cpp b/core/fxcrt/widestring_unittest.cpp
index e913f1e..7803b53 100644
--- a/core/fxcrt/widestring_unittest.cpp
+++ b/core/fxcrt/widestring_unittest.cpp
@@ -1243,8 +1243,9 @@
};
for (size_t i = 0; i < std::size(utf16be_decode_cases); ++i) {
- EXPECT_EQ(WideString::FromUTF16BE(utf16be_decode_cases[i].in.raw_span()),
- utf16be_decode_cases[i].out)
+ EXPECT_EQ(
+ WideString::FromUTF16BE(utf16be_decode_cases[i].in.unsigned_span()),
+ utf16be_decode_cases[i].out)
<< " for case number " << i;
}
}
@@ -1262,8 +1263,9 @@
};
for (size_t i = 0; i < std::size(utf16le_decode_cases); ++i) {
- EXPECT_EQ(WideString::FromUTF16LE(utf16le_decode_cases[i].in.raw_span()),
- utf16le_decode_cases[i].out)
+ EXPECT_EQ(
+ WideString::FromUTF16LE(utf16le_decode_cases[i].in.unsigned_span()),
+ utf16le_decode_cases[i].out)
<< " for case number " << i;
}
}
@@ -1443,7 +1445,7 @@
cleared_vec.pop_back();
WideStringView cleared_string(cleared_vec);
EXPECT_EQ(0u, cleared_string.GetLength());
- EXPECT_FALSE(cleared_string.raw_str());
+ EXPECT_FALSE(cleared_string.unterminated_unsigned_str());
}
TEST(WideStringView, ElementAccess) {
diff --git a/core/fxge/cfx_folderfontinfo.cpp b/core/fxge/cfx_folderfontinfo.cpp
index 30c8f83..6985bb3 100644
--- a/core/fxge/cfx_folderfontinfo.cpp
+++ b/core/fxge/cfx_folderfontinfo.cpp
@@ -250,16 +250,16 @@
static constexpr uint32_t kNameTag =
CFX_FontMapper::MakeTag('n', 'a', 'm', 'e');
- ByteString names =
- LoadTableFromTT(pFile, tables.raw_str(), nTables, kNameTag, filesize);
+ ByteString names = LoadTableFromTT(pFile, tables.unsigned_str(), nTables,
+ kNameTag, filesize);
if (names.IsEmpty())
return;
- ByteString facename = GetNameFromTT(names.raw_span(), 1);
+ ByteString facename = GetNameFromTT(names.unsigned_span(), 1);
if (facename.IsEmpty())
return;
- ByteString style = GetNameFromTT(names.raw_span(), 2);
+ ByteString style = GetNameFromTT(names.unsigned_span(), 2);
if (style != "Regular")
facename += " " + style;
@@ -271,9 +271,9 @@
static constexpr uint32_t kOs2Tag =
CFX_FontMapper::MakeTag('O', 'S', '/', '2');
ByteString os2 =
- LoadTableFromTT(pFile, tables.raw_str(), nTables, kOs2Tag, filesize);
+ LoadTableFromTT(pFile, tables.unsigned_str(), nTables, kOs2Tag, filesize);
if (os2.GetLength() >= 86) {
- pdfium::span<const uint8_t> p = os2.raw_span().subspan(78);
+ pdfium::span<const uint8_t> p = os2.unsigned_span().subspan(78);
uint32_t codepages = fxcrt::GetUInt32MSBFirst(p);
if (codepages & (1U << 17)) {
m_pMapper->AddInstalledFont(facename, FX_Charset::kShiftJIS);
@@ -390,7 +390,7 @@
for (size_t i = 0; i < nTables; i++) {
// TODO(tsepez): iterate over span.
pdfium::span<const uint8_t> p =
- pFont->m_FontTables.raw_span().subspan(i * 16);
+ pFont->m_FontTables.unsigned_span().subspan(i * 16);
if (fxcrt::GetUInt32MSBFirst(p) == table) {
offset = fxcrt::GetUInt32MSBFirst(p.subspan(8));
datasize = fxcrt::GetUInt32MSBFirst(p.subspan(12));
diff --git a/core/fxge/fx_font.cpp b/core/fxge/fx_font.cpp
index ddde3db..5c9d1b4 100644
--- a/core/fxge/fx_font.cpp
+++ b/core/fxge/fx_font.cpp
@@ -119,7 +119,7 @@
return ByteString();
}
- return WideString::FromUTF16BE(utf16_be.raw_span()).ToUTF8();
+ return WideString::FromUTF16BE(utf16_be.unsigned_span()).ToUTF8();
}
}
}
diff --git a/fpdfsdk/cpdfsdk_appstream.cpp b/fpdfsdk/cpdfsdk_appstream.cpp
index 6ee6d39..28a919c 100644
--- a/fpdfsdk/cpdfsdk_appstream.cpp
+++ b/fpdfsdk/cpdfsdk_appstream.cpp
@@ -1852,7 +1852,7 @@
RetainPtr<CPDF_Dictionary> stream_dict = stream->GetMutableDict();
stream_dict->SetMatrixFor("Matrix", widget_->GetMatrix());
stream_dict->SetRectFor("BBox", widget_->GetRotatedRect());
- stream->SetDataAndRemoveFilter(sContents.raw_span());
+ stream->SetDataAndRemoveFilter(sContents.unsigned_span());
}
void CPDFSDK_AppStream::Remove(ByteStringView sAPType) {
diff --git a/fpdfsdk/cpdfsdk_interactiveform.cpp b/fpdfsdk/cpdfsdk_interactiveform.cpp
index fbf09a0..f469ce9 100644
--- a/fpdfsdk/cpdfsdk_interactiveform.cpp
+++ b/fpdfsdk/cpdfsdk_interactiveform.cpp
@@ -73,7 +73,7 @@
ByteString FDFToURLEncodedData(ByteString buffer) {
std::unique_ptr<CFDF_Document> pFDF =
- CFDF_Document::ParseMemory(buffer.raw_span());
+ CFDF_Document::ParseMemory(buffer.unsigned_span());
if (!pFDF)
return buffer;
@@ -94,7 +94,7 @@
WideString name = pField->GetUnicodeTextFor("T");
ByteString name_b = name.ToDefANSI();
ByteString csBValue = pField->GetByteStringFor("V");
- WideString csWValue = PDF_DecodeText(csBValue.raw_span());
+ WideString csWValue = PDF_DecodeText(csBValue.unsigned_span());
ByteString csValue_b = csWValue.ToDefANSI();
encoded_data << name_b << "=" << csValue_b;
if (i != pFields->size() - 1)
@@ -452,7 +452,7 @@
return false;
}
- m_pFormFillEnv->SubmitForm(text_buf.raw_span(), csDestination);
+ m_pFormFillEnv->SubmitForm(text_buf.unsigned_span(), csDestination);
return true;
}
@@ -478,7 +478,7 @@
if (fdf_buffer.IsEmpty())
return false;
- m_pFormFillEnv->SubmitForm(fdf_buffer.raw_span(), sDestination);
+ m_pFormFillEnv->SubmitForm(fdf_buffer.unsigned_span(), sDestination);
return true;
}
diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp
index f2cd947..8a940b3 100644
--- a/fpdfsdk/fpdf_annot.cpp
+++ b/fpdfsdk/fpdf_annot.cpp
@@ -1112,7 +1112,7 @@
auto new_stream = pDoc->NewIndirect<CPDF_Stream>(std::move(stream_dict));
ByteString new_stream_data =
PDF_EncodeText(WideStringFromFPDFWideString(value).AsStringView());
- new_stream->SetData(new_stream_data.raw_span());
+ new_stream->SetData(new_stream_data.unsigned_span());
// Storing reference to indirect object in annotation's AP
if (!pApDict) {
diff --git a/fpdfsdk/fpdf_attachment.cpp b/fpdfsdk/fpdf_attachment.cpp
index b19f9f0..8fc5e54 100644
--- a/fpdfsdk/fpdf_attachment.cpp
+++ b/fpdfsdk/fpdf_attachment.cpp
@@ -36,7 +36,7 @@
ByteString CFXByteStringHexDecode(const ByteString& bsHex) {
std::unique_ptr<uint8_t, FxFreeDeleter> result;
uint32_t size = 0;
- HexDecode(bsHex.raw_span(), &result, &size);
+ HexDecode(bsHex.unsigned_span(), &result, &size);
return ByteString(result.get(), size);
}
diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
index a439897..25c3b04 100644
--- a/fpdfsdk/fpdf_edittext.cpp
+++ b/fpdfsdk/fpdf_edittext.cpp
@@ -542,8 +542,8 @@
CreateDescendantFontsArray(doc, font_dict, cid_font_dict->GetObjNum());
- auto to_unicode_stream =
- doc->NewIndirect<CPDF_Stream>(ByteStringView(to_unicode_cmap).raw_span());
+ auto to_unicode_stream = doc->NewIndirect<CPDF_Stream>(
+ ByteStringView(to_unicode_cmap).unsigned_span());
font_dict->SetNewFor<CPDF_Reference>("ToUnicode", doc,
to_unicode_stream->GetObjNum());
return CPDF_DocPageData::FromDocument(doc)->GetFont(font_dict);
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
index 3ba9ca6..b5da321 100644
--- a/fpdfsdk/fpdf_flatten.cpp
+++ b/fpdfsdk/fpdf_flatten.cpp
@@ -182,7 +182,7 @@
const ByteString& contents) {
auto pNewContents =
pDocument->NewIndirect<CPDF_Stream>(pDocument->New<CPDF_Dictionary>());
- pNewContents->SetData(contents.raw_span());
+ pNewContents->SetData(contents.unsigned_span());
return pNewContents->MakeReference(pDocument);
}
@@ -215,7 +215,7 @@
sStream += ByteString(pAcc->GetSpan());
sStream += "\nQ";
}
- pContentsStream->SetDataAndRemoveFilter(sStream.raw_span());
+ pContentsStream->SetDataAndRemoveFilter(sStream.unsigned_span());
pContentsArray = pDocument->NewIndirect<CPDF_Array>();
pContentsArray->AppendNew<CPDF_Reference>(pDocument,
pContentsStream->GetObjNum());
@@ -413,7 +413,7 @@
ByteString str(buf);
sStream += ByteString::Format("q %s cm /%s Do Q\n", str.c_str(),
sFormName.c_str());
- pNewXObject->SetDataAndRemoveFilter(sStream.raw_span());
+ pNewXObject->SetDataAndRemoveFilter(sStream.unsigned_span());
}
pPageDict->RemoveFor("Annots");
return FLATTEN_SUCCESS;
diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp
index 6710b09..a8a42a0 100644
--- a/fpdfsdk/fpdf_ppo.cpp
+++ b/fpdfsdk/fpdf_ppo.cpp
@@ -640,7 +640,7 @@
pAcc->LoadAllDataFiltered();
bsSrcContentStream = ByteString(pAcc->GetSpan());
}
- pNewXObject->SetDataAndRemoveFilter(bsSrcContentStream.raw_span());
+ pNewXObject->SetDataAndRemoveFilter(bsSrcContentStream.unsigned_span());
}
return pNewXObject;
}
@@ -681,7 +681,7 @@
auto pStream =
dest()->NewIndirect<CPDF_Stream>(dest()->New<CPDF_Dictionary>());
- pStream->SetData(bsContent.raw_span());
+ pStream->SetData(bsContent.unsigned_span());
pDestPageDict->SetNewFor<CPDF_Reference>(pdfium::page_object::kContents,
dest(), pStream->GetObjNum());
}
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index c8cbcaf..de1ffe5 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -233,7 +233,7 @@
auto pEndStream =
pDoc->NewIndirect<CPDF_Stream>(pDoc->New<CPDF_Dictionary>());
- pEndStream->SetData(ByteStringView(" Q").raw_span());
+ pEndStream->SetData(ByteStringView(" Q").unsigned_span());
RetainPtr<CPDF_Array> pContentArray = ToArray(pContentObj);
if (pContentArray) {
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index 6b0a1c1..2e88578 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -1252,7 +1252,7 @@
break;
i++;
}
- wsName = PDF_DecodeText(bsName.raw_span());
+ wsName = PDF_DecodeText(bsName.unsigned_span());
} else {
pDestObj = name_tree->LookupValueAndName(index, &wsName);
}
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index 38232c7..199e0a3 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -503,7 +503,7 @@
continue;
}
if (i == pArray->size() - 1) {
- WideString wPath = WideString::FromUTF16LE(bs.raw_span());
+ WideString wPath = WideString::FromUTF16LE(bs.unsigned_span());
ByteString bPath = wPath.ToUTF8();
static const char kFormat[] =
"\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>";
diff --git a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
index d903b8f..f052484 100644
--- a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
+++ b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
@@ -116,7 +116,7 @@
p += t;
} else {
std::optional<size_t> b =
- DetermineConsecutiveBinaryCount(result, bytes.raw_span(), p);
+ DetermineConsecutiveBinaryCount(result, bytes.unsigned_span(), p);
if (!b.has_value())
return std::nullopt;
@@ -124,9 +124,9 @@
if (b_value == 0)
b_value = 1;
if (b_value == 1 && encodingMode == EncodingMode::kText) {
- EncodeBinary(bytes.raw_span(), p, 1, EncodingMode::kText, &sb);
+ EncodeBinary(bytes.unsigned_span(), p, 1, EncodingMode::kText, &sb);
} else {
- EncodeBinary(bytes.raw_span(), p, b_value, encodingMode, &sb);
+ EncodeBinary(bytes.unsigned_span(), p, b_value, encodingMode, &sb);
encodingMode = EncodingMode::kByte;
textSubMode = SubMode::kAlpha;
}
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 41046c6..e37cf01 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -394,8 +394,8 @@
cMsg = pRuntime->ToWideString(newParams[5]);
pRuntime->BeginBlock();
- m_pFormFillEnv->JS_docmailForm(sTextBuf.raw_span(), bUI, cTo, cSubject, cCc,
- cBcc, cMsg);
+ m_pFormFillEnv->JS_docmailForm(sTextBuf.unsigned_span(), bUI, cTo, cSubject,
+ cCc, cBcc, cMsg);
pRuntime->EndBlock();
return CJS_Result::Success();
}
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index af7eeba..51a269e 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -407,7 +407,8 @@
if (bsStr.IsEmpty())
return result;
- DataVector<uint8_t> buffer = XFA_RemoveBase64Whitespace(bsStr.raw_span());
+ DataVector<uint8_t> buffer =
+ XFA_RemoveBase64Whitespace(bsStr.unsigned_span());
result.reserve(3 * (buffer.size() / 4));
uint32_t dwLimb = 0;