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

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

Issue 2363823004: Fix parsing of minimum values (Closed)
Patch Set: Add tests 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 153
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
tkent 2016/10/06 14:37:42 Adding a comment why the implementation is differe
rwlbuis 2016/10/06 15:10:44 Done.
164 int sign = 1;
165
166 // Step 4 163 // Step 4
167 while (position < end) { 164 while (position < end) {
168 if (!isHTMLSpace<CharacterType>(*position)) 165 if (!isHTMLSpace<CharacterType>(*position))
169 break; 166 break;
170 ++position; 167 ++position;
171 } 168 }
172 169
173 // Step 5 170 // Step 5
174 if (position == end) 171 if (position == end)
175 return false; 172 return false;
176 ASSERT(position < end); 173 ASSERT(position < end);
177 174
178 // Step 6 175 // Step 6
176 StringBuilder digits;
179 if (*position == '-') { 177 if (*position == '-') {
180 sign = -1; 178 digits.append('-');
181 ++position; 179 ++position;
182 } else if (*position == '+') 180 } else if (*position == '+')
183 ++position; 181 ++position;
184 if (position == end) 182 if (position == end)
185 return false; 183 return false;
186 ASSERT(position < end); 184 ASSERT(position < end);
187 185
188 // Step 7 186 // Step 7
189 if (!isASCIIDigit(*position)) 187 if (!isASCIIDigit(*position))
190 return false; 188 return false;
191 189
192 // Step 8 190 // Step 8
193 StringBuilder digits;
194 while (position < end) { 191 while (position < end) {
195 if (!isASCIIDigit(*position)) 192 if (!isASCIIDigit(*position))
196 break; 193 break;
197 digits.append(*position++); 194 digits.append(*position++);
198 } 195 }
199 196
200 // Step 9 197 // Step 9
201 bool ok; 198 bool ok;
202 if (digits.is8Bit()) 199 if (digits.is8Bit())
203 value = sign * 200 value = charactersToIntStrict(digits.characters8(), digits.length(), &ok);
204 charactersToIntStrict(digits.characters8(), digits.length(), &ok);
205 else 201 else
206 value = sign * 202 value = charactersToIntStrict(digits.characters16(), digits.length(), &ok);
207 charactersToIntStrict(digits.characters16(), digits.length(), &ok);
208 return ok; 203 return ok;
209 } 204 }
210 205
211 // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-integers 206 // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-integers
212 bool parseHTMLInteger(const String& input, int& value) { 207 bool parseHTMLInteger(const String& input, int& value) {
213 // Step 1 208 // Step 1
214 // Step 2 209 // Step 2
215 unsigned length = input.length(); 210 unsigned length = input.length();
216 if (!length || input.is8Bit()) { 211 if (!length || input.is8Bit()) {
217 const LChar* start = input.characters8(); 212 const LChar* start = input.characters8();
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 string = StringImpl::create8BitIfPossible(characters, size); 485 string = StringImpl::create8BitIfPossible(characters, size);
491 else if (width == Force8Bit) 486 else if (width == Force8Bit)
492 string = String::make8BitFrom16BitSource(characters, size); 487 string = String::make8BitFrom16BitSource(characters, size);
493 else 488 else
494 string = String(characters, size); 489 string = String(characters, size);
495 490
496 return string; 491 return string;
497 } 492 }
498 493
499 } // namespace blink 494 } // 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