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)
| 1700 | // EachKeyErr while traversing array-index paths. |
| 1701 | // SYS-REQ-004 |
| 1702 | func arrayEachErr(data []byte, cb func(value []byte, dataType ValueType, offset int, err error) error, keys ...string) (offset, count int, err error) { |
| 1703 | if len(data) == 0 { |
| 1704 | return -1, 0, MalformedObjectError |
| 1705 | } |
| 1706 | |
| 1707 | nT := nextToken(data) |
| 1708 | if nT == -1 { |
| 1709 | return -1, 0, MalformedJsonError |
| 1710 | } |
| 1711 | |
| 1712 | if len(keys) == 0 && data[nT] != '[' { |
| 1713 | return -1, 0, MalformedArrayError |
| 1714 | } |
| 1715 | |
| 1716 | offset = nT + 1 |
| 1717 | |
| 1718 | if len(keys) > 0 { |
| 1719 | if offset = searchKeys(data, keys...); offset == -1 { |
| 1720 | return offset, 0, KeyPathNotFoundError |
| 1721 | } |
| 1722 | |
| 1723 | nO := nextToken(data[offset:]) |
| 1724 | if nO == -1 { |
| 1725 | return offset, 0, MalformedJsonError |
| 1726 | } |
| 1727 | |
| 1728 | offset += nO |
| 1729 | |
| 1730 | if data[offset] != '[' { |
| 1731 | return offset, 0, MalformedArrayError |
| 1732 | } |
| 1733 | |
| 1734 | offset++ |
| 1735 | } |
| 1736 | |
| 1737 | nO := nextToken(data[offset:]) |
| 1738 | if nO == -1 { |
| 1739 | return offset, 0, MalformedJsonError |
| 1740 | } |
| 1741 | |
| 1742 | offset += nO |
| 1743 | |
| 1744 | if data[offset] == ']' { |
| 1745 | return offset, 0, nil |
| 1746 | } |
| 1747 | |
| 1748 | for { |
| 1749 | v, t, o, parseErr := Get(data[offset:]) |
| 1750 | |
| 1751 | if o == 0 { |
| 1752 | return offset, count, parseErr |
| 1753 | } |
| 1754 | |
| 1755 | count++ |
| 1756 | if callbackErr := cb(v, t, offset+o-len(v), parseErr); callbackErr != nil { |
| 1757 | if errors.Is(callbackErr, io.EOF) { |
| 1758 | return offset, count, nil |
| 1759 | } |
no test coverage detected