Skip to content
Permalink
Browse files
Replace String::replace() functions with makeStringByReplacingAll() f…
…ree 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
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293326 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Apr 25, 2022
1 parent 98ef776 commit c8a037c3a36b05949b28db1d92f35a0070889a7e
Show file tree
Hide file tree
Showing 81 changed files with 178 additions and 206 deletions.
@@ -92,7 +92,7 @@ Protocol::ErrorStringOr<std::tuple<Ref<Protocol::Runtime::RemoteObject>, std::op
if (injectedScript.hasNoValue())
return makeUnexpected(errorString);

auto functionString = makeString("(function(WebInspectorAudit) { \"use strict\"; return eval(`(", String { test }.replace('`', "\\`"_s), ")`)(WebInspectorAudit); })");
auto functionString = makeString("(function(WebInspectorAudit) { \"use strict\"; return eval(`(", makeStringByReplacingAll(test, '`', "\\`"_s), ")`)(WebInspectorAudit); })");

InjectedScript::ExecuteOptions options;
options.objectGroup = "audit"_s;
@@ -1173,7 +1173,7 @@ void dumpJITMemory(const void* dst, const void* src, size_t size)
{
if (fd == -1) {
auto path = String::fromLatin1(Options::dumpJITMemoryPath());
path = path.replace("%pid", String::number(getCurrentProcessID()));
path = makeStringByReplacingAll(path, "%pid", String::number(getCurrentProcessID()));
fd = open(FileSystem::fileSystemRepresentation(path).data(), O_CREAT | O_TRUNC | O_APPEND | O_WRONLY | O_EXLOCK | O_NONBLOCK, 0666);
RELEASE_ASSERT(fd != -1);
}
@@ -53,9 +53,9 @@ void TypeProfiler::logTypesForTypeLocation(TypeLocation* location, VM& vm)

dataLog("\t\t", location->m_globalVariableID == TypeProfilerReturnStatement ? "[Return Statement]" : "[Normal Statement]", "\n");

dataLog("\t\t#Local#\n\t\t", location->m_instructionTypeSet->dumpTypes().replace("\n", "\n\t\t"), "\n");
dataLog("\t\t#Local#\n\t\t", makeStringByReplacingAll(location->m_instructionTypeSet->dumpTypes(), "\n", "\n\t\t"), "\n");
if (location->m_globalTypeSet)
dataLog("\t\t#Global#\n\t\t", location->m_globalTypeSet->dumpTypes().replace("\n", "\n\t\t"), "\n");
dataLog("\t\t#Global#\n\t\t", makeStringByReplacingAll(location->m_globalTypeSet->dumpTypes(), '\n', "\n\t\t"_s), "\n");
}

void TypeProfiler::insertNewLocation(TypeLocation* location)
@@ -347,8 +347,8 @@ String StructureShape::propertyHash()
builder.append(m_constructorName);
builder.append(':');
for (auto& key : m_fields) {
String property = key.get();
property.replace(":", "\\:"); // Ensure that hash({"foo:", "bar"}) != hash({"foo", ":bar"}) because we're using colons as a separator and colons are legal characters in field names in JS.
// Ensure that hash({"foo:", "bar"}) != hash({"foo", ":bar"}) because we're using colons as a separator and colons are legal characters in field names in JS.
String property = makeStringByReplacingAll(key.get(), ':', "\\:"_s);
builder.append(property);
}

