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 |
(...skipping 10 matching lines...) Expand all Loading... |
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 */ | 23 */ |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 #include "core/html/parser/HTMLParserIdioms.h" | 26 #include "core/html/parser/HTMLParserIdioms.h" |
27 | 27 |
28 #include <limits> | 28 #include <limits> |
29 #include "core/dom/QualifiedName.h" | 29 #include "core/dom/QualifiedName.h" |
30 #include "core/html/parser/HTMLIdentifier.h" | 30 #include "core/html/parser/HTMLIdentifier.h" |
31 #include "platform/Decimal.h" | |
32 #include "wtf/MathExtras.h" | 31 #include "wtf/MathExtras.h" |
33 #include "wtf/text/AtomicString.h" | 32 #include "wtf/text/AtomicString.h" |
34 #include "wtf/text/StringBuilder.h" | 33 #include "wtf/text/StringBuilder.h" |
35 | 34 |
36 namespace WebCore { | 35 namespace WebCore { |
37 | 36 |
38 template <typename CharType> | 37 template <typename CharType> |
39 static String stripLeadingAndTrailingHTMLSpaces(String string, const CharType* c
haracters, unsigned length) | 38 static String stripLeadingAndTrailingHTMLSpaces(String string, const CharType* c
haracters, unsigned length) |
40 { | 39 { |
41 unsigned numLeadingSpaces = 0; | 40 unsigned numLeadingSpaces = 0; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // See HTML5 2.5.4.3 `Real numbers.' | 107 // See HTML5 2.5.4.3 `Real numbers.' |
109 // FIXME: We should use numeric_limits<double>::max for number input type. | 108 // FIXME: We should use numeric_limits<double>::max for number input type. |
110 const Decimal floatMax = Decimal::fromDouble(std::numeric_limits<float>::max
()); | 109 const Decimal floatMax = Decimal::fromDouble(std::numeric_limits<float>::max
()); |
111 if (value < -floatMax || value > floatMax) | 110 if (value < -floatMax || value > floatMax) |
112 return fallbackValue; | 111 return fallbackValue; |
113 | 112 |
114 // We return +0 for -0 case. | 113 // We return +0 for -0 case. |
115 return value.isZero() ? Decimal(0) : value; | 114 return value.isZero() ? Decimal(0) : value; |
116 } | 115 } |
117 | 116 |
118 Decimal parseToDecimalForNumberType(const String& string) | |
119 { | |
120 return parseToDecimalForNumberType(string, Decimal::nan()); | |
121 } | |
122 | |
123 double parseToDoubleForNumberType(const String& string, double fallbackValue) | 117 double parseToDoubleForNumberType(const String& string, double fallbackValue) |
124 { | 118 { |
125 // See HTML5 2.5.4.3 `Real numbers.' | 119 // See HTML5 2.5.4.3 `Real numbers.' |
126 | 120 |
127 // String::toDouble() accepts leading + and whitespace characters, which are
not valid here. | 121 // String::toDouble() accepts leading + and whitespace characters, which are
not valid here. |
128 UChar firstCharacter = string[0]; | 122 UChar firstCharacter = string[0]; |
129 if (firstCharacter != '-' && firstCharacter != '.' && !isASCIIDigit(firstCha
racter)) | 123 if (firstCharacter != '-' && firstCharacter != '.' && !isASCIIDigit(firstCha
racter)) |
130 return fallbackValue; | 124 return fallbackValue; |
131 | 125 |
132 bool valid = false; | 126 bool valid = false; |
133 double value = string.toDouble(&valid); | 127 double value = string.toDouble(&valid); |
134 if (!valid) | 128 if (!valid) |
135 return fallbackValue; | 129 return fallbackValue; |
136 | 130 |
137 // NaN and infinity are considered valid by String::toDouble, but not valid
here. | 131 // NaN and infinity are considered valid by String::toDouble, but not valid
here. |
138 if (!std::isfinite(value)) | 132 if (!std::isfinite(value)) |
139 return fallbackValue; | 133 return fallbackValue; |
140 | 134 |
141 // Numbers are considered finite IEEE 754 single-precision floating point va
lues. | 135 // Numbers are considered finite IEEE 754 single-precision floating point va
lues. |
142 // See HTML5 2.5.4.3 `Real numbers.' | 136 // See HTML5 2.5.4.3 `Real numbers.' |
143 if (-std::numeric_limits<float>::max() > value || value > std::numeric_limit
s<float>::max()) | 137 if (-std::numeric_limits<float>::max() > value || value > std::numeric_limit
s<float>::max()) |
144 return fallbackValue; | 138 return fallbackValue; |
145 | 139 |
146 // The following expression converts -0 to +0. | 140 // The following expression converts -0 to +0. |
147 return value ? value : 0; | 141 return value ? value : 0; |
148 } | 142 } |
149 | 143 |
150 double parseToDoubleForNumberType(const String& string) | |
151 { | |
152 return parseToDoubleForNumberType(string, std::numeric_limits<double>::quiet
_NaN()); | |
153 } | |
154 | |
155 template <typename CharacterType> | 144 template <typename CharacterType> |
156 static bool parseHTMLIntegerInternal(const CharacterType* position, const Charac
terType* end, int& value) | 145 static bool parseHTMLIntegerInternal(const CharacterType* position, const Charac
terType* end, int& value) |
157 { | 146 { |
158 // Step 3 | 147 // Step 3 |
159 int sign = 1; | 148 int sign = 1; |
160 | 149 |
161 // Step 4 | 150 // Step 4 |
162 while (position < end) { | 151 while (position < end) { |
163 if (!isHTMLSpace<CharacterType>(*position)) | 152 if (!isHTMLSpace<CharacterType>(*position)) |
164 break; | 153 break; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 { | 279 { |
291 return threadSafeEqual(a.localName().impl(), b.localName().impl()); | 280 return threadSafeEqual(a.localName().impl(), b.localName().impl()); |
292 } | 281 } |
293 | 282 |
294 bool threadSafeMatch(const HTMLIdentifier& localName, const QualifiedName& qName
) | 283 bool threadSafeMatch(const HTMLIdentifier& localName, const QualifiedName& qName
) |
295 { | 284 { |
296 return threadSafeEqual(localName.asStringImpl(), qName.localName().impl()); | 285 return threadSafeEqual(localName.asStringImpl(), qName.localName().impl()); |
297 } | 286 } |
298 | 287 |
299 } | 288 } |
OLD | NEW |