Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLParserIdioms.cpp

Issue 2363823004: Fix parsing of minimum values (Closed)
Patch Set: Add a comment Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/imported/wpt/html/dom/reflection-text-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 bool valid = false; 154 bool valid = false;
155 double value = string.toDouble(&valid); 155 double value = string.toDouble(&valid);
156 return checkDoubleValue(value, valid, fallbackValue); 156 return checkDoubleValue(value, valid, fallbackValue);
157 } 157 }
158 158
159 template <typename CharacterType> 159 template <typename CharacterType>
160 static bool parseHTMLIntegerInternal(const CharacterType* position, 160 static bool parseHTMLIntegerInternal(const CharacterType* position,
161 const CharacterType* end, 161 const CharacterType* end,
162 int& value) { 162 int& value) {
163 // Step 3 163 // Step 3
164 int sign = 1; 164 // We do not do this step and do not have a local sign
165 // variable since due to a bug in charactersToIntStrict
166 // we have to add the sign to the digits string.
165 167
166 // Step 4 168 // Step 4
167 while (position < end) { 169 while (position < end) {
168 if (!isHTMLSpace<CharacterType>(*position)) 170 if (!isHTMLSpace<CharacterType>(*position))
169 break; 171 break;
170 ++position; 172 ++position;
171 } 173 }
172 174
173 // Step 5 175 // Step 5
174 if (position == end) 176 if (position == end)
175 return false; 177 return false;
176 ASSERT(position < end); 178 ASSERT(position < end);
177 179
178 // Step 6 180 // Step 6
181 StringBuilder digits;
179 if (*position == '-') { 182 if (*position == '-') {
180 sign = -1; 183 digits.append('-');
181 ++position; 184 ++position;
182 } else if (*position == '+') 185 } else if (*position == '+')
183 ++position; 186 ++position;
184 if (position == end) 187 if (position == end)
185 return false; 188 return false;
186 ASSERT(position < end); 189 ASSERT(position < end);
187 190
188 // Step 7 191 // Step 7
189 if (!isASCIIDigit(*position)) 192 if (!isASCIIDigit(*position))
190 return false; 193 return false;
191 194
192 // Step 8 195 // Step 8
193 StringBuilder digits;
194 while (position < end) { 196 while (position < end) {
195 if (!isASCIIDigit(*position)) 197 if (!isASCIIDigit(*position))
196 break; 198 break;
197 digits.append(*position++); 199 digits.append(*position++);
198 } 200 }
199 201
200 // Step 9 202 // Step 9
201 bool ok; 203 bool ok;
202 if (digits.is8Bit()) 204 if (digits.is8Bit())
203 value = sign * 205 value = charactersToIntStrict(digits.characters8(), digits.length(), &ok);
204 charactersToIntStrict(digits.characters8(), digits.length(), &ok);
205 else 206 else
206 value = sign * 207 value = charactersToIntStrict(digits.characters16(), digits.length(), &ok);
207 charactersToIntStrict(digits.characters16(), digits.length(), &ok);
208 return ok; 208 return ok;
209 } 209 }
210 210
211 // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-integers 211 // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-integers
212 bool parseHTMLInteger(const String& input, int& value) { 212 bool parseHTMLInteger(const String& input, int& value) {
213 // Step 1 213 // Step 1
214 // Step 2 214 // Step 2
215 unsigned length = input.length(); 215 unsigned length = input.length();
216 if (!length || input.is8Bit()) { 216 if (!length || input.is8Bit()) {
217 const LChar* start = input.characters8(); 217 const LChar* start = input.characters8();
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 string = StringImpl::create8BitIfPossible(characters, size); 490 string = StringImpl::create8BitIfPossible(characters, size);
491 else if (width == Force8Bit) 491 else if (width == Force8Bit)
492 string = String::make8BitFrom16BitSource(characters, size); 492 string = String::make8BitFrom16BitSource(characters, size);
493 else 493 else
494 string = String(characters, size); 494 string = String(characters, size);
495 495
496 return string; 496 return string;
497 } 497 }
498 498
499 } // namespace blink 499 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/imported/wpt/html/dom/reflection-text-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698