Skip to content

Commit

Permalink
Remove equalIgnoringCase since all callers really wanted equalIgnorin…
Browse files Browse the repository at this point in the history
…gASCIICase

https://bugs.webkit.org/show_bug.cgi?id=153411

Reviewed by Ryosuke Niwa.

Source/WebCore:

Tests: fast/media/media-query-non-ASCII-case-folding.html
       fast/dom/HTMLAnchorElement/anchor-non-ASCII-case-folding.html
       fast/xpath/xpath-non-ASCII-case-folding.html

No tests included that cover the minor behavior changes in Document::setDomain,
CSPSource::schemeMatches, CSPSource::hostMatches, OriginAccessEntry::operator==,
UserContentURLPattern::matches, UserContentURLPattern::matchesHost,
ContentFilterUnblockHandler::canHandleRequest. Would like to add tests for those
if possible, but it seems clear all are progressions.

For background on why this is the right thing to do in almost every case:

- MIME types are all ASCII and not case sensitive (details in RFC 2045)
  <http://tools.ietf.org/html/rfc2045>
- case insensitive comparisons in HTML are all "ASCII case-insensitive"
  https://www.w3.org/TR/html/infrastructure.html#ascii-case-insensitive
- same for CSS

* Modules/webdatabase/DatabaseAuthorizer.cpp:
(WebCore::DatabaseAuthorizer::denyBasedOnTableName): Use equalIgnoringASCIICase.
No change in behavior since the string we are comparing with is always
"__WebKitDatabaseInfoTable__" in practice.

* accessibility/AccessibilityNodeObject.cpp:
(WebCore::siblingWithAriaRole): Changed argument type to take a const char*,
added some FIXMEs and use equalIgnoringCase. No change in behavior since the
strings we are comparing with are "menu" and "menuitem".
(WebCore::AccessibilityNodeObject::menuElementForMenuButton): Updated to pass
arguments in reverse order.
(WebCore::AccessibilityNodeObject::menuItemElementForMenu): Ditto.

* css/CSSParser.cpp:
(WebCore::CSSParser::parseFontFaceValue): Use equalIgnoringASCIICase.
No change in behavior because the property names are all ASCII constants.

* css/CSSParserValues.h: Removed unused equalIgnoringCase function.

* css/MediaQueryEvaluator.cpp:
(WebCore::MediaQueryEvaluator::mediaTypeMatch): Use equalIgnoringASCIICase.
Changes behavior: No non-ASCII case folding when matching media types.
Covered by new test.
(WebCore::MediaQueryEvaluator::mediaTypeMatchSpecific): Use equalIgnoringASCIICase.
No change in behavior since the only string this is ever called with is "print".

* dom/DataTransfer.cpp:
(WebCore::DataTransfer::hasFileOfType): Use equalIgnoringASCIICase.
No change in behavior because local files will not have content types with
non-ASCII characters in them. In the extremely unlikely case that this is incorrect,
the change in behavior is a progression.

* dom/Document.cpp:
(WebCore::Document::setDomain): Use equalIgnoringASCIICase.
Changes behavior: Domains considered equal because of non-ASCII case folding
would get through without an error before, and now will properly throw an exception.

* dom/Element.cpp:
(WebCore::isStyleAttribute): Refactored into a helper function. Use
equalLettersIgnoringASCIICase. No change in behavior.
(WebCore::Element::synchronizeAttribute): Use isStyleAttribute.

* dom/TreeScope.cpp:
(WebCore::TreeScope::findAnchor): Use equalIgnoringASCIICase.
Changes behavior: Could go to an anchor and it would be considered a match because
of non-ASCII case folding. Covered by new test.

* html/HiddenInputType.cpp:
(WebCore::HiddenInputType::appendFormData): Use equalIgnoringASCIICase.
No change in behavior: comparing with an ASCII literal.
* html/canvas/WebGL2RenderingContext.cpp:
(WebCore::WebGL2RenderingContext::getExtension): Ditto.
* html/canvas/WebGLRenderingContext.cpp:
(WebCore::WebGLRenderingContext::getExtension): Ditto.

* html/parser/CSSPreloadScanner.cpp:
(WebCore::CSSPreloadScanner::emitRule): Use equalLettersIgnoringASCIICase and
StringView to avoid needing a special ruleEqualIgnoringCase function.
No change in behavior.