@@ -180,7 +180,7 @@ void replace(String& string, const RegularExpression& target, StringView replace
index = target.match(string, index, &matchLength);
if (index < 0)
break;
string.replace(index, matchLength, replacement);
string = makeStringByReplacing(string, index, matchLength, replacement);
index += replacement.length();
if (!matchLength)
break; // Avoid infinite loop on 0-length matches, e.g. [a-z]*
@@ -151,7 +151,7 @@ static String canonicalLanguageIdentifier(const String& languageCode)
String lowercaseLanguageCode = languageCode.convertToASCIILowercase();

if (lowercaseLanguageCode.length() >= 3 && lowercaseLanguageCode[2] == '_')
lowercaseLanguageCode.replace(2, 1, "-");
lowercaseLanguageCode = makeStringByReplacing(lowercaseLanguageCode, 2, 1, "-"_s);

return lowercaseLanguageCode;
}
@@ -773,7 +773,7 @@ String mapHostNames(const String& string, URLDecodeFunction decodeFunction)
String result = string;
while (!hostNameRanges->isEmpty()) {
auto [location, length, mappedHostName] = hostNameRanges->takeLast();
result = result.replace(location, length, mappedHostName);
result = makeStringByReplacing(result, location, length, mappedHostName);
}
return result;
}
@@ -2887,12 +2887,12 @@ auto URLParser::parseURLEncodedForm(StringView input) -> URLEncodedForm
for (StringView bytes : input.split('&')) {
auto equalIndex = bytes.find('=');
if (equalIndex == notFound) {
auto name = formURLDecode(bytes.toString().replace('+', 0x20));
auto name = formURLDecode(makeStringByReplacingAll(bytes.toString(), '+', 0x20));
if (name)
output.append({ name.value(), emptyString() });
} else {
auto name = formURLDecode(bytes.left(equalIndex).toString().replace('+', 0x20));
auto value = formURLDecode(bytes.substring(equalIndex + 1).toString().replace('+', 0x20));
auto name = formURLDecode(makeStringByReplacingAll(bytes.left(equalIndex).toString(), '+', 0x20));
auto value = formURLDecode(makeStringByReplacingAll(bytes.substring(equalIndex + 1).toString(), '+', 0x20));
if (name && value)
output.append({ name.value(), value.value() });
}
@@ -531,7 +531,7 @@ AtomString makeAtomString(StringTypes... strings)
return result;
}

inline String makeStringByInserting(StringView originalString, StringView stringToInsert, unsigned position)
inline String WARN_UNUSED_RETURN makeStringByInserting(StringView originalString, StringView stringToInsert, unsigned position)
{
return makeString(originalString.left(position), stringToInsert, originalString.substring(position));
}
@@ -1308,25 +1308,30 @@ inline bool String::containsIgnoringASCIICase(StringView string, unsigned start)
return findIgnoringASCIICase(string, start) != notFound;
}

inline String& String::replace(StringView target, StringView replacement)
inline String WARN_UNUSED_RETURN makeStringByReplacingAll(const String& string, StringView target, StringView replacement)
{
if (m_impl)
m_impl = m_impl->replace(target, replacement);
return *this;
if (auto* impl = string.impl())
return String { impl->replace(target, replacement) };
return string;
}

inline String& String::replace(unsigned start, unsigned length, StringView replacement)
inline String WARN_UNUSED_RETURN makeStringByReplacing(const String& string, unsigned start, unsigned length, StringView replacement)
{
if (m_impl)
m_impl = m_impl->replace(start, length, replacement);
return *this;
if (auto* impl = string.impl())
return String { impl->replace(start, length, replacement) };
return string;
}

inline String& String::replace(UChar target, StringView replacement)
inline String WARN_UNUSED_RETURN makeStringByReplacingAll(const String& string, UChar target, StringView replacement)
{
if (m_impl)
m_impl = m_impl->replace(target, replacement);
return *this;
if (auto* impl = string.impl())
return String { impl->replace(target, replacement) };
return string;
}

inline String WARN_UNUSED_RETURN makeStringBySimplifyingNewLines(const String& string)
{
return makeStringByReplacingAll(makeStringByReplacingAll(string, "\r\n"_s, "\n"_s), '\r', '\n');
}

inline bool String::startsWith(StringView string) const
@@ -1408,6 +1413,8 @@ inline bool AtomString::endsWithIgnoringASCIICase(StringView string) const

using WTF::append;
using WTF::equal;
using WTF::makeStringByReplacing;
using WTF::makeStringBySimplifyingNewLines;
using WTF::StringView;
using WTF::StringViewWithUnderlyingString;
using WTF::hasUnpairedSurrogate;
@@ -191,13 +191,6 @@ class String final {
bool endsWith(char character) const { return endsWith(static_cast<UChar>(character)); }
bool hasInfixEndingAt(StringView suffix, unsigned end) const;

String& replace(UChar target, UChar replacement);
String& replace(UChar target, StringView replacement);
String& replace(UChar target, ASCIILiteral);
String& replace(UChar target, const char*) = delete;
String& replace(StringView target, StringView replacement);
String& replace(unsigned start, unsigned length, StringView replacement);

WTF_EXPORT_PRIVATE void remove(unsigned position, unsigned length = 1);

WTF_EXPORT_PRIVATE String substring(unsigned position, unsigned length = MaxLength) const;
@@ -482,20 +475,22 @@ inline UChar String::characterAt(unsigned index) const
return (*m_impl)[index];
}

inline String& String::replace(UChar target, UChar replacement)
inline String WARN_UNUSED_RETURN makeStringByReplacingAll(const String& string, UChar target, UChar replacement)
{
if (m_impl)
m_impl = m_impl->replace(target, replacement);
return *this;
if (auto impl = string.impl())
return String { impl->replace(target, replacement) };
return string;
}

ALWAYS_INLINE String& String::replace(UChar target, ASCIILiteral literal)
ALWAYS_INLINE String WARN_UNUSED_RETURN makeStringByReplacingAll(const String& string, UChar target, ASCIILiteral literal)
{
if (m_impl)
m_impl = m_impl->replace(target, literal.characters(), literal.length());
return *this;
if (auto impl = string.impl())
return String { impl->replace(target, literal.characters(), literal.length()) };
return string;
}

String makeStringByReplacingAll(const String&, UChar target, const char*) = delete;

template<size_t inlineCapacity> inline String String::make8BitFrom16BitSource(const Vector<UChar, inlineCapacity>& buffer)
{
return make8BitFrom16BitSource(buffer.data(), buffer.size());
@@ -636,6 +631,7 @@ using WTF::appendNumber;
using WTF::charactersToDouble;
using WTF::charactersToFloat;
using WTF::emptyString;
using WTF::makeStringByReplacingAll;
using WTF::nullString;
using WTF::equal;
using WTF::find;
@@ -36,8 +36,7 @@ static String platformLanguage()
if (localeDefault.isEmpty() || equalIgnoringASCIICase(localeDefault, "C") || equalIgnoringASCIICase(localeDefault, "POSIX"))
return "en-US"_s;

String normalizedDefault = localeDefault;
normalizedDefault.replace('_', '-');
auto normalizedDefault = makeStringByReplacingAll(localeDefault, '_', '-');
return normalizedDefault.left(normalizedDefault.find('.'));
}

@@ -916,21 +916,15 @@ String SQLiteIDBBackingStore::encodeDatabaseName(const String& databaseName)
if (databaseName.isEmpty())
return "%00"_s;

String filename = FileSystem::encodeForFileName(databaseName);
filename.replace('.', "%2E"_s);

return filename;
return makeStringByReplacingAll(FileSystem::encodeForFileName(databaseName), '.', "%2E"_s);
}

String SQLiteIDBBackingStore::decodeDatabaseName(const String& encodedName)
{
if (encodedName == "%00"_s)
return emptyString();

String name = encodedName;
name.replace("%2E", ".");

return FileSystem::decodeFromFilename(name);
return FileSystem::decodeFromFilename(makeStringByReplacingAll(encodedName, "%2E"_s, "."_s));
}

String SQLiteIDBBackingStore::fullDatabasePathForDirectory(const String& fullDatabaseDirectory)
@@ -216,7 +216,8 @@ bool GStreamerMediaEndpoint::setConfiguration(MediaEndpointConfiguration& config
bool stunSet = false;
for (auto& url : server.urls) {
if (url.protocol().startsWith("turn")) {
auto valid = url.string().isolatedCopy().replace("turn:", "turn://").replace("turns:", "turns://");
auto valid = makeStringByReplacingAll(url.string().isolatedCopy(), "turn:"_s, "turn://"_s);
valid = makeStringByReplacingAll(valid, "turns:"_s, "turns://"_s);
URL validURL(URL(), valid);
// FIXME: libnice currently doesn't seem to handle IPv6 addresses very well.
if (validURL.host().startsWith('['))
@@ -229,7 +230,7 @@ bool GStreamerMediaEndpoint::setConfiguration(MediaEndpointConfiguration& config
GST_WARNING("Unable to use TURN server: %s", validURL.string().utf8().data());
}
if (!stunSet && url.protocol().startsWith("stun")) {
auto valid = url.string().isolatedCopy().replace("stun:", "stun://");
auto valid = makeStringByReplacingAll(url.string().isolatedCopy(), "stun:"_s, "stun://"_s);
URL validURL(URL(), valid);
// FIXME: libnice currently doesn't seem to handle IPv6 addresses very well.
if (validURL.host().startsWith('['))
@@ -149,7 +149,7 @@ static HashMap<String, String> queryKeysAndValues(StringView queryString)
if (keyLength && valueLength) {
String key = queryString.substring(keyLocation, keyLength).convertToASCIILowercase();
String value = queryString.substring(valueLocation, valueLength).toString();
value.replace('+', ' ');
value = makeStringByReplacingAll(value, '+', ' ');

if (!key.isEmpty() && !value.isEmpty())
queryDictionary.add(key, value);
@@ -302,8 +302,7 @@ Vector<uint8_t> TextCodecICU::encode(StringView string, UnencodableHandling hand
// Encoding will change the yen sign back into a backslash.
String copy;
if (shouldShowBackslashAsCurrencySymbolIn(m_encodingName)) {
copy = string.toStringWithoutCopying();
copy.replace('\\', yenSign);
copy = makeStringByReplacingAll(string.toStringWithoutCopying(), '\\', yenSign);
string = copy;
}

@@ -1127,11 +1127,8 @@ Vector<String> AccessibilityRenderObject::determineDropEffects() const
{
// Order is aria-dropeffect, dropzone, webkitdropzone
const AtomString& dropEffects = getAttribute(aria_dropeffectAttr);
if (!dropEffects.isEmpty()) {
String dropEffectsString = dropEffects.string();
dropEffectsString.replace('\n', ' ');
return dropEffectsString.split(' ');
}
if (!dropEffects.isEmpty())
return makeStringByReplacingAll(dropEffects.string(), '\n', ' ').split(' ');

auto dropzone = getAttribute(dropzoneAttr);
if (!dropzone.isEmpty())
@@ -288,7 +288,7 @@ void AccessibilityAtspi::registerRoot(AccessibilityRootAtspi& rootObject, Vector
}

ensureCache();
String path = makeString("/org/a11y/webkit/accessible/", createVersion4UUIDString().replace('-', '_'));
String path = makeString("/org/a11y/webkit/accessible/", makeStringByReplacingAll(createVersion4UUIDString(), '-', '_'));
Vector<unsigned, 3> registeredObjects;
registeredObjects.reserveInitialCapacity(interfaces.size());
for (const auto& interface : interfaces) {
@@ -332,7 +332,7 @@ String AccessibilityAtspi::registerObject(AccessibilityObjectAtspi& atspiObject,
return { };

ensureCache();
String path = makeString("/org/a11y/atspi/accessible/", createVersion4UUIDString().replace('-', '_'));
String path = makeString("/org/a11y/atspi/accessible/", makeStringByReplacingAll(createVersion4UUIDString(), '-', '_'));
Vector<unsigned, 7> registeredObjects;
registeredObjects.reserveInitialCapacity(interfaces.size());
for (const auto& interface : interfaces) {
@@ -382,7 +382,7 @@ String AccessibilityAtspi::registerHyperlink(AccessibilityObjectAtspi& atspiObje
if (!m_connection)
return { };

String path = makeString("/org/a11y/atspi/accessible/", createVersion4UUIDString().replace('-', '_'));
String path = makeString("/org/a11y/atspi/accessible/", makeStringByReplacingAll(createVersion4UUIDString(), '-', '_'));
Vector<unsigned, 1> registeredObjects;
registeredObjects.reserveInitialCapacity(interfaces.size());
for (const auto& interface : interfaces) {
@@ -473,7 +473,7 @@ void RedirectAction::RegexSubstitutionAction::applyToURL(URL& url) const
String substitution = regexSubstitution;
size_t resultLength = JSValueToNumber(context, getProperty(result, "length"), nullptr);
for (size_t i = 0; i < std::min<size_t>(10, resultLength); i++)
substitution.replace(makeString('\\', i), valueToWTFString(getArrayValue(result, i)));
substitution = makeStringByReplacingAll(substitution, makeString('\\', i), valueToWTFString(getArrayValue(result, i)));

URL replacementURL(substitution);
if (replacementURL.isValid())
@@ -94,7 +94,7 @@ static Expected<Vector<String>, std::error_code> getDomainList(const JSON::Array
{ '$', "\\$"_s }
} };
for (auto& pair : escapeTable)
domain = domain.replace(pair.first, pair.second);
domain = makeStringByReplacingAll(domain, pair.first, pair.second);

const char* protocolRegex = "[a-z][a-z+.-]*:\\/\\/";
const char* allowSubdomainsRegex = "(.*\\.)*";
@@ -43,13 +43,13 @@
namespace WebCore {

// https://drafts.csswg.org/css-syntax/#input-preprocessing
String CSSTokenizer::preprocessString(String string)
String CSSTokenizer::preprocessString(const String& string)
{
// We don't replace '\r' and '\f' with '\n' as the specification suggests, instead
// we treat them all the same in the isNewLine function below.
StringImpl* oldImpl = string.impl();
string.replace('\0', replacementCharacter);
String replaced = replaceUnpairedSurrogatesWithReplacementCharacter(WTFMove(string));
String replaced = makeStringByReplacingAll(string, '\0', replacementCharacter);
replaced = replaceUnpairedSurrogatesWithReplacementCharacter(WTFMove(replaced));
if (replaced.impl() != oldImpl)
registerString(replaced);
return replaced;
@@ -64,7 +64,7 @@ class CSSTokenizer {
UChar consume();
void reconsume(UChar);

String preprocessString(String);
String preprocessString(const String&);

CSSParserToken consumeNumericToken();
CSSParserToken consumeIdentLikeToken();
@@ -54,8 +54,8 @@ String TextBox::debugDescription() const

stream << boxName() << " " << absoluteBoxRect() << " (" << this << ")";
auto textContent = text().originalContent().substring(text().start(), text().length()).toString();
textContent.replace('\\', "\\\\"_s);
textContent.replace('\n', "\\n"_s);
textContent = makeStringByReplacingAll(textContent, '\\', "\\\\"_s);
textContent = makeStringByReplacingAll(textContent, '\n', "\\n"_s);
const size_t maxPrintedLength = 80;
if (textContent.length() > maxPrintedLength) {
auto substring = StringView(textContent).left(maxPrintedLength);
@@ -6814,7 +6814,7 @@ String Document::displayStringModifiedByEncoding(const String& string) const
{
if (!m_decoder)
return string;
return String { string }.replace('\\', m_decoder->encoding().backslashAsCurrencySymbol());
return makeStringByReplacingAll(string, '\\', m_decoder->encoding().backslashAsCurrencySymbol());
}

void Document::dispatchPageshowEvent(PageshowEventPersistence persisted)
@@ -1798,9 +1798,8 @@ void Node::showNode(const char* prefix) const
if (!prefix)
prefix = "";
if (isTextNode()) {
String value = nodeValue();
value.replace('\\', "\\\\"_s);
value.replace('\n', "\\n"_s);
String value = makeStringByReplacingAll(nodeValue(), '\\', "\\\\"_s);
value = makeStringByReplacingAll(value, '\n', "\\n"_s);
fprintf(stderr, "%s%s\t%p \"%s\"\n", prefix, nodeName().utf8().data(), this, value.utf8().data());
} else {
StringBuilder attrs;