Commit e7550a36 by Jacob Vosmaer

Use bufio.Scanner

parent e2a70231
......@@ -9,26 +9,15 @@ import (
)
func main() {
r := bufio.NewReader(os.Stdin)
s := bufio.NewScanner(os.Stdin)
w := bufio.NewWriter(os.Stdout)
var errR error
for errR == nil {
var p []byte
p, errR = r.ReadBytes('\n')
if len(p) == 0 {
break
}
mustWrite(w, bytes.TrimPrefix(p, []byte(" ")))
}
if errW := w.Flush(); errW != nil {
log.Fatal(errW)
for s.Scan() {
mustWrite(w, bytes.TrimPrefix(s.Bytes(), []byte(" ")))
}
if errR != io.EOF {
log.Fatal(errR)
}
must(w.Flush())
must(s.Err())
}
func mustWrite(w io.Writer, p []byte) {
......@@ -36,3 +25,9 @@ func mustWrite(w io.Writer, p []byte) {
log.Fatal(err)
}
}
func must(err error) {
if err != nil {
log.Fatal(err)
}
}
......@@ -8,27 +8,15 @@ import (
)
func main() {
r := bufio.NewReader(os.Stdin)
s := bufio.NewScanner(os.Stdin)
w := bufio.NewWriter(os.Stdout)
var errR error
for errR == nil {
var p []byte
p, errR = r.ReadBytes('\n')
if len(p) == 0 {
break
}
for s.Scan() {
mustWrite(w, []byte(" "))
mustWrite(w, p)
}
if errW := w.Flush(); errW != nil {
log.Fatal(errW)
}
if errR != io.EOF {
log.Fatal(errR)
mustWrite(w, s.Bytes())
}
must(w.Flush())
must(s.Err())
}
func mustWrite(w io.Writer, p []byte) {
......@@ -36,3 +24,9 @@ func mustWrite(w io.Writer, p []byte) {
log.Fatal(err)
}
}
func must(err error) {
if err != nil {
log.Fatal(err)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment