|
1 | 1 | note |
2 | 2 | description: "Parse serialized JSON data" |
3 | | - author: "$Author: jfiat $" |
4 | | - date: "$Date: 2014-11-17 11:54:05 +0100 (lun., 17 nov. 2014) $" |
5 | | - revision: "$Revision: 96099 $" |
| 3 | + author: "$Author$" |
| 4 | + date: "$Date$" |
| 5 | + revision: "$Revision$" |
6 | 6 |
|
7 | 7 | class |
8 | 8 | JSON_PARSER |
@@ -509,88 +509,111 @@ feature {NONE} -- Implementation |
509 | 509 | if c = token_minus then |
510 | 510 | s.extend (c) |
511 | 511 | i := i + 1 |
512 | | - c := a_number [i] |
| 512 | + if i > n then |
| 513 | + Result := False |
| 514 | + else |
| 515 | + c := a_number [i] |
| 516 | + end |
513 | 517 | end |
514 | 518 | --| "0|[1-9]\d* |
515 | | - if c.is_digit then |
| 519 | + if Result and c.is_digit then |
516 | 520 | if c = '0' then |
517 | 521 | --| "0" |
518 | 522 | s.extend (c) |
519 | 523 | i := i + 1 |
520 | | - c := a_number [i] |
| 524 | + if i <= n then |
| 525 | + c := a_number [i] |
| 526 | + end |
521 | 527 | else |
522 | 528 | --| "[1-9]" |
523 | 529 | s.extend (c) |
524 | | - i := i + 1 |
525 | | - c := a_number [i] |
| 530 | + |
526 | 531 | --| "\d*" |
527 | | - from |
528 | | - until |
529 | | - i > n or not c.is_digit |
530 | | - loop |
531 | | - s.extend (c) |
532 | | - i := i + 1 |
| 532 | + i := i + 1 |
| 533 | + if i <= n then |
533 | 534 | c := a_number [i] |
| 535 | + from |
| 536 | + until |
| 537 | + i > n or not c.is_digit |
| 538 | + loop |
| 539 | + s.extend (c) |
| 540 | + i := i + 1 |
| 541 | + if i <= n then |
| 542 | + c := a_number [i] |
| 543 | + end |
| 544 | + end |
534 | 545 | end |
535 | 546 | end |
536 | 547 | end |
537 | 548 | end |
538 | | - if Result then |
539 | | - --| "(\.\d+)?" |
540 | | - if c = token_dot then |
541 | | - --| "\.\d+" = "\.\d\d*" |
542 | | - s.extend (c) |
543 | | - i := i + 1 |
544 | | - c := a_number [i] |
545 | | - if c.is_digit then |
546 | | - from |
547 | | - until |
548 | | - i > n or not c.is_digit |
549 | | - loop |
550 | | - s.extend (c) |
551 | | - i := i + 1 |
552 | | - c := a_number [i] |
| 549 | + if i > n then |
| 550 | + -- Exit |
| 551 | + else |
| 552 | + if Result then |
| 553 | + --| "(\.\d+)?" |
| 554 | + if c = token_dot then |
| 555 | + --| "\.\d+" = "\.\d\d*" |
| 556 | + s.extend (c) |
| 557 | + i := i + 1 |
| 558 | + c := a_number [i] |
| 559 | + if c.is_digit then |
| 560 | + from |
| 561 | + until |
| 562 | + i > n or not c.is_digit |
| 563 | + loop |
| 564 | + s.extend (c) |
| 565 | + i := i + 1 |
| 566 | + if i <= n then |
| 567 | + c := a_number [i] |
| 568 | + end |
| 569 | + end |
| 570 | + else |
| 571 | + Result := False --| expecting digit |
553 | 572 | end |
554 | | - else |
555 | | - Result := False --| expecting digit |
556 | 573 | end |
557 | 574 | end |
558 | | - end |
559 | | - if Result then --| "(?:[eE][+-]?\d+)?\b" |
560 | | - if is_exp_token (c) then |
561 | | - --| "[eE][+-]?\d+" |
562 | | - s.extend (c) |
563 | | - i := i + 1 |
564 | | - c := a_number [i] |
565 | | - if c = token_plus or c = token_minus then |
| 575 | + if Result then --| "(?:[eE][+-]?\d+)?\b" |
| 576 | + if is_exp_token (c) then |
| 577 | + --| "[eE][+-]?\d+" |
566 | 578 | s.extend (c) |
567 | 579 | i := i + 1 |
568 | 580 | c := a_number [i] |
569 | | - end |
570 | | - if c.is_digit then |
571 | | - from |
572 | | - until |
573 | | - i > n or not c.is_digit |
574 | | - loop |
| 581 | + if c = token_plus or c = token_minus then |
575 | 582 | s.extend (c) |
576 | 583 | i := i + 1 |
577 | | - c := a_number [i] |
| 584 | + if i <= n then |
| 585 | + c := a_number [i] |
| 586 | + end |
| 587 | + end |
| 588 | + if c.is_digit then |
| 589 | + from |
| 590 | + until |
| 591 | + i > n or not c.is_digit |
| 592 | + loop |
| 593 | + s.extend (c) |
| 594 | + i := i + 1 |
| 595 | + if i <= n then |
| 596 | + c := a_number [i] |
| 597 | + end |
| 598 | + end |
| 599 | + else |
| 600 | + Result := False --| expecting digit |
578 | 601 | end |
579 | | - else |
580 | | - Result := False --| expecting digit |
581 | 602 | end |
582 | 603 | end |
583 | | - end |
584 | | - if Result then --| "\b" |
585 | | - from |
586 | | - until |
587 | | - i > n or not c.is_space |
588 | | - loop |
589 | | - s.extend (c) |
590 | | - i := i + 1 |
591 | | - c := a_number [i] |
| 604 | + if Result then --| "\b" |
| 605 | + from |
| 606 | + until |
| 607 | + i > n or not c.is_space |
| 608 | + loop |
| 609 | + s.extend (c) |
| 610 | + i := i + 1 |
| 611 | + if i <= n then |
| 612 | + c := a_number [i] |
| 613 | + end |
| 614 | + end |
| 615 | + Result := i > n and then s.same_string (a_number) |
592 | 616 | end |
593 | | - Result := i > n and then s.same_string (a_number) |
594 | 617 | end |
595 | 618 | end |
596 | 619 |
|
@@ -651,6 +674,6 @@ feature {NONE} -- Constants |
651 | 674 | null_id: STRING = "null" |
652 | 675 |
|
653 | 676 | note |
654 | | - copyright: "2010-2014, Javier Velilla and others https://github.com/eiffelhub/json." |
| 677 | + copyright: "2010-2015, Javier Velilla and others https://github.com/eiffelhub/json." |
655 | 678 | license: "https://github.com/eiffelhub/json/blob/master/License.txt" |
656 | 679 | end |
0 commit comments