* inspector/InspectorNodeFinder.cpp:
(WebCore::InspectorNodeFinder::matchesElement): Use equalIgnoringASCIICase.
Changes behavior, but it's an inspector UI thing, not a web behavior thing,
so I don't think a new regression test is needed.

* loader/HistoryController.cpp:
(WebCore::HistoryController::currentItemShouldBeReplaced): Use
equalIgnoringASCIICase. No change in behavior because we are comparing
with "about:blank".

* loader/SubframeLoader.cpp:
(WebCore::findPluginMIMETypeFromURL): Use equalIgnoringASCIICase.
No change in behavior unless a plug-in claims an extension with non-ASCII
characters. I don't think a new regression test is needed.

* loader/appcache/ApplicationCacheHost.cpp:
(WebCore::ApplicationCacheHost::shouldLoadResourceFromApplicationCache):
Use equalIgnoringASCIICase. No change in behavior because both strings are
protocols from URLs and we don't parse non-ASCII characters into protocol strings;
non-ASCII are already encoding as punycode.
* loader/appcache/ManifestParser.cpp:
(WebCore::parseManifest): Ditto.

* page/ContentSecurityPolicy.cpp:
(WebCore::isExperimentalDirectiveName): Added. Used by isDirectiveName.
Uses equalLettersIgnoringASCIICase. No change in behavior.
(WebCore::isDirectiveName): Use equalLettersIgnoringASCIICase.
No change in behavior.
(WebCore::isSourceListNone): Use equalLettersIgnoringASCIICase. No
change in behavior.
(WebCore::CSPSource::schemeMatches): Use equalLettersIgnoringASCIICase
and equalIgnoringASCIICase. It's all about comparing URL protocols. The
old code might have done something strange if someone specified a protocol
with a non-ASCII character in it.
(WebCore::CSPSource::hostMatches): Use equalIgnoringASCIICase.
(WebCore::CSPSourceList::parseSource): Use equalLettersIgnoringASCIICase.
No change in behavior.
(WebCore::CSPDirectiveList::checkSourceAndReportViolation): Tweaked code
to do less unnecessary String allocation.
(WebCore::CSPDirectiveList::parseReflectedXSS): Use
equalLettersIgnoringASCIICase. No change in behavior.
(WebCore::CSPDirectiveList::addDirective): Ditto.
(WebCore::ContentSecurityPolicy::reportUnsupportedDirective): Use
equalLettersIgnoringASCIICase and remove unneeded global constant strings.
No change in behavior.
(WebCore::ContentSecurityPolicy::reportDirectiveAsSourceExpression):
Tweak code to eliminate unneeded local.
(WebCore::ContentSecurityPolicy::reportDuplicateDirective): Ditto.
(WebCore::ContentSecurityPolicy::reportInvalidSourceExpression): Use
equalLettersIgnoringASCIICase. No change in behavior.

* page/OriginAccessEntry.h:
(WebCore::operator==): Use equalLettersIgnoringASCIICase.

* page/Performance.cpp:
(WebCore::Performance::webkitGetEntriesByName): Use equalLettersIgnoringASCIICase.
No change in behavior.

* page/UserContentURLPattern.cpp:
(WebCore::UserContentURLPattern::matches): Use equalIgnoringASCIICase to match
schemes.
(WebCore::UserContentURLPattern::matchesHost): Use equalIgnoringASCIICase to
match host names.

* platform/URL.cpp:
(WebCore::URL::init): Use equalIgnoringASCIICase, and also use StringView to
avoid having to allocate a second string just for comparison purposes. Should be
better for efficiency with no change in behavior.

* platform/cocoa/ContentFilterUnblockHandlerCocoa.mm:
(WebCore::ContentFilterUnblockHandler::canHandleRequest): Use equalIgnoringASCIICase
to compare hosts.

* platform/efl/PlatformSpeechSynthesisProviderEfl.cpp:
(WebCore::PlatformSpeechSynthesisProviderEfl::voiceName): Use StringView and
equalIgnoringASCIICase to compare language tags. No test needed because there are
no language tags with non-ASCII characters in them.

* platform/graphics/FontCache.cpp:
(WebCore::FontPlatformDataCacheKey::operator==): Changed to use the equal
function from CaseFoldingHash. In a subsequent patch we will change this to be
ASCIICaseFoldingHash since font names don't need to compare non-ASCII characters
in a case folding manner, but for now preserve behavior.
(WebCore::alternateFamilyName): Use equalLettersIgnoringASCIICase to avoid having
to use a special familyNameEqualIgnoringCase function. This does mean there will
be a null check and a length check that wasn't there before, but the actual
comparison function will be tighter. Guessing it will be a wash. Also improved
the comments and sorted the Windows cases in with the others. No behavior change.

