SYS-REQ-009
(keys []string, setValue []byte, comma, object bool)
| 632 | |
| 633 | // SYS-REQ-009 |
| 634 | func createInsertComponent(keys []string, setValue []byte, comma, object bool) []byte { |
| 635 | isIndex := string(keys[0][0]) == "[" |
| 636 | offset := 0 |
| 637 | lk := calcAllocateSpace(keys, setValue, comma, object) |
| 638 | buffer := make([]byte, lk, lk) |
| 639 | if comma { |
| 640 | offset += WriteToBuffer(buffer[offset:], ",") |
| 641 | } |
| 642 | if isIndex && !comma { |
| 643 | offset += WriteToBuffer(buffer[offset:], "[") |
| 644 | } else { |
| 645 | if object { |
| 646 | offset += WriteToBuffer(buffer[offset:], "{") |
| 647 | } |
| 648 | if !isIndex { |
| 649 | offset += WriteToBuffer(buffer[offset:], "\"") |
| 650 | offset += WriteToBuffer(buffer[offset:], keys[0]) |
| 651 | offset += WriteToBuffer(buffer[offset:], "\":") |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | for i := 1; i < len(keys); i++ { |
| 656 | if string(keys[i][0]) == "[" { |
| 657 | offset += WriteToBuffer(buffer[offset:], "[") |
| 658 | } else { |
| 659 | offset += WriteToBuffer(buffer[offset:], "{\"") |
| 660 | offset += WriteToBuffer(buffer[offset:], keys[i]) |
| 661 | offset += WriteToBuffer(buffer[offset:], "\":") |
| 662 | } |
| 663 | } |
| 664 | offset += WriteToBuffer(buffer[offset:], string(setValue)) |
| 665 | for i := len(keys) - 1; i > 0; i-- { |
| 666 | if string(keys[i][0]) == "[" { |
| 667 | offset += WriteToBuffer(buffer[offset:], "]") |
| 668 | } else { |
| 669 | offset += WriteToBuffer(buffer[offset:], "}") |
| 670 | } |
| 671 | } |
| 672 | if isIndex && !comma { |
| 673 | offset += WriteToBuffer(buffer[offset:], "]") |
| 674 | } |
| 675 | if object && !isIndex { |
| 676 | offset += WriteToBuffer(buffer[offset:], "}") |
| 677 | } |
| 678 | return buffer |
| 679 | } |
| 680 | |
| 681 | // SYS-REQ-009 |
| 682 | func calcAllocateSpace(keys []string, setValue []byte, comma, object bool) int { |
no test coverage detected
searching dependent graphs…