parseNth parses the argument for :nth-child (normally of the form an+b).
()
| 584 | |
| 585 | // parseNth parses the argument for :nth-child (normally of the form an+b). |
| 586 | func (p *parser) parseNth() (a, b int, err error) { |
| 587 | // initial state |
| 588 | if p.i >= len(p.s) { |
| 589 | goto eof |
| 590 | } |
| 591 | switch p.s[p.i] { |
| 592 | case '-': |
| 593 | p.i++ |
| 594 | goto negativeA |
| 595 | case '+': |
| 596 | p.i++ |
| 597 | goto positiveA |
| 598 | case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': |
| 599 | goto positiveA |
| 600 | case 'n', 'N': |
| 601 | a = 1 |
| 602 | p.i++ |
| 603 | goto readN |
| 604 | case 'o', 'O', 'e', 'E': |
| 605 | id, nameErr := p.parseName() |
| 606 | if nameErr != nil { |
| 607 | return 0, 0, nameErr |
| 608 | } |
| 609 | id = toLowerASCII(id) |
| 610 | if id == "odd" { |
| 611 | return 2, 1, nil |
| 612 | } |
| 613 | if id == "even" { |
| 614 | return 2, 0, nil |
| 615 | } |
| 616 | return 0, 0, fmt.Errorf("expected 'odd' or 'even', but found '%s' instead", id) |
| 617 | default: |
| 618 | goto invalid |
| 619 | } |
| 620 | |
| 621 | positiveA: |
| 622 | if p.i >= len(p.s) { |
| 623 | goto eof |
| 624 | } |
| 625 | switch p.s[p.i] { |
| 626 | case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': |
| 627 | a, err = p.parseInteger() |
| 628 | if err != nil { |
| 629 | return 0, 0, err |
| 630 | } |
| 631 | goto readA |
| 632 | case 'n', 'N': |
| 633 | a = 1 |
| 634 | p.i++ |
| 635 | goto readN |
| 636 | default: |
| 637 | goto invalid |
| 638 | } |
| 639 | |
| 640 | negativeA: |
| 641 | if p.i >= len(p.s) { |
| 642 | goto eof |
| 643 | } |
no test coverage detected