MCPcopy Create free account
hub / github.com/go-git/go-git / countLines

Function countLines

common.go:9–20  ·  view source on GitHub ↗

countLines returns the number of lines in a string à la git, this is The newline character is assumed to be '\n'. The empty string contains 0 lines. If the last line of the string doesn't end with a newline, it will still be considered a line.

(s string)

Source from the content-addressed store, hash-verified

7// contains 0 lines. If the last line of the string doesn't end with a
8// newline, it will still be considered a line.
9func countLines(s string) int {
10 if s == "" {
11 return 0
12 }
13
14 nEOL := strings.Count(s, "\n")
15 if strings.HasSuffix(s, "\n") {
16 return nEOL
17 }
18
19 return nEOL + 1
20}

Callers 2

TestCountLinesMethod · 0.85
addBlamesMethod · 0.85

Calls 1

CountMethod · 0.65

Tested by 1

TestCountLinesMethod · 0.68