MCPcopy Create free account
hub / github.com/sergi/go-diff / diffLinesToStrings

Method diffLinesToStrings

diffmatchpatch/diff.go:1339–1351  ·  view source on GitHub ↗

diffLinesToStrings splits two texts into a list of strings. Each string represents one line.

(text1, text2 string)

Source from the content-addressed store, hash-verified

1337
1338// diffLinesToStrings splits two texts into a list of strings. Each string represents one line.
1339func (dmp *DiffMatchPatch) diffLinesToStrings(text1, text2 string) (string, string, []string) {
1340 n1 := strings.Count(text1, "\n") + 1
1341 n2 := strings.Count(text2, "\n") + 1
1342
1343 lineArray := make([]string, 1, n1+n2+1) // e.g. lineArray[4] == 'Hello\n'
1344
1345 lineHash := make(map[string]int, n1+n2)
1346 //Each string has the index of lineArray which it points to
1347 strIndexArray1 := dmp.diffLinesToStringsMunge(text1, &lineArray, lineHash, n1)
1348 strIndexArray2 := dmp.diffLinesToStringsMunge(text2, &lineArray, lineHash, n2)
1349
1350 return intArrayToString(strIndexArray1), intArrayToString(strIndexArray2), lineArray
1351}
1352
1353// diffLinesToStringsMunge splits a text into an array of strings, and reduces the texts to a []index.
1354func (dmp *DiffMatchPatch) diffLinesToStringsMunge(text string, lineArray *[]string, lineHash map[string]int, lineCount int) []index {

Callers 2

DiffLinesToCharsMethod · 0.95
DiffLinesToRunesMethod · 0.95

Calls 2

intArrayToStringFunction · 0.85

Tested by

no test coverage detected