parseNth parses the argument for :nth-child (normally of the form an+b).
()
| 631 | |
| 632 | // parseNth parses the argument for :nth-child (normally of the form an+b). |
| 633 | func (p *parser) parseNth() (a, b int, err error) { |
| 634 | // initial state |
| 635 | if p.i >= len(p.s) { |
| 636 | goto eof |
| 637 | } |
| 638 | switch p.s[p.i] { |
| 639 | case '-': |
| 640 | p.i++ |
| 641 | goto negativeA |
| 642 | case '+': |
| 643 | p.i++ |
| 644 | goto positiveA |
| 645 | case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': |
| 646 | goto positiveA |
| 647 | case 'n', 'N': |
| 648 | a = 1 |
| 649 | p.i++ |
| 650 | goto readN |
| 651 | case 'o', 'O', 'e', 'E': |
| 652 | id, nameErr := p.parseName() |
| 653 | if nameErr != nil { |
| 654 | return 0, 0, nameErr |
| 655 | } |
| 656 | id = toLowerASCII(id) |
| 657 | if id == "odd" { |
| 658 | return 2, 1, nil |
| 659 | } |
| 660 | if id == "even" { |
| 661 | return 2, 0, nil |
| 662 | } |
| 663 | return 0, 0, fmt.Errorf("expected 'odd' or 'even', but found '%s' instead", id) |
| 664 | default: |
| 665 | goto invalid |
| 666 | } |
| 667 | |
| 668 | positiveA: |
| 669 | if p.i >= len(p.s) { |
| 670 | goto eof |
| 671 | } |
| 672 | switch p.s[p.i] { |
| 673 | case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': |
| 674 | a, err = p.parseInteger() |
| 675 | if err != nil { |
| 676 | return 0, 0, err |
| 677 | } |
| 678 | goto readA |
| 679 | case 'n', 'N': |
| 680 | a = 1 |
| 681 | p.i++ |
| 682 | goto readN |
| 683 | default: |
| 684 | goto invalid |
| 685 | } |
| 686 | |
| 687 | negativeA: |
| 688 | if p.i >= len(p.s) { |
| 689 | goto eof |
| 690 | } |
no test coverage detected