* platform/graphics/FontCascade.cpp:
(WebCore::operator==): Changed to use the equal function from CaseFoldingHash.
Same rationale as above in FontPlatformDataCacheKey.

* platform/graphics/FontDescription.cpp:
(WebCore::FontCascadeDescription::familiesEqualForTextAutoSizing): Use
equalIgnoringASCIICase to compare font family names. Only possible change in
behavior would be if actual fonts with non-ASCII names but that were specified
with different case in style sheets. Highly unlikely this exists.

* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::supportsType): Use equalLettersIgnoringASCIICase.
No change in behavior.
* platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:
(WebCore::keySystemIsSupported): Ditto.

* platform/graphics/freetype/FontCacheFreeType.cpp:
(WebCore::isCommonlyUsedGenericFamily): Added.
(WebCore::FontCache::createFontPlatformData): Moved code into the
isCommonlyUsedGenericFamily helper and used equalIgnoringASCIICase.

* platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp:
(WebCore::FontCustomPlatformData::supportsFormat): Use
equalLettersIgnoringASCIICase. No change in behavior.
* platform/graphics/win/FontCacheWin.cpp:
(WebCore::adjustedGDIFontWeight): Ditto.
(WebCore::FontCache::createFontPlatformData): Ditto.
* platform/graphics/win/FontCustomPlatformData.cpp:
(WebCore::FontCustomPlatformData::supportsFormat): Ditto.
* platform/graphics/win/FontCustomPlatformDataCairo.cpp:
(WebCore::FontCustomPlatformData::supportsFormat): Ditto.

* platform/mac/PlatformSpeechSynthesizerMac.mm:
(-[WebSpeechSynthesisWrapper speakUtterance:]): Use equalIgnoringASCIICase to
compare languages. No change in behavior because languages have all-ASCII names.

* platform/network/CacheValidation.cpp:
(WebCore::shouldUpdateHeaderAfterRevalidation): Use equalIgnoringASCIICase.
No change in behavior since it's a fixed list of all ASCII headers.
* platform/network/curl/ResourceHandleManager.cpp:
(WebCore::isAppendableHeader): Ditto.

* platform/network/mac/ResourceHandleMac.mm:
(WebCore::ResourceHandle::willSendRequest): Use equalIgnoringASCIICase.
No change in behavior because HTTP methods are all ASCII letters.

* platform/text/mac/LocaleMac.mm:
(WebCore::determineLocale): Use equalIgnoringASCIICase. No change in behavior
because locale languages identifiers are all ASCII.
* platform/text/win/LocaleWin.cpp:
(WebCore::LCIDFromLocaleInternal): Ditto.

* svg/SVGToOTFFontConversion.cpp:
(WebCore::SVGToOTFFontConverter::appendArabicReplacementSubtable):
Use equalIgnoringASCIICase. No change in behavior because Arabic form attribute
values are all ASCII.

* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::uppercaseKnownHTTPMethod): Use equalIgnoringASCIICase.
No change in behavior because these are all fixed known ASCII HTTP method names.

* xml/XPathFunctions.cpp:
(WebCore::XPath::FunLang::evaluate): Use equalIgnoringASCIICase. Changes behavior
if specifying a non-ASCII character. Covered by new test.

* xml/XPathStep.cpp:
(WebCore::XPath::nodeMatchesBasicTest): Use equalIgnoringASCIICase. Changes
behavior if an element local name or XPath predicate has a non-ASCII character.
Covered by new test.

Source/WebKit/mac:

* WebCoreSupport/WebFrameLoaderClient.mm:
(parameterValue): Use equalIgnoringASCIICase. No behavior change because the
only name we ever search for with this is "pluginspage".

Source/WebKit/win:

* Plugins/PluginDatabase.cpp:
(WebCore::PluginDatabase::MIMETypeForExtension): Use equalIgnoringASCIICase to compare
file extensions.
* Plugins/PluginDatabaseWin.cpp:
(WebCore::PluginDatabase::getPluginPathsInDirectories): Use equalLettersIgnoringASCIICase
to compare filenames.
* Plugins/PluginPackageWin.cpp:
(WebCore::PluginPackage::isPluginBlacklisted): Use equalLettersIgnoringASCIICase to
compare DLL filenames.
* Plugins/PluginStream.cpp:
(WebCore::PluginStream::destroyStream): Use equalLettersIgnoringASCIICase to check HTTP method.
* Plugins/PluginView.cpp:
(WebCore::PluginView::setParameters): Use equalLettersIgnoringASCIICase to check
plug-in parameter name.
* WebView.cpp:
(WebView::canHandleRequest): Use URL::protocolIs instead of equalIgnoringCase.

Source/WebKit2:

* Shared/API/c/WKString.cpp:
(WKStringIsEqualToUTF8CStringIgnoringCase): Use equalIgnoringASCIICase.
This is a change in behavior for callers who passed non-ASCII letters to
this function and expected case insensitive comparison.

* WebProcess/Plugins/PDF/DeprecatedPDFPlugin.mm:
(WebKit::PDFPlugin::streamDidReceiveResponse): Use equalIgnoringASCIICase.
No change in behavior because this is just checking a fixed ASCII MIME type.
(WebKit::PDFPlugin::manualStreamDidReceiveResponse): Ditto.
* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::streamDidReceiveResponse): Ditto.
(WebKit::PDFPlugin::manualStreamDidReceiveResponse): Ditto.

Source/WTF:

* wtf/text/AtomicString.h: Removed equalIgnoringCase.
Added some overloads for equalIgnoringASCIICase and moved the function bodies to
bottom of the file to make the function declarations easier to read and scan through.
I plan to do this for more of the functions in this class in the future.

* wtf/text/StringCommon.h: Added overloads for equalIgnoringASCIICase,
equalPossiblyIgnoringASCIICase, and a helper named equalIgnoringASCIICaseCommon.
Added an overload for equalLettersIgnoringASCIICase.

* wtf/text/StringImpl.cpp:
(WTF::equalIgnoringCase): Made the few remaining versions of this function private
to this file. Once we get done moving every client that should be using ASCII case
instead to new functions, these will almost certainly be deleted.
(WTF::equalIgnoringASCIICaseNonNull): Tweaked implementation a tiny bit.

* wtf/text/StringImpl.h: Sorted forward declarations at the top of the file.
Fixed some small formatting mistakes. Removed equalIgnoringCase, but left
equalIgnoringCaseNonNull behind for use by CaseFoldingHash until it is replaced
with ASCIICaseFoldingHash. Improved equalIgnoringASCIICase implementation.
Removed unneeded using for equalIgnoringASCIICase now that StringCommon.h takes
care of it.

* wtf/text/StringView.cpp:
(WTF::equalIgnoringASCIICase): Deleted. We no longer pass in the length for this,
so the arguments have changed and the implementation is also now in ASCIICommon.h
so it's an inline in the header file.

* wtf/text/StringView.h: Added an overload of equalIgnoringASCIICase,while
removing another.

* wtf/text/WTFString.h: Removed some unneeded forward delcarations. Fixed formatting
of the type name NSString *. Improved some comments. Removed equalIgnoringCase.
Separated declaration from implementation in a few cases to start making the
function declarations easier to read and scan through. I plan to do more in the future.

Tools:

* Scripts/do-webcore-rename: Removed rename of equalIgnoringCase since we
have removed the function instead.

* TestWebKitAPI/Tests/WTF/StringImpl.cpp:
(TestWebKitAPI::TEST): Updated test since nullptr is now ambiguous since we
added overloads for const char*.

* WebKitTestRunner/InjectedBundle/atk/AccessibilityUIElementAtk.cpp:
(WTR::AccessibilityUIElement::isPressActionSupported): Use equalLettersIgnoringASCIICase.
(WTR::AccessibilityUIElement::hasPopup): Ditto.
* WebKitTestRunner/cocoa/CrashReporterInfo.mm:
(WTR::testPathFromURL): Ditto.

LayoutTests:

* fast/dom/HTMLAnchorElement/anchor-non-ASCII-case-folding-expected.txt: Added.
* fast/dom/HTMLAnchorElement/anchor-non-ASCII-case-folding.html: Added.
* fast/dom/HTMLAnchorElement/resources/iframe-with-non-ASCII-matching-anchor.html: Added.

* fast/media/media-query-non-ASCII-case-folding-expected.txt: Added.
* fast/media/media-query-non-ASCII-case-folding.html: Added.

