prettyPrintInvertedIndexKey returns a string representation of the path part of a JSON inverted index.
(b []byte)
| 633 | // prettyPrintInvertedIndexKey returns a string representation of the path part of a JSON inverted |
| 634 | // index. |
| 635 | func prettyPrintInvertedIndexKey(b []byte) (string, []byte, error) { |
| 636 | outBytes := "" |
| 637 | // We're skipping the first byte because it's the JSON tag. |
| 638 | tempB := b[1:] |
| 639 | for { |
| 640 | i := bytes.IndexByte(tempB, escape) |
| 641 | |
| 642 | if i == -1 { |
| 643 | return "", nil, errors.Errorf("did not find terminator %#x in buffer %#x", escape, b) |
| 644 | } |
| 645 | if i+1 >= len(tempB) { |
| 646 | return "", nil, errors.Errorf("malformed escape in buffer %#x", b) |
| 647 | } |
| 648 | |
| 649 | switch tempB[i+1] { |
| 650 | case escapedTerm: |
| 651 | if len(tempB[:i]) > 0 { |
| 652 | outBytes = outBytes + strconv.Quote(unsafeString(tempB[:i])) |
| 653 | } else { |
| 654 | lenOut := len(outBytes) |
| 655 | if lenOut > 1 && outBytes[lenOut-1] == '/' { |
| 656 | outBytes = outBytes[:lenOut-1] |
| 657 | } |
| 658 | } |
| 659 | return outBytes, tempB[i+escapeLength:], nil |
| 660 | case escapedJSONObjectKeyTerm: |
| 661 | outBytes = outBytes + strconv.Quote(unsafeString(tempB[:i])) + "/" |
| 662 | case escapedJSONArray: |
| 663 | outBytes = outBytes + "Arr/" |
| 664 | default: |
| 665 | return "", nil, errors.Errorf("malformed escape in buffer %#x", b) |
| 666 | |
| 667 | } |
| 668 | |
| 669 | tempB = tempB[i+escapeLength:] |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | // UnsafeConvertStringToBytes converts a string to a byte array to be used with |
| 674 | // string encoding functions. Note that the output byte array should not be |
no test coverage detected
searching dependent graphs…