source: webkit/trunk/Source/WebCore/css/parser/CSSTokenizer.h

Last change on this file was 293326, checked in by Chris Dumez, 3 years ago

Replace String::replace() functions with makeStringByReplacingAll() free functions
https://bugs.webkit.org/show_bug.cgi?id=239685

Reviewed by Darin Adler.

Replace String::replace() functions with makeStringByReplacingAll() free functions.

"All" is added to the name since every instance is replaced, not just the first one.
Making it a free function that returns a new String is a step towards making String
immutable.

In the future, we may want to add a makeStringByReplacingAll() that takes in a
StringView instead of a const String. Some call sites would benefit from that.

  • Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp:

(TestWebKitAPI::TEST):

  • Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp:

(TestWebKitAPI::TEST):

  • Tools/TestWebKitAPI/Tests/WebKit/OverrideAppleLanguagesPreference.mm:

(AppleLanguagesTest::AppleLanguagesTest):

  • Tools/WebKitTestRunner/InjectedBundle/atspi/AccessibilityUIElementAtspi.cpp:

(WTR::AccessibilityUIElement::stringValue):
(WTR::AccessibilityUIElement::attributedStringForRange):

  • Source/JavaScriptCore/inspector/agents/InspectorAuditAgent.cpp:

(Inspector::InspectorAuditAgent::run):

  • Source/JavaScriptCore/jit/ExecutableAllocator.cpp:

(JSC::dumpJITMemory):

  • Source/JavaScriptCore/runtime/TypeProfiler.cpp:

(JSC::TypeProfiler::logTypesForTypeLocation):

  • Source/JavaScriptCore/runtime/TypeSet.cpp:

(JSC::StructureShape::propertyHash):

  • Source/JavaScriptCore/yarr/RegularExpression.cpp:

(JSC::Yarr::replace):

  • Source/WebCore/PAL/pal/text/TextCodecICU.cpp:

(PAL::TextCodecICU::encode const):

  • Source/WebKit/NetworkProcess/DatabaseUtilities.cpp:

(WebKit::DatabaseUtilities::stripIndexQueryToMatchStoredValue):

  • Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp:

(WebKit::escapeForJSON):

  • Source/WebKit/UIProcess/API/glib/WebKitWebContext.cpp:

(webkit_web_context_set_preferred_languages):

  • Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm:

(WebKit::WebViewImpl::insertText):

  • Source/WebKit/WebProcess/WebCoreSupport/WebContextMenuClient.cpp:

(WebKit::WebContextMenuClient::searchWithGoogle):

  • Source/WebKit/WebProcess/WebCoreSupport/WebResourceLoadObserver.cpp:

(WebKit::WebResourceLoadObserver::logUserInteractionWithReducedTimeResolution):

  • Source/WebKitLegacy/mac/WebView/WebHTMLRepresentation.mm:

(matchLabelsAgainstString):

  • Source/WebKitLegacy/mac/WebView/WebHTMLView.mm:

(-[WebHTMLView insertText:]):

  • Source/WebKitLegacy/win/DOMHTMLClasses.cpp:

(DOMHTMLInputElement::replaceCharactersInRange):

  • Source/WebKitLegacy/win/WebCoreSupport/WebContextMenuClient.cpp:

(WebContextMenuClient::searchWithGoogle):

  • Source/WebKitLegacy/win/WebLocalizableStrings.cpp:

(LocalizedString::operator LPCTSTR const):

  • Source/WTF/wtf/Language.cpp:

(WTF::canonicalLanguageIdentifier):

  • Source/WTF/wtf/URLHelpers.cpp:

(WTF::URLHelpers::mapHostNames):

  • Source/WTF/wtf/URLParser.cpp:

(WTF::URLParser::parseURLEncodedForm):

  • Source/WTF/wtf/text/StringView.h:

(WTF::makeStringByReplacingAll):
(WTF::makeStringByReplacing):
(WTF::String::replace): Deleted.

  • Source/WTF/wtf/text/WTFString.h:

