MCPcopy Create free account
hub / github.com/cogentcore/core / QFormat

Method QFormat

texteditor/difflib/bytes/bytes.go:816–849  ·  view source on GitHub ↗
(aline []byte, bline []byte, atags []byte, btags []byte)

Source from the content-addressed store, hash-verified

814}
815
816func (d *Differ) QFormat(aline []byte, bline []byte, atags []byte, btags []byte) (out [][]byte) {
817 // Format "?" output and deal with leading tabs.
818
819 // Can hurt, but will probably help most of the time.
820 common := min(count_leading(aline, '\t'), count_leading(bline, '\t'))
821 common = min(common, count_leading(atags[:common], ' '))
822 common = min(common, count_leading(btags[:common], ' '))
823 atags = bytes.TrimRightFunc(atags[common:], unicode.IsSpace)
824 btags = bytes.TrimRightFunc(btags[common:], unicode.IsSpace)
825
826 out = [][]byte{append([]byte("- "), aline...)}
827 if len(atags) > 0 {
828 t := make([]byte, 0, len(atags)+common+3)
829 t = append(t, []byte("? ")...)
830 for i := 0; i < common; i++ {
831 t = append(t, byte('\t'))
832 }
833 t = append(t, atags...)
834 t = append(t, byte('\n'))
835 out = append(out, t)
836 }
837 out = append(out, append([]byte("+ "), bline...))
838 if len(btags) > 0 {
839 t := make([]byte, 0, len(btags)+common+3)
840 t = append(t, []byte("? ")...)
841 for i := 0; i < common; i++ {
842 t = append(t, byte('\t'))
843 }
844 t = append(t, btags...)
845 t = append(t, byte('\n'))
846 out = append(out, t)
847 }
848 return out
849}
850
851// Convert range to the "ed" format
852func formatRangeUnified(start, stop int) []byte {

Callers 2

TestDifferQFormatFunction · 0.95
FancyReplaceMethod · 0.95

Calls 1

count_leadingFunction · 0.70

Tested by 1

TestDifferQFormatFunction · 0.76