From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WebCore/html/parser/HTMLParserIdioms.h | 93 +++++++++++++++++++++------ 1 file changed, 75 insertions(+), 18 deletions(-) (limited to 'Source/WebCore/html/parser/HTMLParserIdioms.h') diff --git a/Source/WebCore/html/parser/HTMLParserIdioms.h b/Source/WebCore/html/parser/HTMLParserIdioms.h index 7c5914248..29a6c6ed3 100644 --- a/Source/WebCore/html/parser/HTMLParserIdioms.h +++ b/Source/WebCore/html/parser/HTMLParserIdioms.h @@ -22,30 +22,32 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef HTMLParserIdioms_h -#define HTMLParserIdioms_h +#pragma once -#include "QualifiedName.h" +#include #include -#include +#include +#include +#include namespace WebCore { class Decimal; +class QualifiedName; // Space characters as defined by the HTML specification. -bool isHTMLSpace(UChar); +template bool isHTMLSpace(CharacterType); +template bool isComma(CharacterType); +template bool isHTMLSpaceOrComma(CharacterType); bool isHTMLLineBreak(UChar); bool isNotHTMLSpace(UChar); -bool isHTMLSpaceButNotLineBreak(UChar character); +bool isHTMLSpaceButNotLineBreak(UChar); + +// 2147483647 is 2^31 - 1. +static const unsigned maxHTMLNonNegativeInteger = 2147483647; // Strip leading and trailing whitespace as defined by the HTML specification. -String stripLeadingAndTrailingHTMLSpaces(const String&); -template -String stripLeadingAndTrailingHTMLSpaces(const Vector& vector) -{ - return stripLeadingAndTrailingHTMLSpaces(StringImpl::create8BitIfPossible(vector)); -} +WEBCORE_EXPORT String stripLeadingAndTrailingHTMLSpaces(const String&); // An implementation of the HTML specification's algorithm to convert a number to a string for number and range types. String serializeForNumberType(const Decimal&); @@ -60,14 +62,33 @@ double parseToDoubleForNumberType(const String&); double parseToDoubleForNumberType(const String&, double fallbackValue); // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-integers -bool parseHTMLInteger(const String&, int&); +WEBCORE_EXPORT std::optional parseHTMLInteger(StringView); // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-non-negative-integers -bool parseHTMLNonNegativeInteger(const String&, unsigned int&); +WEBCORE_EXPORT std::optional parseHTMLNonNegativeInteger(StringView); + +// https://html.spec.whatwg.org/#valid-non-negative-integer +std::optional parseValidHTMLNonNegativeInteger(StringView); + +// https://html.spec.whatwg.org/#valid-floating-point-number +std::optional parseValidHTMLFloatingPointNumber(StringView); + +// https://html.spec.whatwg.org/multipage/infrastructure.html#rules-for-parsing-floating-point-number-values +Vector parseHTMLListOfOfFloatingPointNumberValues(StringView); + +// https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-refresh +bool parseMetaHTTPEquivRefresh(const StringView&, double& delay, String& url); + +// https://html.spec.whatwg.org/multipage/infrastructure.html#cors-settings-attribute +String parseCORSSettingsAttribute(const AtomicString&); + +bool threadSafeMatch(const QualifiedName&, const QualifiedName&); + +AtomicString parseHTMLHashNameReference(StringView); // Inline implementations of some of the functions declared above. -inline bool isHTMLSpace(UChar character) +template inline bool isHTMLSpace(CharacterType character) { // Histogram from Apple's page load test combined with some ad hoc browsing some other test suites. // @@ -87,6 +108,16 @@ inline bool isHTMLLineBreak(UChar character) return character <= '\r' && (character == '\n' || character == '\r'); } +template inline bool isComma(CharacterType character) +{ + return character == ','; +} + +template inline bool isHTMLSpaceOrComma(CharacterType character) +{ + return isComma(character) || isHTMLSpace(character); +} + inline bool isNotHTMLSpace(UChar character) { return !isHTMLSpace(character); @@ -97,10 +128,36 @@ inline bool isHTMLSpaceButNotLineBreak(UChar character) return isHTMLSpace(character) && !isHTMLLineBreak(character); } -bool threadSafeMatch(const QualifiedName&, const QualifiedName&); +// https://html.spec.whatwg.org/multipage/infrastructure.html#limited-to-only-non-negative-numbers-greater-than-zero +inline unsigned limitToOnlyHTMLNonNegativeNumbersGreaterThanZero(unsigned value, unsigned defaultValue = 1) +{ + return (value > 0 && value <= maxHTMLNonNegativeInteger) ? value : defaultValue; +} -String bestFitSourceForImageAttributes(float deviceScaleFactor, const String& srcAttribute, const String& sourceSetAttribute); +inline unsigned limitToOnlyHTMLNonNegativeNumbersGreaterThanZero(StringView stringValue, unsigned defaultValue = 1) +{ + ASSERT(defaultValue > 0); + ASSERT(defaultValue <= maxHTMLNonNegativeInteger); + auto optionalValue = parseHTMLNonNegativeInteger(stringValue); + unsigned value = optionalValue && optionalValue.value() ? optionalValue.value() : defaultValue; + ASSERT(value > 0); + ASSERT(value <= maxHTMLNonNegativeInteger); + return value; +} + +// https://html.spec.whatwg.org/#reflecting-content-attributes-in-idl-attributes:idl-unsigned-long +inline unsigned limitToOnlyHTMLNonNegative(unsigned value, unsigned defaultValue = 0) +{ + ASSERT(defaultValue <= maxHTMLNonNegativeInteger); + return value <= maxHTMLNonNegativeInteger ? value : defaultValue; +} +inline unsigned limitToOnlyHTMLNonNegative(StringView stringValue, unsigned defaultValue = 0) +{ + ASSERT(defaultValue <= maxHTMLNonNegativeInteger); + unsigned value = parseHTMLNonNegativeInteger(stringValue).value_or(defaultValue); + ASSERT(value <= maxHTMLNonNegativeInteger); + return value; } -#endif +} // namespace WebCore -- cgit v1.2.1