OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 leading_zero = true; | 288 leading_zero = true; |
289 ++current; | 289 ++current; |
290 if (current == end) return 0; | 290 if (current == end) return 0; |
291 } | 291 } |
292 | 292 |
293 int begin_pos = buffer_pos; | 293 int begin_pos = buffer_pos; |
294 while ((*current >= '0' && *current <= '9') | 294 while ((*current >= '0' && *current <= '9') |
295 || (*current >= 'a' && *current <= 'f') | 295 || (*current >= 'a' && *current <= 'f') |
296 || (*current >= 'A' && *current <= 'F')) { | 296 || (*current >= 'A' && *current <= 'F')) { |
297 if (significant_digits <= max_significant_digits) { | 297 if (significant_digits <= max_significant_digits) { |
298 buffer[buffer_pos++] = *current; | 298 buffer[buffer_pos++] = static_cast<char>(*current); |
299 significant_digits++; | 299 significant_digits++; |
300 } else { | 300 } else { |
301 insignificant_digits++; | 301 insignificant_digits++; |
302 nonzero_digit_dropped = nonzero_digit_dropped || *current != '0'; | 302 nonzero_digit_dropped = nonzero_digit_dropped || *current != '0'; |
303 } | 303 } |
304 ++current; | 304 ++current; |
305 if (current == end) break; | 305 if (current == end) break; |
306 } | 306 } |
307 | 307 |
308 if (!allow_trailing_junk && AdvanceToNonspace(¤t, end)) { | 308 if (!allow_trailing_junk && AdvanceToNonspace(¤t, end)) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 if (current == end) return signed_zero; | 418 if (current == end) return signed_zero; |
419 } | 419 } |
420 } | 420 } |
421 | 421 |
422 bool octal = leading_zero && (flags & ALLOW_OCTALS) != 0; | 422 bool octal = leading_zero && (flags & ALLOW_OCTALS) != 0; |
423 | 423 |
424 // Copy significant digits of the integer part (if any) to the buffer. | 424 // Copy significant digits of the integer part (if any) to the buffer. |
425 while (*current >= '0' && *current <= '9') { | 425 while (*current >= '0' && *current <= '9') { |
426 if (significant_digits < max_significant_digits) { | 426 if (significant_digits < max_significant_digits) { |
427 ASSERT(buffer_pos < buffer_size); | 427 ASSERT(buffer_pos < buffer_size); |
428 buffer[buffer_pos++] = *current; | 428 buffer[buffer_pos++] = static_cast<char>(*current); |
429 significant_digits++; | 429 significant_digits++; |
430 // Will later check if it's an octal in the buffer. | 430 // Will later check if it's an octal in the buffer. |
431 } else { | 431 } else { |
432 insignificant_digits++; // Move the digit into the exponential part. | 432 insignificant_digits++; // Move the digit into the exponential part. |
433 nonzero_digit_dropped = nonzero_digit_dropped || *current != '0'; | 433 nonzero_digit_dropped = nonzero_digit_dropped || *current != '0'; |
434 } | 434 } |
435 octal = octal && *current < '8'; | 435 octal = octal && *current < '8'; |
436 ++current; | 436 ++current; |
437 if (current == end) goto parsing_done; | 437 if (current == end) goto parsing_done; |
438 } | 438 } |
439 | 439 |
440 if (*current == '.') { | 440 if (*current == '.') { |
441 ASSERT(buffer_pos < buffer_size); | 441 ASSERT(buffer_pos < buffer_size); |
442 buffer[buffer_pos++] = '.'; | |
443 ++current; | 442 ++current; |
444 if (current == end) { | 443 if (current == end) { |
445 if (significant_digits == 0 && !leading_zero) { | 444 if (significant_digits == 0 && !leading_zero) { |
446 return JUNK_STRING_VALUE; | 445 return JUNK_STRING_VALUE; |
447 } else { | 446 } else { |
448 goto parsing_done; | 447 goto parsing_done; |
449 } | 448 } |
450 } | 449 } |
| 450 buffer[buffer_pos++] = '.'; |
451 | 451 |
452 if (significant_digits == 0) { | 452 if (significant_digits == 0) { |
453 octal = false; | 453 octal = false; |
454 // Integer part consists of 0 or is absent. Significant digits start after | 454 // Integer part consists of 0 or is absent. Significant digits start after |
455 // leading zeros (if any). | 455 // leading zeros (if any). |
456 while (*current == '0') { | 456 while (*current == '0') { |
457 ++current; | 457 ++current; |
458 if (current == end) return signed_zero; | 458 if (current == end) return signed_zero; |
459 exponent--; // Move this 0 into the exponent. | 459 exponent--; // Move this 0 into the exponent. |
460 } | 460 } |
461 } | 461 } |
462 | 462 |
463 // There is the fractional part. | 463 // There is the fractional part. |
464 while (*current >= '0' && *current <= '9') { | 464 while (*current >= '0' && *current <= '9') { |
465 if (significant_digits < max_significant_digits) { | 465 if (significant_digits < max_significant_digits) { |
466 ASSERT(buffer_pos < buffer_size); | 466 ASSERT(buffer_pos < buffer_size); |
467 buffer[buffer_pos++] = *current; | 467 buffer[buffer_pos++] = static_cast<char>(*current); |
468 significant_digits++; | 468 significant_digits++; |
469 } else { | 469 } else { |
470 // Ignore insignificant digits in the fractional part. | 470 // Ignore insignificant digits in the fractional part. |
471 nonzero_digit_dropped = nonzero_digit_dropped || *current != '0'; | 471 nonzero_digit_dropped = nonzero_digit_dropped || *current != '0'; |
472 } | 472 } |
473 ++current; | 473 ++current; |
474 if (current == end) goto parsing_done; | 474 if (current == end) goto parsing_done; |
475 } | 475 } |
476 } | 476 } |
477 | 477 |
(...skipping 11 matching lines...) Expand all Loading... |
489 ++current; | 489 ++current; |
490 if (current == end) { | 490 if (current == end) { |
491 if (allow_trailing_junk) { | 491 if (allow_trailing_junk) { |
492 goto parsing_done; | 492 goto parsing_done; |
493 } else { | 493 } else { |
494 return JUNK_STRING_VALUE; | 494 return JUNK_STRING_VALUE; |
495 } | 495 } |
496 } | 496 } |
497 char sign = '+'; | 497 char sign = '+'; |
498 if (*current == '+' || *current == '-') { | 498 if (*current == '+' || *current == '-') { |
499 sign = *current; | 499 sign = static_cast<char>(*current); |
500 ++current; | 500 ++current; |
501 if (current == end) { | 501 if (current == end) { |
502 if (allow_trailing_junk) { | 502 if (allow_trailing_junk) { |
503 goto parsing_done; | 503 goto parsing_done; |
504 } else { | 504 } else { |
505 return JUNK_STRING_VALUE; | 505 return JUNK_STRING_VALUE; |
506 } | 506 } |
507 } | 507 } |
508 } | 508 } |
509 | 509 |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 // Allocate result and fill in the parts. | 972 // Allocate result and fill in the parts. |
973 StringBuilder builder(result_size + 1); | 973 StringBuilder builder(result_size + 1); |
974 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); | 974 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); |
975 if (decimal_pos > 0) builder.AddCharacter('.'); | 975 if (decimal_pos > 0) builder.AddCharacter('.'); |
976 builder.AddSubstring(decimal_buffer, decimal_pos); | 976 builder.AddSubstring(decimal_buffer, decimal_pos); |
977 return builder.Finalize(); | 977 return builder.Finalize(); |
978 } | 978 } |
979 | 979 |
980 | 980 |
981 } } // namespace v8::internal | 981 } } // namespace v8::internal |
OLD | NEW |