* fast/xpath/xpath-non-ASCII-case-folding-expected.txt: Added.
* fast/xpath/xpath-non-ASCII-case-folding.html: Added.

Canonical link: https://commits.webkit.org/171666@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@195743 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
darinadler committed Jan 28, 2016
1 parent e7cd5be commit 507aa34
Show file tree
Hide file tree
Showing 81 changed files with 947 additions and 480 deletions.
17 changes: 17 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,20 @@
2016-01-28 Darin Adler <darin@apple.com>

Remove equalIgnoringCase since all callers really wanted equalIgnoringASCIICase
https://bugs.webkit.org/show_bug.cgi?id=153411

Reviewed by Ryosuke Niwa.

* fast/dom/HTMLAnchorElement/anchor-non-ASCII-case-folding-expected.txt: Added.
* fast/dom/HTMLAnchorElement/anchor-non-ASCII-case-folding.html: Added.
* fast/dom/HTMLAnchorElement/resources/iframe-with-non-ASCII-matching-anchor.html: Added.

* fast/media/media-query-non-ASCII-case-folding-expected.txt: Added.
* fast/media/media-query-non-ASCII-case-folding.html: Added.

* fast/xpath/xpath-non-ASCII-case-folding-expected.txt: Added.
* fast/xpath/xpath-non-ASCII-case-folding.html: Added.

2016-01-28 Zalan Bujtas <zalan@apple.com>

Unexpected content wrapping at http://email.osh.com/H/2/v100000152474feb8ec7c1a1f4bbe5c7c0/HTML
Expand Down
@@ -0,0 +1,3 @@
This tests whether clicking on an anchor that only matches because of incorrect non-ASCII case folding will scroll to anchor. If clicking on the link below triggers a scroll, the test fails.

PASS
@@ -0,0 +1,2 @@
<p>This tests whether clicking on an anchor that only matches because of incorrect non-ASCII case folding will scroll to anchor. If clicking on the link below triggers a scroll, the test fails.</p>
<iframe src="resources/iframe-with-non-ASCII-matching-anchor.html" width="100%" height="2000"></iframe>
@@ -0,0 +1,41 @@
<meta charset="utf-8">
<script>

function runTest()
{
if (!window.testRunner)
return;
if (!window.eventSender)
return;

testRunner.waitUntilDone();
testRunner.dumpAsText();

var anchor = document.getElementById("start");
var x = frameElement.offsetLeft + anchor.offsetLeft + 2;
var y = frameElement.offsetTop + anchor.offsetTop + 2;
eventSender.mouseMoveTo(x, y);
eventSender.mouseDown();
eventSender.mouseUp();
setTimeout(finish, 1000);
}

function finish()
{
var result;
if (top.scrollY == 0)
result = "PASS";
else
result = "FAIL: should not match the anchor and should not trigger a scroll";

top.document.body.appendChild(document.createTextNode(result));

testRunner.notifyDone();
}

</script>
<body onload="runTest();">
<a id="start" href="#scroll">Go to anchor</a>
<div style="height: 1000px"></div>
<a name="ſcroll">Anchor</a>
</body>
@@ -0,0 +1,12 @@
Test media queries to make sure only ASCII case is folded, and other non-ASCII case folding is not performed.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS matchMedia('screen').matches is true
PASS matchMedia('SCREEN').matches is true
PASS matchMedia('ſcreen').matches is false
PASS successfullyParsed is true

TEST COMPLETE

@@ -0,0 +1,9 @@
<meta charset="utf-8">
<script src="../../resources/js-test-pre.js"></script>
<script>
description("Test media queries to make sure only ASCII case is folded, and other non-ASCII case folding is not performed.");
shouldBeTrue("matchMedia('screen').matches");
shouldBeTrue("matchMedia('SCREEN').matches");
shouldBeFalse("matchMedia('ſcreen').matches");
</script>
<script src="../../resources/js-test-post.js"></script>
15 changes: 15 additions & 0 deletions LayoutTests/fast/xpath/xpath-non-ASCII-case-folding-expected.txt
@@ -0,0 +1,15 @@
Test XPath element tag and language matching to make sure only ASCII case is folded, and other non-ASCII case folding is not performed.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS document.evaluate('count(.//span[attribute::id])', document.body, null, XPathResult.NUMBER_TYPE, null).numberValue is 1
PASS document.evaluate('count(.//ſpan[attribute::id])', document.body, null, XPathResult.NUMBER_TYPE, null).numberValue is 0
PASS document.evaluate('count(.//p[lang("en")])', document.body, null, XPathResult.NUMBER_TYPE, null).numberValue is 1
PASS document.evaluate('count(.//p[lang("sv")])', document.body, null, XPathResult.NUMBER_TYPE, null).numberValue is 1
PASS document.evaluate('count(.//p[lang("SV")])', document.body, null, XPathResult.NUMBER_TYPE, null).numberValue is 1
PASS document.evaluate('count(.//p[lang("ſv")])', document.body, null, XPathResult.NUMBER_TYPE, null).numberValue is 0
PASS successfullyParsed is true

