Do not trim CR on Windows when --read0 is set

This commit is contained in:
Junegunn Choi 2024-04-04 23:39:29 +09:00
parent 9b9ad77e1c
commit 68a35e4735
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -127,8 +127,10 @@ func (r *Reader) feed(src io.Reader) {
*/
delim := byte('\n')
trimCR := util.IsWindows()
if r.delimNil {
delim = '\000'
trimCR = false
}
slab := make([]byte, readerSlabSize)
@ -157,7 +159,7 @@ func (r *Reader) feed(src io.Reader) {
// Found the delimiter
slice := buf[:i+1]
buf = buf[i+1:]
if util.IsWindows() && len(slice) >= 2 && slice[len(slice)-2] == byte('\r') {
if trimCR && len(slice) >= 2 && slice[len(slice)-2] == byte('\r') {
slice = slice[:len(slice)-2]
} else {
slice = slice[:len(slice)-1]