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

Method diffLinesToStringsMunge

diffmatchpatch/diff.go:1354–1380  ·  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, lineCount int)

Source from the content-addressed store, hash-verified

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 {
1355 lineStart := 0
1356 lineEnd := -1
1357 strs := make([]index, 0, lineCount)
1358
1359 for lineEnd < len(text)-1 {
1360 lineEnd = indexOf(text, "\n", lineStart)
1361
1362 if lineEnd == -1 {
1363 lineEnd = len(text) - 1
1364 }
1365
1366 line := text[lineStart : lineEnd+1]
1367 lineStart = lineEnd + 1
1368 lineValue, ok := lineHash[line]
1369
1370 if ok {
1371 strs = append(strs, index(lineValue))
1372 } else {
1373 *lineArray = append(*lineArray, line)
1374 lineHash[line] = len(*lineArray) - 1
1375 strs = append(strs, index(len(*lineArray)-1))
1376 }
1377 }
1378
1379 return strs
1380}

Callers 1

diffLinesToStringsMethod · 0.95

Calls 2

indexOfFunction · 0.85
indexTypeAlias · 0.85

Tested by

no test coverage detected