Skip to content

Commit 65bc768

Browse files
tkent-googleChromium LUCI CQ
authored andcommitted
Add a WTF::String constructor with a base::span<const char>
It simplifies string construction. This CL has no behavior changes. Bug: 351564777 Change-Id: Ifdd6a3a9270295a6175653348032167473ac4a11 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5991511 Reviewed-by: Fredrik Söderquist <fs@opera.com> Reviewed-by: Kent Tamura <tkent@chromium.org> Commit-Queue: Kent Tamura <tkent@chromium.org> Cr-Commit-Position: refs/heads/main@{#1378632}
1 parent 9e5bd20 commit 65bc768

File tree

9 files changed

+16
-16
lines changed

9 files changed

+16
-16
lines changed

third_party/blink/renderer/core/clipboard/clipboard_utilities_test.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ TEST(ClipboardUtilitiesTest, URLToImageMarkupEmbeddedNull) {
4141
const char kTitleWithNull[] = "\0";
4242
const char kExpectedOutputWithNull[] =
4343
"<img src=\"http://test.example/%00.png\" alt=\"\0\"/>";
44-
EXPECT_EQ(
45-
String(base::byte_span_from_cstring(kExpectedOutputWithNull)),
46-
URLToImageMarkup(
47-
KURL(NullURL(), String(base::byte_span_from_cstring(kURLWithNull))),
48-
String(base::byte_span_from_cstring(kTitleWithNull))));
44+
EXPECT_EQ(String(base::span_from_cstring(kExpectedOutputWithNull)),
45+
URLToImageMarkup(
46+
KURL(NullURL(), String(base::span_from_cstring(kURLWithNull))),
47+
String(base::span_from_cstring(kTitleWithNull))));
4948
}
5049

5150
TEST(ClipboardUtilitiesTest, PNGToImageMarkupEmpty) {

third_party/blink/renderer/core/fetch/fetch_data_loader_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ TEST_F(FetchDataLoaderTest, LoadAsStringWithNullBytes) {
782782
EXPECT_CALL(*consumer, BeginRead(_)).WillOnce(Return(Result::kDone));
783783
EXPECT_CALL(*fetch_data_loader_client,
784784
DidFetchDataLoadedString(
785-
String(base::byte_span_with_nul_from_cstring(kPattern))));
785+
String(base::span_with_nul_from_cstring(kPattern))));
786786
EXPECT_CALL(checkpoint, Call(3));
787787
EXPECT_CALL(*consumer, Cancel());
788788
EXPECT_CALL(checkpoint, Call(4));

third_party/blink/renderer/core/html/parser/html_document_parser_fastpath_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ TEST(HTMLDocumentParserFastpathTest, NullMappedToReplacementChar) {
315315
base::HistogramTester histogram_tester;
316316
// Constructor that takes a base::span is needed because of \0 in string.
317317
div->setInnerHTML(
318-
String(base::byte_span_from_cstring("<div id='x' name='x\0y'></div>")));
318+
String(base::span_from_cstring("<div id='x' name='x\0y'></div>")));
319319
Element* new_div = div->getElementById(AtomicString("x"));
320320
ASSERT_TRUE(new_div);
321321
// Null chars are generally mapped to \uFFFD (at least this test should

third_party/blink/renderer/core/loader/resource/multipart_image_resource_parser_test.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace multipart_image_resource_parser_test {
1919
String ToString(const Vector<char>& data) {
2020
if (data.empty())
2121
return String("");
22-
return String(base::as_byte_span(data));
22+
return String(data);
2323
}
2424

2525
class MockClient final : public GarbageCollected<MockClient>,
@@ -240,9 +240,9 @@ void VariousChunkSizesTest(base::span<const TestChunk> chunks,
240240
parser->AppendData(data.subspan(chunk.start_position,
241241
chunk.end_position - chunk.start_position));
242242
EXPECT_EQ(chunk.expected_responses, client->responses_.size());
243-
EXPECT_EQ(
244-
String(base::as_byte_span(chunk.expected_data)),
245-
client->data_.size() > 0 ? ToString(client->data_.back()) : String(""));
243+
EXPECT_EQ(String(chunk.expected_data), client->data_.size() > 0
244+
? ToString(client->data_.back())
245+
: String(""));
246246
}
247247
// Check final state
248248
parser->Finish();

third_party/blink/renderer/platform/exported/web_string.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ std::string WebString::Latin1() const {
109109
}
110110

111111
WebString WebString::FromLatin1(std::string_view s) {
112-
return String(base::as_bytes(base::span(s)));
112+
return String(s);
113113
}
114114

115115
std::string WebString::Ascii() const {

third_party/blink/renderer/platform/peerconnection/rtc_ice_candidate_platform.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void RTCIceCandidatePlatform::PopulateFields(bool use_username_from_candidate) {
8585
auto type = c.type_name();
8686
DCHECK(type == "host" || type == "srflx" || type == "prflx" ||
8787
type == "relay");
88-
type_ = String(base::as_byte_span(type));
88+
type_ = String(type);
8989
if (!c.tcptype().empty()) {
9090
tcp_type_ = String::FromUTF8(c.tcptype());
9191
}

third_party/blink/renderer/platform/text/unicode_utilities_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ TEST(UnicodeUtilitiesTest, FoldQuoteMarkOrSoftHyphenTest) {
150150

151151
FoldQuoteMarksAndSoftHyphens(string_to_fold);
152152

153-
const String folded_string(base::byte_span_from_cstring("\"\"\"\'\'\'\0"));
153+
const String folded_string(base::span_from_cstring("\"\"\"\'\'\'\0"));
154154
ASSERT_EQ(std::size(kCharactersToFold), folded_string.length());
155155
EXPECT_EQ(string_to_fold, folded_string);
156156

third_party/blink/renderer/platform/wtf/text/wtf_string.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ String String::Format(const char* format, ...) {
242242
va_end(args);
243243
}
244244

245-
return String(base::as_bytes(
246-
base::span(buffer).first(base::checked_cast<size_t>(length))));
245+
return String(base::span(buffer).first(base::checked_cast<size_t>(length)));
247246
}
248247

249248
String String::EncodeForDebugging() const {

third_party/blink/renderer/platform/wtf/text/wtf_string.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class WTF_EXPORT String {
8484

8585
// Construct a string with latin1 data.
8686
explicit String(base::span<const LChar> latin1_data);
87+
explicit String(base::span<const char> latin1_data)
88+
: String(base::as_bytes(latin1_data)) {}
8789
String(const char* characters, unsigned length);
8890
explicit String(const std::string& s) : String(base::as_byte_span(s)) {}
8991

0 commit comments

Comments
 (0)