TEST COMPLETE

26 changes: 26 additions & 0 deletions LayoutTests/fast/xpath/xpath-non-ASCII-case-folding.html
@@ -0,0 +1,26 @@
<meta charset="utf-8">
<script src="../../resources/js-test-pre.js"></script>
<body>
<div id="test">
<p id="English">This paragraph is marked as being in English.</p>
<p id="Swedish">This paragraph is marked as being in Swedish.</p>
<p><span id="anything">The span element containing the text in this paragraph has an ID specified on it.</span></p>
</div>
</body>
<script>
description("Test XPath element tag and language matching to make sure only ASCII case is folded, and other non-ASCII case folding is not performed.");

document.getElementById("English").setAttributeNS("http://www.w3.org/XML/1998/namespace", "lang", "en");
document.getElementById("Swedish").setAttributeNS("http://www.w3.org/XML/1998/namespace", "lang", "sv");

shouldBe("document.evaluate('count(.//span[attribute::id])', document.body, null, XPathResult.NUMBER_TYPE, null).numberValue", "1");
shouldBe("document.evaluate('count(.//ſpan[attribute::id])', document.body, null, XPathResult.NUMBER_TYPE, null).numberValue", "0");

shouldBe("document.evaluate('count(.//p[lang(\"en\")])', document.body, null, XPathResult.NUMBER_TYPE, null).numberValue", "1");
shouldBe("document.evaluate('count(.//p[lang(\"sv\")])', document.body, null, XPathResult.NUMBER_TYPE, null).numberValue", "1");
shouldBe("document.evaluate('count(.//p[lang(\"SV\")])', document.body, null, XPathResult.NUMBER_TYPE, null).numberValue", "1");
shouldBe("document.evaluate('count(.//p[lang(\"ſv\")])', document.body, null, XPathResult.NUMBER_TYPE, null).numberValue", "0");

document.body.removeChild(document.getElementById("test"));
</script>
<script src="../../resources/js-test-post.js"></script>
42 changes: 42 additions & 0 deletions Source/WTF/ChangeLog
@@ -1,3 +1,45 @@
2016-01-28 Darin Adler <darin@apple.com>

Remove equalIgnoringCase since all callers really wanted equalIgnoringASCIICase
https://bugs.webkit.org/show_bug.cgi?id=153411

Reviewed by Ryosuke Niwa.

* wtf/text/AtomicString.h: Removed equalIgnoringCase.
Added some overloads for equalIgnoringASCIICase and moved the function bodies to
bottom of the file to make the function declarations easier to read and scan through.
I plan to do this for more of the functions in this class in the future.

* wtf/text/StringCommon.h: Added overloads for equalIgnoringASCIICase,
equalPossiblyIgnoringASCIICase, and a helper named equalIgnoringASCIICaseCommon.
Added an overload for equalLettersIgnoringASCIICase.

* wtf/text/StringImpl.cpp:
(WTF::equalIgnoringCase): Made the few remaining versions of this function private
to this file. Once we get done moving every client that should be using ASCII case
instead to new functions, these will almost certainly be deleted.
(WTF::equalIgnoringASCIICaseNonNull): Tweaked implementation a tiny bit.

* wtf/text/StringImpl.h: Sorted forward declarations at the top of the file.
Fixed some small formatting mistakes. Removed equalIgnoringCase, but left
equalIgnoringCaseNonNull behind for use by CaseFoldingHash until it is replaced
with ASCIICaseFoldingHash. Improved equalIgnoringASCIICase implementation.
Removed unneeded using for equalIgnoringASCIICase now that StringCommon.h takes
care of it.

