Skip to content
Permalink
Browse files
Make StringView(const char*) private
https://bugs.webkit.org/show_bug.cgi?id=240942

Reviewed by Darin Adler.

Make StringView(const char*) private and update existing call sites
to use either StringView(ASCIILiteral) or StringView::fromLatin1(const char*).

* Source/WTF/wtf/text/StringView.h:
* Source/WebCore/platform/sql/SQLiteStatement.cpp:
(WebCore::SQLiteStatement::isColumnDeclaredAsBlob):
* Source/WebGPU/WGSL/Parser.cpp:
(WGSL::Parser<Lexer>::parseTypeDecl):
* Tools/TestWebKitAPI/Tests/WTF/StringParsingBuffer.cpp:
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WTF/StringView.cpp:
(TestWebKitAPI::stringViewFromLiteral):
* Tools/TestWebKitAPI/Tests/WTF/TextBreakIterator.cpp:
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/Tests/WebCore/ISOBox.cpp:
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/251034@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294916 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed May 27, 2022
1 parent f0a9930 commit 53034845497a9098f088ea21b90d341547667a2f
Showing 10 changed files with 60 additions and 60 deletions.
@@ -166,7 +166,7 @@ const char* Thread::normalizeThreadName(const char* threadName)
// This name can be com.apple.WebKit.ProcessLauncher or com.apple.CoreIPC.ReceiveQueue.
// We are using those names for the thread name, but both are longer than the limit of
// the platform thread name length, 32 for Windows and 16 for Linux.
StringView result(threadName);
auto result = StringView::fromLatin1(threadName);
size_t size = result.reverseFind('.');
if (size != notFound)
result = result.substring(size + 1);
@@ -69,7 +69,7 @@ static size_t computeMemoryFootprint()
return;
}
if (scannedCount == 7) {
StringView pathString(path);
auto pathString = StringView::fromLatin1(path);
isAnonymous = pathString == "[heap]"_s || pathString.startsWith("[stack"_s);
return;
}
@@ -69,9 +69,6 @@ class StringView final {
StringView(const char*, unsigned length);
StringView(ASCIILiteral);

// FIXME: Make private once all call sites have been ported to fromLatin1.
explicit StringView(const char*);

ALWAYS_INLINE static StringView fromLatin1(const char* characters) { return StringView { characters }; }

static StringView empty();
@@ -191,6 +188,9 @@ class StringView final {
struct UnderlyingString;

private:
// Clients should use StringView(ASCIILiteral) or StringView::fromLatin1() instead.
explicit StringView(const char*);

friend bool equal(StringView, StringView);
friend WTF_EXPORT_PRIVATE bool equalRespectingNullity(StringView, StringView);

@@ -271,7 +271,7 @@ void PlatformDisplay::initializeEGLDisplay()

{
const char* extensionsString = eglQueryString(m_eglDisplay, EGL_EXTENSIONS);
auto displayExtensions = StringView { extensionsString }.split(' ');
auto displayExtensions = StringView::fromLatin1(extensionsString).split(' ');
auto findExtension =
[&](auto extensionName) {
return std::any_of(displayExtensions.begin(), displayExtensions.end(),
@@ -183,7 +183,7 @@ int SQLiteStatement::columnCount()
bool SQLiteStatement::isColumnDeclaredAsBlob(int col)
{
ASSERT(col >= 0);
return equalLettersIgnoringASCIICase(StringView(sqlite3_column_decltype(m_statement, col)), "blob"_s);
return equalLettersIgnoringASCIICase(StringView::fromLatin1(sqlite3_column_decltype(m_statement, col)), "blob"_s);
}

String SQLiteStatement::columnName(int col)
@@ -341,19 +341,19 @@ Expected<UniqueRef<AST::TypeDecl>, Error> Parser<Lexer>::parseTypeDecl()

if (current().m_type == TokenType::KeywordI32) {
consume();
RETURN_NODE_REF(NamedType, StringView { "i32" });
RETURN_NODE_REF(NamedType, StringView { "i32"_s });
}
if (current().m_type == TokenType::KeywordF32) {
consume();
RETURN_NODE_REF(NamedType, StringView { "f32" });
RETURN_NODE_REF(NamedType, StringView { "f32"_s });
}
if (current().m_type == TokenType::KeywordU32) {
consume();
RETURN_NODE_REF(NamedType, StringView { "u32" });
RETURN_NODE_REF(NamedType, StringView { "u32"_s });
}
if (current().m_type == TokenType::KeywordBool) {
consume();
RETURN_NODE_REF(NamedType, StringView { "bool" });
RETURN_NODE_REF(NamedType, StringView { "bool"_s });
}
if (current().m_type == TokenType::Identifier) {
CONSUME_TYPE_NAMED(name, Identifier);
@@ -46,7 +46,7 @@ TEST(WTF, StringParsingBufferEmpty)

TEST(WTF, StringParsingBufferInitial)
{
StringView string { "abc" };
StringView string { "abc"_s };
StringParsingBuffer<LChar> parsingBuffer { string.characters8(), string.length() };

EXPECT_FALSE(parsingBuffer.atEnd());
@@ -59,7 +59,7 @@ TEST(WTF, StringParsingBufferInitial)

TEST(WTF, StringParsingBufferAdvance)
{
StringView string { "abc" };
StringView string { "abc"_s };
StringParsingBuffer<LChar> parsingBuffer { string.characters8(), string.length() };

parsingBuffer.advance();
@@ -71,7 +71,7 @@ TEST(WTF, StringParsingBufferAdvance)

TEST(WTF, StringParsingBufferAdvanceBy)
{
StringView string { "abc" };
StringView string { "abc"_s };
StringParsingBuffer<LChar> parsingBuffer { string.characters8(), string.length() };

parsingBuffer.advanceBy(2);
@@ -83,7 +83,7 @@ TEST(WTF, StringParsingBufferAdvanceBy)

TEST(WTF, StringParsingBufferPreIncrement)
{
StringView string { "abc" };
StringView string { "abc"_s };
StringParsingBuffer<LChar> parsingBuffer { string.characters8(), string.length() };

auto preIncrementedParsingBuffer = ++parsingBuffer;
@@ -99,7 +99,7 @@ TEST(WTF, StringParsingBufferPreIncrement)

TEST(WTF, StringParsingBufferPostIncrement)
{
StringView string { "abc" };
StringView string { "abc"_s };
StringParsingBuffer<LChar> parsingBuffer { string.characters8(), string.length() };

auto postIncrementedParsingBuffer = parsingBuffer++;
@@ -115,7 +115,7 @@ TEST(WTF, StringParsingBufferPostIncrement)

TEST(WTF, StringParsingBufferPlusEquals)
{
StringView string { "abc" };
StringView string { "abc"_s };
StringParsingBuffer<LChar> parsingBuffer { string.characters8(), string.length() };

parsingBuffer += 2;
@@ -127,7 +127,7 @@ TEST(WTF, StringParsingBufferPlusEquals)

TEST(WTF, StringParsingBufferEnd)
{
StringView string { "abc" };
StringView string { "abc"_s };
StringParsingBuffer<LChar> parsingBuffer { string.characters8(), string.length() };

++parsingBuffer;
@@ -147,7 +147,7 @@ TEST(WTF, StringParsingBufferEnd)

TEST(WTF, StringParsingBufferSubscript)
{
StringView string { "abc" };
StringView string { "abc"_s };
StringParsingBuffer<LChar> parsingBuffer { string.characters8(), string.length() };

++parsingBuffer;
@@ -157,7 +157,7 @@ TEST(WTF, StringParsingBufferSubscript)

TEST(WTF, StringParsingBufferStringView)
{
StringView string { "abc" };
StringView string { "abc"_s };
StringParsingBuffer<LChar> parsingBuffer { string.characters8(), string.length() };

++parsingBuffer;
@@ -169,7 +169,7 @@ TEST(WTF, StringParsingBufferStringView)

TEST(WTF, StringParsingBufferReadCharactersForParsing)
{
auto latin1 = StringView { "abc" };
auto latin1 = StringView { "abc"_s };
auto result1 = WTF::readCharactersForParsing(latin1, [](auto parsingBuffer) {
EXPECT_FALSE(parsingBuffer.atEnd());
EXPECT_TRUE(parsingBuffer.hasCharactersRemaining());
@@ -32,7 +32,7 @@ namespace TestWebKitAPI {

StringView stringViewFromLiteral(const char* characters)
{
return StringView(characters);
return StringView::fromLatin1(characters);
}

StringView stringViewFromUTF8(String& ref, const char* characters)
@@ -37,22 +37,22 @@ static String makeUTF16(std::vector<UChar> input)
TEST(WTF, TextBreakIteratorNumGraphemeClusters)
{
EXPECT_EQ(0U, numGraphemeClusters(StringView { }));
EXPECT_EQ(0U, numGraphemeClusters(StringView { "" }));
EXPECT_EQ(0U, numGraphemeClusters(StringView { ""_s }));
EXPECT_EQ(0U, numGraphemeClusters(makeUTF16({ })));

EXPECT_EQ(1U, numGraphemeClusters(StringView { "a" }));
EXPECT_EQ(1U, numGraphemeClusters(StringView { "a"_s }));
EXPECT_EQ(1U, numGraphemeClusters(makeUTF16({ 'a' })));
EXPECT_EQ(1U, numGraphemeClusters(StringView { "\r\n" }));
EXPECT_EQ(1U, numGraphemeClusters(StringView { "\n" }));
EXPECT_EQ(1U, numGraphemeClusters(StringView { "\r" }));
EXPECT_EQ(1U, numGraphemeClusters(StringView { "\r\n"_s }));
EXPECT_EQ(1U, numGraphemeClusters(StringView { "\n"_s }));
EXPECT_EQ(1U, numGraphemeClusters(StringView { "\r"_s }));
EXPECT_EQ(1U, numGraphemeClusters(makeUTF16({ '\r', '\n' })));
EXPECT_EQ(1U, numGraphemeClusters(makeUTF16({ '\n' })));
EXPECT_EQ(1U, numGraphemeClusters(makeUTF16({ '\r' })));

EXPECT_EQ(2U, numGraphemeClusters(StringView { "\n\r" }));
EXPECT_EQ(2U, numGraphemeClusters(StringView { "\n\r"_s }));
EXPECT_EQ(2U, numGraphemeClusters(makeUTF16({ '\n', '\r' })));

EXPECT_EQ(2U, numGraphemeClusters(StringView { "\r\n\r" }));
EXPECT_EQ(2U, numGraphemeClusters(StringView { "\r\n\r"_s }));
EXPECT_EQ(2U, numGraphemeClusters(makeUTF16({ '\r', '\n', '\r' })));

EXPECT_EQ(1U, numGraphemeClusters(makeUTF16({ 'g', 0x308 })));
@@ -61,7 +61,7 @@ TEST(WTF, TextBreakIteratorNumGraphemeClusters)

EXPECT_EQ(2U, numGraphemeClusters(makeUTF16({ 0x308, 'g' })));

EXPECT_EQ(3U, numGraphemeClusters(StringView { "\r\nbc" }));
EXPECT_EQ(3U, numGraphemeClusters(StringView { "\r\nbc"_s }));
EXPECT_EQ(3U, numGraphemeClusters(makeUTF16({ 'g', 0x308, 'b', 'c' })));
}

@@ -70,52 +70,52 @@ TEST(WTF, TextBreakIteratorNumCodeUnitsInGraphemeClusters)
EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { }, 0));
EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { }, 1));

EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { "" }, 0));
EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { "" }, 1));
EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { ""_s }, 0));
EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { ""_s }, 1));

EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(makeUTF16({ }), 0));
EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(makeUTF16({ }), 1));

EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(StringView { "a" }, 1));
EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(StringView { "a"_s }, 1));
EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(makeUTF16({ 'a' }), 1));
EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(StringView { "\n" }, 1));
EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(StringView { "\r" }, 1));
EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(StringView { "\n"_s }, 1));
EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(StringView { "\r"_s }, 1));
EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(makeUTF16({ '\n' }), 1));
EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(makeUTF16({ '\r' }), 1));

EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { "abc" }, 0));
EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(StringView { "abc" }, 1));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(StringView { "abc" }, 2));
EXPECT_EQ(3U, numCodeUnitsInGraphemeClusters(StringView { "abc" }, 3));
EXPECT_EQ(3U, numCodeUnitsInGraphemeClusters(StringView { "abc" }, 4));
EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { "abc"_s }, 0));
EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(StringView { "abc"_s }, 1));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(StringView { "abc"_s }, 2));
EXPECT_EQ(3U, numCodeUnitsInGraphemeClusters(StringView { "abc"_s }, 3));
EXPECT_EQ(3U, numCodeUnitsInGraphemeClusters(StringView { "abc"_s }, 4));

EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(makeUTF16({ 'a', 'b', 'c' }), 0));
EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(makeUTF16({ 'a', 'b', 'c' }), 1));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(makeUTF16({ 'a', 'b', 'c' }), 2));
EXPECT_EQ(3U, numCodeUnitsInGraphemeClusters(makeUTF16({ 'a', 'b', 'c' }), 3));
EXPECT_EQ(3U, numCodeUnitsInGraphemeClusters(makeUTF16({ 'a', 'b', 'c' }), 4));

EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { "\r\n" }, 0));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(StringView { "\r\n" }, 1));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(StringView { "\r\n" }, 2));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(StringView { "\r\n" }, 3));
EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { "\r\n"_s }, 0));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(StringView { "\r\n"_s }, 1));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(StringView { "\r\n"_s }, 2));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(StringView { "\r\n"_s }, 3));

EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(makeUTF16({ '\r', '\n' }), 0));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(makeUTF16({ '\r', '\n' }), 1));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(makeUTF16({ '\r', '\n' }), 2));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(makeUTF16({ '\r', '\n' }), 3));

EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { "\n\r" }, 0));
EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(StringView { "\n\r" }, 1));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(StringView { "\n\r" }, 2));
EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { "\n\r"_s }, 0));
EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(StringView { "\n\r"_s }, 1));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(StringView { "\n\r"_s }, 2));

EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(makeUTF16({ '\n', '\r' }), 1));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(makeUTF16({ '\n', '\r' }), 2));

EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { "\r\n\r" }, 0));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(StringView { "\r\n\r" }, 1));
EXPECT_EQ(3U, numCodeUnitsInGraphemeClusters(StringView { "\r\n\r" }, 2));
EXPECT_EQ(3U, numCodeUnitsInGraphemeClusters(StringView { "\r\n\r" }, 3));
EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { "\r\n\r"_s }, 0));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(StringView { "\r\n\r"_s }, 1));
EXPECT_EQ(3U, numCodeUnitsInGraphemeClusters(StringView { "\r\n\r"_s }, 2));
EXPECT_EQ(3U, numCodeUnitsInGraphemeClusters(StringView { "\r\n\r"_s }, 3));

EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(makeUTF16({ '\r', '\n', '\r' }), 0));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(makeUTF16({ '\r', '\n', '\r' }), 1));
@@ -128,12 +128,12 @@ TEST(WTF, TextBreakIteratorNumCodeUnitsInGraphemeClusters)

EXPECT_EQ(1U, numCodeUnitsInGraphemeClusters(makeUTF16({ 0x308, 'g' }), 1));

EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { "\r\nbc" }, 0));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(StringView { "\r\nbc" }, 1));
EXPECT_EQ(3U, numCodeUnitsInGraphemeClusters(StringView { "\r\nbc" }, 2));
EXPECT_EQ(4U, numCodeUnitsInGraphemeClusters(StringView { "\r\nbc" }, 3));
EXPECT_EQ(4U, numCodeUnitsInGraphemeClusters(StringView { "\r\nbc" }, 4));
EXPECT_EQ(4U, numCodeUnitsInGraphemeClusters(StringView { "\r\nbc" }, 5));
EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(StringView { "\r\nbc"_s }, 0));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(StringView { "\r\nbc"_s }, 1));
EXPECT_EQ(3U, numCodeUnitsInGraphemeClusters(StringView { "\r\nbc"_s }, 2));
EXPECT_EQ(4U, numCodeUnitsInGraphemeClusters(StringView { "\r\nbc"_s }, 3));
EXPECT_EQ(4U, numCodeUnitsInGraphemeClusters(StringView { "\r\nbc"_s }, 4));
EXPECT_EQ(4U, numCodeUnitsInGraphemeClusters(StringView { "\r\nbc"_s }, 5));

