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

Function BytesToLineStrings

texteditor/text/util.go:18–32  ·  view source on GitHub ↗

BytesToLineStrings returns []string lines from []byte input. If addNewLn is true, each string line has a \n appended at end.

(txt []byte, addNewLn bool)

Source from the content-addressed store, hash-verified

16// BytesToLineStrings returns []string lines from []byte input.
17// If addNewLn is true, each string line has a \n appended at end.
18func BytesToLineStrings(txt []byte, addNewLn bool) []string {
19 lns := bytes.Split(txt, []byte("\n"))
20 nl := len(lns)
21 if nl == 0 {
22 return nil
23 }
24 str := make([]string, nl)
25 for i, l := range lns {
26 str[i] = string(l)
27 if addNewLn {
28 str[i] += "\n"
29 }
30 }
31 return str
32}
33
34// StringLinesToByteLines returns [][]byte lines from []string lines
35func StringLinesToByteLines(str []string) [][]byte {

Callers 1

DiffEditorDialogFromRevsFunction · 0.92

Calls 1

SplitMethod · 0.80

Tested by

no test coverage detected