* wtf/text/StringView.cpp:
(WTF::equalIgnoringASCIICase): Deleted. We no longer pass in the length for this,
so the arguments have changed and the implementation is also now in ASCIICommon.h
so it's an inline in the header file.

* wtf/text/StringView.h: Added an overload of equalIgnoringASCIICase,while
removing another.

* wtf/text/WTFString.h: Removed some unneeded forward delcarations. Fixed formatting
of the type name NSString *. Improved some comments. Removed equalIgnoringCase.
Separated declaration from implementation in a few cases to start making the
function declarations easier to read and scan through. I plan to do more in the future.

2016-01-27 Chris Dumez <cdumez@apple.com>

window.atob() should ignore spaces in input
Expand Down
37 changes: 25 additions & 12 deletions Source/WTF/wtf/text/AtomicString.h
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2004, 2005, 2006, 2008, 2014 Apple Inc. All rights reserved.
* Copyright (C) 2004-2006, 2008, 2014-2016 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -215,17 +215,10 @@ inline bool operator!=(const LChar* a, const AtomicString& b) { return !(b == a)
inline bool operator!=(const String& a, const AtomicString& b) { return !equal(a.impl(), b.impl()); }
inline bool operator!=(const Vector<UChar>& a, const AtomicString& b) { return !(a == b); }

inline bool equalIgnoringCase(const AtomicString& a, const AtomicString& b) { return equalIgnoringCase(a.impl(), b.impl()); }
inline bool equalIgnoringCase(const AtomicString& a, const LChar* b) { return equalIgnoringCase(a.impl(), b); }
inline bool equalIgnoringCase(const AtomicString& a, const char* b) { return equalIgnoringCase(a.impl(), reinterpret_cast<const LChar*>(b)); }
inline bool equalIgnoringCase(const AtomicString& a, const String& b) { return equalIgnoringCase(a.impl(), b.impl()); }
inline bool equalIgnoringCase(const LChar* a, const AtomicString& b) { return equalIgnoringCase(a, b.impl()); }
inline bool equalIgnoringCase(const char* a, const AtomicString& b) { return equalIgnoringCase(reinterpret_cast<const LChar*>(a), b.impl()); }
inline bool equalIgnoringCase(const String& a, const AtomicString& b) { return equalIgnoringCase(a.impl(), b.impl()); }

inline bool equalIgnoringASCIICase(const AtomicString& a, const AtomicString& b) { return equalIgnoringASCIICase(a.impl(), b.impl()); }
inline bool equalIgnoringASCIICase(const AtomicString& a, const String& b) { return equalIgnoringASCIICase(a.impl(), b.impl()); }
inline bool equalIgnoringASCIICase(const String& a, const AtomicString& b) { return equalIgnoringASCIICase(a.impl(), b.impl()); }
bool equalIgnoringASCIICase(const AtomicString&, const AtomicString&);
bool equalIgnoringASCIICase(const AtomicString&, const String&);
bool equalIgnoringASCIICase(const String&, const AtomicString&);
bool equalIgnoringASCIICase(const AtomicString&, const char*);

template<unsigned length> bool equalLettersIgnoringASCIICase(const AtomicString&, const char (&lowercaseLetters)[length]);

Expand Down Expand Up @@ -344,6 +337,26 @@ template<unsigned length> inline bool equalLettersIgnoringASCIICase(const Atomic
return equalLettersIgnoringASCIICase(string.string(), lowercaseLetters);
}

inline bool equalIgnoringASCIICase(const AtomicString& a, const AtomicString& b)
{
return equalIgnoringASCIICase(a.string(), b.string());
}

inline bool equalIgnoringASCIICase(const AtomicString& a, const String& b)
{
return equalIgnoringASCIICase(a.string(), b);
}

inline bool equalIgnoringASCIICase(const String& a, const AtomicString& b)
{
return equalIgnoringASCIICase(a, b.string());
}

inline bool equalIgnoringASCIICase(const AtomicString& a, const char* b)
{
return equalIgnoringASCIICase(a.string(), b);
}

} // namespace WTF

#ifndef ATOMICSTRING_HIDE_GLOBALS
Expand Down
35 changes: 34 additions & 1 deletion Source/WTF/wtf/text/StringCommon.h
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Apple Inc. All rights reserved.
* Copyright (C) 2015-2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -31,7 +31,14 @@

