\r handling
parent
7f8ad39656
commit
73e5a4ef41
14
main.go
14
main.go
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -11,8 +12,19 @@ import (
|
||||||
"strings"
|
"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() {
|
func main() {
|
||||||
parser := csv.NewReader(os.Stdin)
|
parser := csv.NewReader(replacer{os.Stdin})
|
||||||
fields, err := parser.Read()
|
fields, err := parser.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue