\r handling
parent
7f8ad39656
commit
73e5a4ef41
14
main.go
14
main.go
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue