mirror of
https://gitea.com/gitea/tea.git
synced 2024-12-19 07:35:06 +01:00
d6df0a53b5
Co-authored-by: Norwin Roosen <git@nroo.de> Co-authored-by: Norwin <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/390 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Norwin <noerw@noreply.gitea.io> Co-committed-by: Norwin <noerw@noreply.gitea.io>
21 lines
453 B
Go
21 lines
453 B
Go
package git
|
|
|
|
import "strings"
|
|
|
|
// 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.
|
|
func countLines(s string) int {
|
|
if s == "" {
|
|
return 0
|
|
}
|
|
|
|
nEOL := strings.Count(s, "\n")
|
|
if strings.HasSuffix(s, "\n") {
|
|
return nEOL
|
|
}
|
|
|
|
return nEOL + 1
|
|
}
|