\r handling
This commit is contained in:
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)
|
||||
|
||||
Reference in New Issue
Block a user