namespace WTF {

template<typename CharacterTypeA, typename CharacterTypeB> bool equalIgnoringASCIICase(const CharacterTypeA*, const CharacterTypeB*, unsigned length);
template<typename CharacterTypeA, typename CharacterTypeB> bool equalIgnoringASCIICase(const CharacterTypeA*, unsigned lengthA, const CharacterTypeB*, unsigned lengthB);

template<typename StringClassA, typename StringClassB> bool equalIgnoringASCIICaseCommon(const StringClassA&, const StringClassB&);

template<typename CharacterType> bool equalLettersIgnoringASCIICase(const CharacterType*, const char* lowercaseLetters, unsigned length);
template<typename CharacterType, unsigned lowercaseLettersLength> bool equalLettersIgnoringASCIICase(const CharacterType*, unsigned charactersLength, const char (&lowercaseLetters)[lowercaseLettersLength]);

template<typename StringClass, unsigned length> bool equalLettersIgnoringASCIICaseCommon(const StringClass&, const char (&lowercaseLetters)[length]);

template<typename T>
Expand Down Expand Up @@ -326,6 +333,11 @@ inline bool equalIgnoringASCIICase(const CharacterTypeA* a, const CharacterTypeB
return true;
}

template<typename CharacterTypeA, typename CharacterTypeB> inline bool equalIgnoringASCIICase(const CharacterTypeA* a, unsigned lengthA, const CharacterTypeB* b, unsigned lengthB)
{
return lengthA == lengthB && equalIgnoringASCIICase(a, b, lengthA);
}

template<typename StringClassA, typename StringClassB>
bool equalIgnoringASCIICaseCommon(const StringClassA& a, const StringClassB& b)
{
Expand All @@ -346,6 +358,18 @@ bool equalIgnoringASCIICaseCommon(const StringClassA& a, const StringClassB& b)
return equalIgnoringASCIICase(a.characters16(), b.characters16(), length);
}

template<typename StringClassA> bool equalIgnoringASCIICaseCommon(const StringClassA& a, const char* b)
{
unsigned length = a.length();
if (length != strlen(b))
return false;

if (a.is8Bit())
return equalIgnoringASCIICase(a.characters8(), b, length);

return equalIgnoringASCIICase(a.characters16(), b, length);
}

template<typename StringClassA, typename StringClassB>
bool startsWith(const StringClassA& reference, const StringClassB& prefix)
{
Expand Down Expand Up @@ -559,6 +583,13 @@ template<typename CharacterType> inline bool equalLettersIgnoringASCIICase(const
return true;
}

template<typename CharacterType, unsigned lowercaseLettersLength> inline bool equalLettersIgnoringASCIICase(const CharacterType* characters, unsigned charactersLength, const char (&lowercaseLetters)[lowercaseLettersLength])
{
ASSERT(strlen(lowercaseLetters) == lowercaseLettersLength - 1);
unsigned lowercaseLettersStringLength = lowercaseLettersLength - 1;
return charactersLength == lowercaseLettersStringLength && equalLettersIgnoringASCIICase(characters, lowercaseLetters, lowercaseLettersStringLength);
}

// This is intentionally not marked inline because it's used often and is not speed-critical enough to want it inlined everywhere.
template<typename StringClass> bool equalLettersIgnoringASCIICaseCommonWithoutLength(const StringClass& string, const char* lowercaseLetters)
{
Expand All @@ -578,12 +609,14 @@ template<typename StringClass> bool equalLettersIgnoringASCIICaseCommonWithoutLe
template<typename StringClass, unsigned length> inline bool equalLettersIgnoringASCIICaseCommon(const StringClass& string, const char (&lowercaseLetters)[length])
{
// Don't actually use the length; we are choosing code size over speed.
ASSERT(strlen(lowercaseLetters) == length - 1);
const char* pointer = lowercaseLetters;
return equalLettersIgnoringASCIICaseCommonWithoutLength(string, pointer);
}

}

using WTF::equalIgnoringASCIICase;
using WTF::equalLettersIgnoringASCIICase;

#endif // StringCommon_h
2 changes: 1 addition & 1 deletion Source/WTF/wtf/text/StringHash.h
Expand Up @@ -110,7 +110,7 @@ namespace WTF {

static inline bool equal(const StringImpl* a, const StringImpl* b)
{
return equalIgnoringCaseNonNull(a, b);
return equalCompatibiltyCaselessNonNull(a, b);
}

static unsigned hash(const RefPtr<StringImpl>& key)
Expand Down

0 comments on commit 507aa34

Please sign in to comment.