// CanFormatDiffSlice reports whether we support custom formatting for nodes // that are slices of primitive kinds or strings. func (opts formatOptions) CanFormatDiffSlice(v *valueNode) bool { … } // FormatDiffSlice prints a diff for the slices (or strings) represented by v. // This provides custom-tailored logic to make printing of differences in // textual strings and slices of primitive kinds more readable. func (opts formatOptions) FormatDiffSlice(v *valueNode) textNode { … } // formatASCII formats s as an ASCII string. // This is useful for printing binary strings in a semi-legible way. func formatASCII(s string) string { … } func (opts formatOptions) formatDiffSlice( vx, vy reflect.Value, chunkSize int, name string, makeRec func(reflect.Value, diffMode) textRecord, ) (list textList) { … } // coalesceAdjacentEdits coalesces the list of edits into groups of adjacent // equal or unequal counts. // // Example: // // Input: "..XXY...Y" // Output: [ // {NumIdentical: 2}, // {NumRemoved: 2, NumInserted 1}, // {NumIdentical: 3}, // {NumInserted: 1}, // ] func coalesceAdjacentEdits(name string, es diff.EditScript) (groups []diffStats) { … } // coalesceInterveningIdentical coalesces sufficiently short (<= windowSize) // equal groups into adjacent unequal groups that currently result in a // dual inserted/removed printout. This acts as a high-pass filter to smooth // out high-frequency changes within the windowSize. // // Example: // // WindowSize: 16, // Input: [ // {NumIdentical: 61}, // group 0 // {NumRemoved: 3, NumInserted: 1}, // group 1 // {NumIdentical: 6}, // ├── coalesce // {NumInserted: 2}, // ├── coalesce // {NumIdentical: 1}, // ├── coalesce // {NumRemoved: 9}, // └── coalesce // {NumIdentical: 64}, // group 2 // {NumRemoved: 3, NumInserted: 1}, // group 3 // {NumIdentical: 6}, // ├── coalesce // {NumInserted: 2}, // ├── coalesce // {NumIdentical: 1}, // ├── coalesce // {NumRemoved: 7}, // ├── coalesce // {NumIdentical: 1}, // ├── coalesce // {NumRemoved: 2}, // └── coalesce // {NumIdentical: 63}, // group 4 // ] // Output: [ // {NumIdentical: 61}, // {NumIdentical: 7, NumRemoved: 12, NumInserted: 3}, // {NumIdentical: 64}, // {NumIdentical: 8, NumRemoved: 12, NumInserted: 3}, // {NumIdentical: 63}, // ] func coalesceInterveningIdentical(groups []diffStats, windowSize int) []diffStats { … } // cleanupSurroundingIdentical scans through all unequal groups, and // moves any leading sequence of equal elements to the preceding equal group and // moves and trailing sequence of equal elements to the succeeding equal group. // // This is necessary since coalesceInterveningIdentical may coalesce edit groups // together such that leading/trailing spans of equal elements becomes possible. // Note that this can occur even with an optimal diffing algorithm. // // Example: // // Input: [ // {NumIdentical: 61}, // {NumIdentical: 1 , NumRemoved: 11, NumInserted: 2}, // assume 3 leading identical elements // {NumIdentical: 67}, // {NumIdentical: 7, NumRemoved: 12, NumInserted: 3}, // assume 10 trailing identical elements // {NumIdentical: 54}, // ] // Output: [ // {NumIdentical: 64}, // incremented by 3 // {NumRemoved: 9}, // {NumIdentical: 67}, // {NumRemoved: 9}, // {NumIdentical: 64}, // incremented by 10 // ] func cleanupSurroundingIdentical(groups []diffStats, eq func(i, j int) bool) []diffStats { … }