EXPECT_EQ(0U, numCodeUnitsInGraphemeClusters(makeUTF16({ 'g', 0x308, 'b', 'c' }), 0));
EXPECT_EQ(2U, numCodeUnitsInGraphemeClusters(makeUTF16({ 'g', 0x308, 'b', 'c' }), 1));
@@ -38,11 +38,11 @@ using namespace WebCore;

namespace TestWebKitAPI {

static const char* base64EncodedSinfWithKeyID3 = "AAAAYXNpbmYAAAAMZnJtYW1wNGEAAAAUc2NobQAAAABjYmNzAAEAAAAAADlzY2hpAAAAMXRlbmMBAAAAAAABAAAAAAAAAAAAAAAAAAAAAAMQ1fvWuC7ZPk75iuQJMe4ztw==";
static constexpr auto base64EncodedSinfWithKeyID3 = "AAAAYXNpbmYAAAAMZnJtYW1wNGEAAAAUc2NobQAAAABjYmNzAAEAAAAAADlzY2hpAAAAMXRlbmMBAAAAAAABAAAAAAAAAAAAAAAAAAAAAAMQ1fvWuC7ZPk75iuQJMe4ztw=="_s;

TEST(ISOBox, ISOProtectionSchemeInfoBox)
{
auto sinfArray = base64Decode(StringView(base64EncodedSinfWithKeyID3));
auto sinfArray = base64Decode(StringView { base64EncodedSinfWithKeyID3 });
ASSERT_TRUE(sinfArray);
ASSERT_EQ(97UL, sinfArray->size());

@@ -74,7 +74,7 @@ TEST(ISOBox, ISOProtectionSchemeInfoBox)
ASSERT_EQ(defaultIV, trackEncryptionBox->defaultConstantIV());
}

static const char* base64EncodedPsshWithAssetId = "AAAAsHBzc2gAAAAAlM6G+wf/T0OtuJPS+paMogAAAJAAAACQZnBzZAAAABBmcHNpAAAAAGNlbmMAAAA8ZnBzawAAABxma3JpAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAYZmthaQAAAAAAAAAAAAAAAAAAAPEAAAA8ZnBzawAAABxma3JpAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAYZmthaQAAAAAAAAAAAAAAAAAAAPI=";
static constexpr auto base64EncodedPsshWithAssetId = "AAAAsHBzc2gAAAAAlM6G+wf/T0OtuJPS+paMogAAAJAAAACQZnBzZAAAABBmcHNpAAAAAGNlbmMAAAA8ZnBzawAAABxma3JpAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAYZmthaQAAAAAAAAAAAAAAAAAAAPEAAAA8ZnBzawAAABxma3JpAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAYZmthaQAAAAAAAAAAAAAAAAAAAPI="_s;

TEST(ISOBox, ISOFairPlayStreamingPsshBox)
{

0 comments on commit 5303484

Please sign in to comment.