arrayEachErr also returns ArrayEach's closing-bracket offset for use by EachKeyErr while traversing array-index paths. SYS-REQ-004
(data []byte, cb func(value []byte, dataType ValueType, offset int, err error) error, keys ...string)
| 1638 | // EachKeyErr while traversing array-index paths. |
| 1639 | // SYS-REQ-004 |
| 1640 | func arrayEachErr(data []byte, cb func(value []byte, dataType ValueType, offset int, err error) error, keys ...string) (offset, count int, err error) { |
| 1641 | if len(data) == 0 { |
| 1642 | return -1, 0, MalformedObjectError |
| 1643 | } |
| 1644 | |
| 1645 | nT := nextToken(data) |
| 1646 | if nT == -1 { |
| 1647 | return -1, 0, MalformedJsonError |
| 1648 | } |
| 1649 | |
| 1650 | if len(keys) == 0 && data[nT] != '[' { |
| 1651 | return -1, 0, MalformedArrayError |
| 1652 | } |
| 1653 | |
| 1654 | offset = nT + 1 |
| 1655 | |
| 1656 | if len(keys) > 0 { |
| 1657 | if offset = searchKeys(data, keys...); offset == -1 { |
| 1658 | return offset, 0, KeyPathNotFoundError |
| 1659 | } |
| 1660 | |
| 1661 | nO := nextToken(data[offset:]) |
| 1662 | if nO == -1 { |
| 1663 | return offset, 0, MalformedJsonError |
| 1664 | } |
| 1665 | |
| 1666 | offset += nO |
| 1667 | |
| 1668 | if data[offset] != '[' { |
| 1669 | return offset, 0, MalformedArrayError |
| 1670 | } |
| 1671 | |
| 1672 | offset++ |
| 1673 | } |
| 1674 | |
| 1675 | nO := nextToken(data[offset:]) |
| 1676 | if nO == -1 { |
| 1677 | return offset, 0, MalformedJsonError |
| 1678 | } |
| 1679 | |
| 1680 | offset += nO |
| 1681 | |
| 1682 | if data[offset] == ']' { |
| 1683 | return offset, 0, nil |
| 1684 | } |
| 1685 | |
| 1686 | for { |
| 1687 | v, t, o, parseErr := Get(data[offset:]) |
| 1688 | |
| 1689 | if o == 0 { |
| 1690 | return offset, count, parseErr |
| 1691 | } |
| 1692 | |
| 1693 | count++ |
| 1694 | if callbackErr := cb(v, t, offset+o-len(v), parseErr); callbackErr != nil { |
| 1695 | if errors.Is(callbackErr, io.EOF) { |
| 1696 | return offset, count, nil |
| 1697 | } |
no test coverage detected