// DetectLineEnding detects a dominant line ending in the content.
DetectLineEnding detects a dominant line ending in the content.
// DetectLineEnding detects a dominant line ending in the content .
func DetectLineEnding(content string) (string, error) {
	prev := ' '
	counts := make(map[string]int)
	for _, c := range content {
		if c == '\r' && prev != '\n' {
			counts[cr]++
		} else if c == '\n' {
			if prev == '\r' {
				counts[crlf]++
				counts[cr]--
			} else {
				counts[lf]++
			}
		}
		prev = c
	}
	if counts[crlf]+counts[cr]+counts[lf] == 0 {
		return "", nil
	}
	if counts[crlf] > counts[cr] && counts[crlf] > counts[lf] {
		return crlf, nil
	} else if counts[cr] > counts[lf] && counts[cr] > counts[crlf] {
		return cr, nil
	} else if counts[lf] > counts[cr] && counts[lf] > counts[crlf] {
		return lf, nil
	}
	return "", fmt.Errorf("not found dominant line ending, counts=%v", counts)
}
func DetectLineEnding ( content string ) ( string , error ) { prev := ' ' counts := make ( map [ string ] int ) for _ , c := range content { if c == '\r' && prev != '\n' { counts [ cr ] ++ } else if c == '\n' { if prev == '\r' { counts [ crlf ] ++ counts [ cr ] -- } else { counts [ lf ] ++ } } prev = c } if counts [ crlf ] + counts [ cr ] + counts [ lf ] == 0 { return " " , nil } if counts [ crlf ] > counts [ cr ] && counts [ crlf ] > counts [ lf ] { return crlf , nil } else if counts [ cr ] > counts [ lf ] && counts [ cr ] > counts [ crlf ] { return cr , nil } else if counts [ lf ] > counts [ cr ] && counts [ lf ] > counts [ crlf ] { return lf , nil } return " " , fmt . Errorf ( " " , counts ) }
DetectLineEnding detects a dominant line ending in the content.
DetectLineEnding detects a dominant line ending in the content .