(WTF::makeStringByReplacingAll):
(WTF::String::replace): Deleted.

  • Source/WTF/wtf/unix/LanguageUnix.cpp:

(WTF::platformLanguage):

  • Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:

(WebCore::IDBServer::SQLiteIDBBackingStore::encodeDatabaseName):
(WebCore::IDBServer::SQLiteIDBBackingStore::decodeDatabaseName):

  • Source/WebCore/Modules/mediastream/gstreamer/GStreamerMediaEndpoint.cpp:

(WebCore::GStreamerMediaEndpoint::setConfiguration):

  • Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp:

(WebCore::queryKeysAndValues):

  • Source/WebCore/accessibility/AccessibilityRenderObject.cpp:

(WebCore::AccessibilityRenderObject::determineDropEffects const):

  • Source/WebCore/accessibility/atspi/AccessibilityAtspi.cpp:

(WebCore::AccessibilityAtspi::registerRoot):
(WebCore::AccessibilityAtspi::registerObject):
(WebCore::AccessibilityAtspi::registerHyperlink):

  • Source/WebCore/contentextensions/ContentExtensionActions.cpp:

(WebCore::ContentExtensions::RedirectAction::RegexSubstitutionAction::applyToURL const):

  • Source/WebCore/contentextensions/ContentExtensionParser.cpp:

(WebCore::ContentExtensions::getDomainList):

  • Source/WebCore/css/parser/CSSTokenizer.cpp:

(WebCore::CSSTokenizer::preprocessString):

  • Source/WebCore/display/css/DisplayTextBox.cpp:

(WebCore::Display::TextBox::debugDescription const):

  • Source/WebCore/dom/Document.cpp:

(WebCore::Document::displayStringModifiedByEncoding const):

  • Source/WebCore/dom/Node.cpp:

(WebCore::Node::showNode const):

  • Source/WebCore/dom/Text.cpp:

(WebCore::appendTextRepresentation):

  • Source/WebCore/dom/ViewportArguments.cpp:

(WebCore::viewportErrorMessage):

  • Source/WebCore/editing/EditingStyle.cpp:

(WebCore::StyleChange::extractTextStyles):

  • Source/WebCore/editing/Editor.cpp:

(WebCore::Editor::selectedText const):

  • Source/WebCore/editing/FrameSelection.cpp:

(WebCore::FrameSelection::debugRenderer const):

  • Source/WebCore/editing/MarkupAccumulator.cpp:

(WebCore::MarkupAccumulator::appendQuotedURLAttributeValue):

  • Source/WebCore/editing/TextIterator.cpp:

(WebCore::foldQuoteMarks):

  • Source/WebCore/editing/VisibleUnits.cpp:

(WebCore::charactersAroundPosition):

  • Source/WebCore/editing/cocoa/EditorCocoa.mm:

(WebCore::Editor::stringSelectionForPasteboard):
(WebCore::Editor::stringSelectionForPasteboardWithImageAltText):

  • Source/WebCore/editing/cocoa/HTMLConverter.mm:

(WebCore::editingAttributedString):

  • Source/WebCore/editing/markup.cpp:

(WebCore::StyledMarkupAccumulator::takeResults):
(WebCore::createFragmentFromText):

  • Source/WebCore/html/HTMLElement.cpp:

(WebCore::HTMLElement::setInnerText):

  • Source/WebCore/html/HTMLTextAreaElement.cpp:

(WebCore::HTMLTextAreaElement::setValueCommon):

  • Source/WebCore/html/HTMLTextFormControlElement.cpp:

(WebCore::HTMLTextFormControlElement::setRangeText):

  • Source/WebCore/html/LinkRelAttribute.cpp:

(WebCore::LinkRelAttribute::LinkRelAttribute):

  • Source/WebCore/html/TextFieldInputType.cpp:

(WebCore::TextFieldInputType::handleBeforeTextInsertedEvent):

  • Source/WebCore/html/URLDecomposition.cpp:

