\r handling

main
Bel LaPointe 2025-02-23 16:57:36 -07:00
parent 7f8ad39656
commit 73e5a4ef41
1 changed files with 13 additions and 1 deletions

14
main.go
View File

@ -1,6 +1,7 @@
package main
import (
"bytes"
"encoding/csv"
"encoding/json"
"fmt"
@ -11,8 +12,19 @@ import (
"strings"
)
type replacer struct {
r io.Reader
}
func (r replacer) Read(b []byte) (int, error) {
n, err := r.r.Read(b)
c := bytes.ReplaceAll(b[:n], []byte("\r"), []byte("\n"))
copy(b, c)
return n, err
}
func main() {
parser := csv.NewReader(os.Stdin)
parser := csv.NewReader(replacer{os.Stdin})
fields, err := parser.Read()
if err != nil {
panic(err)