Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/css/parser/CSSTokenizer.h" | 6 #include "core/css/parser/CSSTokenizer.h" |
| 7 | 7 |
| 8 namespace blink { | 8 namespace blink { |
| 9 #include "core/CSSTokenizerCodepoints.cpp" | 9 #include "core/CSSTokenizerCodepoints.cpp" |
| 10 } | 10 } |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 } | 268 } |
| 269 | 269 |
| 270 static unsigned long long getInteger(CSSTokenizerInputStream& input, unsigned& o ffset) | 270 static unsigned long long getInteger(CSSTokenizerInputStream& input, unsigned& o ffset) |
| 271 { | 271 { |
| 272 unsigned intStartPos = offset; | 272 unsigned intStartPos = offset; |
| 273 offset = input.skipWhilePredicate<isASCIIDigit>(offset); | 273 offset = input.skipWhilePredicate<isASCIIDigit>(offset); |
| 274 unsigned intEndPos = offset; | 274 unsigned intEndPos = offset; |
| 275 return input.getUInt(intStartPos, intEndPos); | 275 return input.getUInt(intStartPos, intEndPos); |
| 276 } | 276 } |
| 277 | 277 |
| 278 static double getFraction(CSSTokenizerInputStream& input, unsigned& offset, unsi gned& digitsNumber) | 278 static double getFraction(CSSTokenizerInputStream& input, unsigned& offset) |
| 279 { | 279 { |
| 280 unsigned fractionStartPos = 0; | 280 if (input.peek(offset) != '.' || !isASCIIDigit(input.peek(offset + 1))) |
| 281 unsigned fractionEndPos = 0; | 281 return 0; |
| 282 if (input.peek(offset) == '.' && isASCIIDigit(input.peek(++offset))) { | 282 unsigned startOffset = offset; |
| 283 fractionStartPos = offset - 1; | 283 offset = input.skipWhilePredicate<isASCIIDigit>(offset + 1); |
| 284 offset = input.skipWhilePredicate<isASCIIDigit>(offset); | 284 return input.getDouble(startOffset, offset); |
| 285 fractionEndPos = offset; | |
| 286 } | |
| 287 digitsNumber = fractionEndPos- fractionStartPos; | |
| 288 return input.getDouble(fractionStartPos, fractionEndPos); | |
| 289 } | 285 } |
|
Yoav Weiss
2014/10/20 07:06:45
So beyond the refactoring (which I like), and the
Timothy Loh
2014/10/20 07:18:24
There's a change here which is to only consume the
Yoav Weiss
2014/10/20 07:26:14
Oh, right. So the move from 'isASCIIDigit(input.pe
| |
| 290 | 286 |
| 291 static unsigned long long getExponent(CSSTokenizerInputStream& input, unsigned& offset, int& sign) | 287 static unsigned long long getExponent(CSSTokenizerInputStream& input, unsigned& offset, int& sign) |
| 292 { | 288 { |
| 293 unsigned exponentStartPos = 0; | 289 unsigned exponentStartPos = 0; |
| 294 unsigned exponentEndPos = 0; | 290 unsigned exponentEndPos = 0; |
| 295 if ((input.peek(offset) == 'E' || input.peek(offset) == 'e')) { | 291 if ((input.peek(offset) == 'E' || input.peek(offset) == 'e')) { |
| 296 int offsetBeforeExponent = offset; | 292 int offsetBeforeExponent = offset; |
| 297 ++offset; | 293 ++offset; |
| 298 if (input.peek(offset) == '+') { | 294 if (input.peek(offset) == '+') { |
| 299 ++offset; | 295 ++offset; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 313 // This method merges the following spec sections for efficiency | 309 // This method merges the following spec sections for efficiency |
| 314 // http://www.w3.org/TR/css3-syntax/#consume-a-number | 310 // http://www.w3.org/TR/css3-syntax/#consume-a-number |
| 315 // http://www.w3.org/TR/css3-syntax/#convert-a-string-to-a-number | 311 // http://www.w3.org/TR/css3-syntax/#convert-a-string-to-a-number |
| 316 CSSParserToken CSSTokenizer::consumeNumber() | 312 CSSParserToken CSSTokenizer::consumeNumber() |
| 317 { | 313 { |
| 318 ASSERT(nextCharsAreNumber()); | 314 ASSERT(nextCharsAreNumber()); |
| 319 NumericValueType type = IntegerValueType; | 315 NumericValueType type = IntegerValueType; |
| 320 double value = 0; | 316 double value = 0; |
| 321 unsigned offset = 0; | 317 unsigned offset = 0; |
| 322 int exponentSign = 1; | 318 int exponentSign = 1; |
| 323 unsigned fractionDigits; | |
| 324 int sign = getSign(m_input, offset); | 319 int sign = getSign(m_input, offset); |
| 325 unsigned long long integerPart = getInteger(m_input, offset); | 320 unsigned long long integerPart = getInteger(m_input, offset); |
| 326 double fractionPart = getFraction(m_input, offset, fractionDigits); | 321 unsigned integerPartEndOffset = offset; |
| 322 | |
| 323 double fractionPart = getFraction(m_input, offset); | |
| 327 unsigned long long exponentPart = getExponent(m_input, offset, exponentSign) ; | 324 unsigned long long exponentPart = getExponent(m_input, offset, exponentSign) ; |
| 328 double exponent = pow(10, (float)exponentSign * (double)exponentPart); | 325 double exponent = pow(10, (float)exponentSign * (double)exponentPart); |
| 329 value = (double)sign * ((double)integerPart + fractionPart) * exponent; | 326 value = (double)sign * ((double)integerPart + fractionPart) * exponent; |
| 330 | 327 |
| 331 m_input.advance(offset); | 328 m_input.advance(offset); |
| 332 if (fractionDigits > 0) | 329 if (offset != integerPartEndOffset) |
|
Yoav Weiss
2014/10/20 07:06:45
This is where the magic happens, and exponents are
Timothy Loh
2014/10/20 07:18:24
Yep
| |
| 333 type = NumberValueType; | 330 type = NumberValueType; |
| 334 | 331 |
| 335 return CSSParserToken(NumberToken, value, type); | 332 return CSSParserToken(NumberToken, value, type); |
| 336 } | 333 } |
| 337 | 334 |
| 338 // http://www.w3.org/TR/css3-syntax/#consume-a-numeric-token | 335 // http://www.w3.org/TR/css3-syntax/#consume-a-numeric-token |
| 339 CSSParserToken CSSTokenizer::consumeNumericToken() | 336 CSSParserToken CSSTokenizer::consumeNumericToken() |
| 340 { | 337 { |
| 341 CSSParserToken token = consumeNumber(); | 338 CSSParserToken token = consumeNumber(); |
| 342 if (nextCharsAreIdentifier()) | 339 if (nextCharsAreIdentifier()) |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 | 515 |
| 519 bool CSSTokenizer::nextCharsAreIdentifier() | 516 bool CSSTokenizer::nextCharsAreIdentifier() |
| 520 { | 517 { |
| 521 UChar first = consume(); | 518 UChar first = consume(); |
| 522 bool areIdentifier = nextCharsAreIdentifier(first); | 519 bool areIdentifier = nextCharsAreIdentifier(first); |
| 523 reconsume(first); | 520 reconsume(first); |
| 524 return areIdentifier; | 521 return areIdentifier; |
| 525 } | 522 } |
| 526 | 523 |
| 527 } // namespace blink | 524 } // namespace blink |
| OLD | NEW |