(WebCore::URLDecomposition::setSearch):

  • Source/WebCore/inspector/InspectorStyleSheet.cpp:

(WebCore::InspectorStyleSheet::setRuleSelector):
(WebCore::InspectorStyleSheet::styleSheetTextWithChangedStyle):

  • Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp:

(WebCore::Layout::outputLayoutBox):

  • Source/WebCore/loader/FormSubmission.cpp:

(WebCore::appendMailtoPostFormDataToURL):
(WebCore::encodingFromAcceptCharset):

  • Source/WebCore/page/Frame.cpp:

(WebCore::matchLabelsAgainstString):

  • Source/WebCore/platform/LocalizedStrings.cpp:

(WebCore::contextMenuItemTagLookUpInDictionary):
(WebCore::imageTitle):
(WebCore::webCryptoMasterKeyKeychainLabel):

  • Source/WebCore/platform/graphics/avfoundation/objc/AVStreamDataParserMIMETypeCache.mm:

(WebCore::AVStreamDataParserMIMETypeCache::canDecodeExtendedType):

  • Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:

(WebCore::MediaPlayerPrivateGStreamer::configureDownloadBuffer):

  • Source/WebCore/platform/graphics/gstreamer/mse/AppendPipeline.cpp:

(WebCore::AppendPipeline::AppendPipeline):
(WebCore::AppendPipeline::handleStateChangeMessage):

  • Source/WebCore/platform/gtk/SelectionData.cpp:

(WebCore::replaceNonBreakingSpaceWithSpace):

  • Source/WebCore/platform/mediastream/gstreamer/GStreamerDisplayCaptureDeviceManager.cpp:

(WebCore::GStreamerDisplayCaptureDeviceManager::createDisplayCaptureSource):

  • Source/WebCore/platform/network/ResourceResponseBase.cpp:

(WebCore::ResourceResponseBase::sanitizeSuggestedFilename):

  • Source/WebCore/platform/network/soup/ResourceRequestSoup.cpp:

(WebCore::ResourceRequest::createSoupURI const):

  • Source/WebCore/platform/network/soup/ResourceResponseSoup.cpp:

(WebCore::sanitizeFilename):

  • Source/WebCore/platform/text/DateTimeFormat.cpp:

(WebCore::DateTimeFormat::quoteAndAppendLiteral):

  • Source/WebCore/platform/text/LocaleToScriptMapping.cpp:

(WebCore::localeToScriptCodeForFontSelection):

  • Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp:

(WebCore::scanDirectoryForDictionaries):

  • Source/WebCore/platform/text/win/LocaleWin.cpp:

(WebCore::LocaleWin::shortMonthFormat):

  • Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp:

(WebCore::replaceNBSPWithSpace):

  • Source/WebCore/rendering/LegacyInlineTextBox.cpp:

(WebCore::LegacyInlineTextBox::outputLineBox const):

  • Source/WebCore/rendering/RenderBlock.cpp:

(WebCore::RenderBlock::updateSecurityDiscCharacters):

  • Source/WebCore/rendering/RenderObject.cpp:

(WebCore::RenderObject::outputRenderObject const):

  • Source/WebCore/rendering/RenderText.cpp:

(WebCore::RenderText::setRenderedText):

  • Source/WebCore/rendering/svg/RenderSVGInlineText.cpp:

(WebCore::applySVGWhitespaceRules):

  • Source/WebCore/xml/XSLTProcessor.cpp:

(WebCore::transformTextStringToXHTMLDocumentString):

Canonical link: https://commits.webkit.org/249949@main

File size: 4.8 KB
Line 
1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Copyright (C) 2016-2020 Apple Inc. All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30#pragma once
31
32#include "CSSParserToken.h"
33#include "CSSTokenizerInputStream.h"
34#include <climits>
35#include <wtf/text/StringView.h>
36#include <wtf/text/WTFString.h>
37
38namespace WebCore {
39
40class CSSTokenizerInputStream;
41class CSSParserObserverWrapper;
42class CSSParserTokenRange;
43
44class CSSTokenizer {
45 WTF_MAKE_NONCOPYABLE(CSSTokenizer);
46 WTF_MAKE_FAST_ALLOCATED;
47public:
48 static std::unique_ptr<CSSTokenizer> tryCreate(const String&);
49 static std::unique_ptr<CSSTokenizer> tryCreate(const String&, CSSParserObserverWrapper&); // For the inspector
50
51 explicit CSSTokenizer(const String&);
52 CSSTokenizer(const String&, CSSParserObserverWrapper&); // For the inspector
53
54 CSSParserTokenRange tokenRange() const;
55 unsigned tokenCount();
56
57 Vector<String>&& escapedStringsForAdoption() { return WTFMove(m_stringPool); }
58
59private:
60 CSSTokenizer(const String&, CSSParserObserverWrapper*, bool* constructionSuccess);
61
62 CSSParserToken nextToken();
63
64 UChar consume();
65 void reconsume(UChar);
66
67 String preprocessString(const String&);
68
69 CSSParserToken consumeNumericToken();
70 CSSParserToken consumeIdentLikeToken();
71 CSSParserToken consumeNumber();
72 CSSParserToken consumeStringTokenUntil(UChar);
73 CSSParserToken consumeUrlToken();
74
75 void consumeBadUrlRemnants();
76 void consumeSingleWhitespaceIfNext();
77 void consumeUntilCommentEndFound();
78
79 bool consumeIfNext(UChar);
80 StringView consumeName();
81 UChar32 consumeEscape();
82
83 bool nextTwoCharsAreValidEscape();
84 bool nextCharsAreNumber(UChar);
85 bool nextCharsAreNumber();
86 bool nextCharsAreIdentifier(UChar);
87 bool nextCharsAreIdentifier();
88
89 CSSParserToken blockStart(CSSParserTokenType);
90 CSSParserToken blockStart(CSSParserTokenType blockType, CSSParserTokenType, StringView);
91 CSSParserToken blockEnd(CSSParserTokenType, CSSParserTokenType startType);
92
93 CSSParserToken whiteSpace(UChar);
94 CSSParserToken leftParenthesis(UChar);
95 CSSParserToken rightParenthesis(UChar);
96 CSSParserToken leftBracket(UChar);
97 CSSParserToken rightBracket(UChar);
98 CSSParserToken leftBrace(UChar);
99 CSSParserToken rightBrace(UChar);
100 CSSParserToken plusOrFullStop(UChar);
101 CSSParserToken comma(UChar);
102 CSSParserToken hyphenMinus(UChar);
103 CSSParserToken asterisk(UChar);
104 CSSParserToken lessThan(UChar);
105 CSSParserToken solidus(UChar);
106 CSSParserToken colon(UChar);
107 CSSParserToken semiColon(UChar);
108 CSSParserToken hash(UChar);
109 CSSParserToken circumflexAccent(UChar);
110 CSSParserToken dollarSign(UChar);
111 CSSParserToken verticalLine(UChar);
112 CSSParserToken tilde(UChar);
113 CSSParserToken commercialAt(UChar);
114 CSSParserToken reverseSolidus(UChar);
115 CSSParserToken asciiDigit(UChar);
116 CSSParserToken letterU(UChar);
117 CSSParserToken nameStart(UChar);
118 CSSParserToken stringStart(UChar);
119 CSSParserToken endOfFile(UChar);
120
121 StringView registerString(const String&);
122
123 using CodePoint = CSSParserToken (CSSTokenizer::*)(UChar);
124 static const CodePoint codePoints[];
125
126 Vector<CSSParserTokenType, 8> m_blockStack;
127 Vector<CSSParserToken, 32> m_tokens;
128 // We only allocate strings when escapes are used.
129 Vector<String> m_stringPool;
130 CSSTokenizerInputStream m_input;
131};
132
133} // namespace WebCore
Note: See TracBrowser for help on using the repository browser.