| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #ifndef HTMLParserIdioms_h | 25 #ifndef HTMLParserIdioms_h |
| 26 #define HTMLParserIdioms_h | 26 #define HTMLParserIdioms_h |
| 27 | 27 |
| 28 #include "core/CoreExport.h" | 28 #include "core/CoreExport.h" |
| 29 #include "core/dom/QualifiedName.h" | 29 #include "core/dom/QualifiedName.h" |
| 30 #include "platform/Decimal.h" | 30 #include "platform/Decimal.h" |
| 31 #include "wtf/Forward.h" | 31 #include "wtf/Forward.h" |
| 32 #include "wtf/text/WTFString.h" | 32 #include "wtf/text/WTFString.h" |
| 33 | 33 |
| 34 namespace WTF { | 34 namespace WTF { |
| 35 class TextEncoding; | 35 class TextEncoding; |
| 36 } | 36 } |
| 37 | 37 |
| 38 namespace blink { | 38 namespace blink { |
| 39 | 39 |
| 40 // Strip leading and trailing whitespace as defined by the HTML specification. | 40 // Strip leading and trailing whitespace as defined by the HTML specification. |
| 41 String stripLeadingAndTrailingHTMLSpaces(const String&); | 41 String stripLeadingAndTrailingHTMLSpaces(const String&); |
| 42 | 42 |
| 43 // An implementation of the HTML specification's algorithm to convert a number t
o a string for number and range types. | 43 // An implementation of the HTML specification's algorithm to convert a number |
| 44 // to a string for number and range types. |
| 44 String serializeForNumberType(const Decimal&); | 45 String serializeForNumberType(const Decimal&); |
| 45 String serializeForNumberType(double); | 46 String serializeForNumberType(double); |
| 46 | 47 |
| 47 // Convert the specified string to a decimal/double. If the conversion fails, th
e return value is fallback value or NaN if not specified. | 48 // Convert the specified string to a decimal/double. If the conversion fails, |
| 48 // Leading or trailing illegal characters cause failure, as does passing an empt
y string. | 49 // the return value is fallback value or NaN if not specified. Leading or |
| 49 // The double* parameter may be 0 to check if the string can be parsed without g
etting the result. | 50 // trailing illegal characters cause failure, as does passing an empty string. |
| 51 // The double* parameter may be 0 to check if the string can be parsed without |
| 52 // getting the result. |
| 50 Decimal parseToDecimalForNumberType( | 53 Decimal parseToDecimalForNumberType( |
| 51 const String&, | 54 const String&, |
| 52 const Decimal& fallbackValue = Decimal::nan()); | 55 const Decimal& fallbackValue = Decimal::nan()); |
| 53 double parseToDoubleForNumberType( | 56 double parseToDoubleForNumberType( |
| 54 const String&, | 57 const String&, |
| 55 double fallbackValue = std::numeric_limits<double>::quiet_NaN()); | 58 double fallbackValue = std::numeric_limits<double>::quiet_NaN()); |
| 56 | 59 |
| 57 // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-integers | 60 // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-integers |
| 58 bool parseHTMLInteger(const String&, int&); | 61 bool parseHTMLInteger(const String&, int&); |
| 59 | 62 |
| 60 // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-non-nega
tive-integers | 63 // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-non-nega
tive-integers |
| 61 CORE_EXPORT bool parseHTMLNonNegativeInteger(const String&, unsigned&); | 64 CORE_EXPORT bool parseHTMLNonNegativeInteger(const String&, unsigned&); |
| 62 | 65 |
| 63 // https://html.spec.whatwg.org/multipage/infrastructure.html#rules-for-parsing-
a-list-of-floating-point-numbers | 66 // https://html.spec.whatwg.org/multipage/infrastructure.html#rules-for-parsing-
a-list-of-floating-point-numbers |
| 64 CORE_EXPORT Vector<double> parseHTMLListOfFloatingPointNumbers(const String&); | 67 CORE_EXPORT Vector<double> parseHTMLListOfFloatingPointNumbers(const String&); |
| 65 | 68 |
| 66 typedef Vector<std::pair<String, String>> HTMLAttributeList; | 69 typedef Vector<std::pair<String, String>> HTMLAttributeList; |
| 67 // The returned encoding might not be valid. | 70 // The returned encoding might not be valid. |
| 68 WTF::TextEncoding encodingFromMetaAttributes(const HTMLAttributeList&); | 71 WTF::TextEncoding encodingFromMetaAttributes(const HTMLAttributeList&); |
| 69 | 72 |
| 70 // Space characters as defined by the HTML specification. | 73 // Space characters as defined by the HTML specification. |
| 71 template <typename CharType> | 74 template <typename CharType> |
| 72 inline bool isHTMLSpace(CharType character) { | 75 inline bool isHTMLSpace(CharType character) { |
| 73 // Histogram from Apple's page load test combined with some ad hoc browsing so
me other test suites. | 76 // Histogram from Apple's page load test combined with some ad hoc browsing |
| 77 // some other test suites. |
| 74 // | 78 // |
| 75 // 82%: 216330 non-space characters, all > U+0020 | 79 // 82%: 216330 non-space characters, all > U+0020 |
| 76 // 11%: 30017 plain space characters, U+0020 | 80 // 11%: 30017 plain space characters, U+0020 |
| 77 // 5%: 12099 newline characters, U+000A | 81 // 5%: 12099 newline characters, U+000A |
| 78 // 2%: 5346 tab characters, U+0009 | 82 // 2%: 5346 tab characters, U+0009 |
| 79 // | 83 // |
| 80 // No other characters seen. No U+000C or U+000D, and no other control charact
ers. | 84 // No other characters seen. No U+000C or U+000D, and no other control |
| 81 // Accordingly, we check for non-spaces first, then space, then newline, then
tab, then the other characters. | 85 // characters. Accordingly, we check for non-spaces first, then space, then |
| 86 // newline, then tab, then the other characters. |
| 82 | 87 |
| 83 return character <= ' ' && | 88 return character <= ' ' && |
| 84 (character == ' ' || character == '\n' || character == '\t' || | 89 (character == ' ' || character == '\n' || character == '\t' || |
| 85 character == '\r' || character == '\f'); | 90 character == '\r' || character == '\f'); |
| 86 } | 91 } |
| 87 | 92 |
| 88 template <typename CharType> | 93 template <typename CharType> |
| 89 inline bool isComma(CharType character) { | 94 inline bool isComma(CharType character) { |
| 90 return character == ','; | 95 return character == ','; |
| 91 } | 96 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 121 } | 126 } |
| 122 | 127 |
| 123 inline static String attemptStaticStringCreation(const String str) { | 128 inline static String attemptStaticStringCreation(const String str) { |
| 124 if (!str.is8Bit()) | 129 if (!str.is8Bit()) |
| 125 return attemptStaticStringCreation(str.characters16(), str.length(), | 130 return attemptStaticStringCreation(str.characters16(), str.length(), |
| 126 Force16Bit); | 131 Force16Bit); |
| 127 return attemptStaticStringCreation(str.characters8(), str.length()); | 132 return attemptStaticStringCreation(str.characters8(), str.length()); |
| 128 } | 133 } |
| 129 | 134 |
| 130 } // namespace blink | 135 } // namespace blink |
| 131 #endif | 136 |
| 137 #endif // HTMLParserIdioms_h |
| OLD | NEW |