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

Method diffLinesToStringsMunge

diffmatchpatch/diff.go:1334–1360  ·  view source on GitHub ↗

diffLinesToStringsMunge splits a text into an array of strings, and reduces the texts to a []index.

(text string, lineArray *[]string, lineHash map[string]int)

Source from the content-addressed store, hash-verified

1332
1333// diffLinesToStringsMunge splits a text into an array of strings, and reduces the texts to a []index.
1334func (dmp *DiffMatchPatch) diffLinesToStringsMunge(text string, lineArray *[]string, lineHash map[string]int) []index {
1335 lineStart := 0
1336 lineEnd := -1
1337 strs := []index{}
1338
1339 for lineEnd < len(text)-1 {
1340 lineEnd = indexOf(text, "\n", lineStart)
1341
1342 if lineEnd == -1 {
1343 lineEnd = len(text) - 1
1344 }
1345
1346 line := text[lineStart : lineEnd+1]
1347 lineStart = lineEnd + 1
1348 lineValue, ok := lineHash[line]
1349
1350 if ok {
1351 strs = append(strs, index(lineValue))
1352 } else {
1353 *lineArray = append(*lineArray, line)
1354 lineHash[line] = len(*lineArray) - 1
1355 strs = append(strs, index(len(*lineArray)-1))
1356 }
1357 }
1358
1359 return strs
1360}

Callers 1

diffLinesToStringsMethod · 0.95

Calls 2

indexOfFunction · 0.85
indexTypeAlias · 0.85

Tested by

no test coverage detected