remove whitespace
This commit is contained in:
parent
46856df495
commit
38960cfc90
@ -7,50 +7,50 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// Package `bufio` will help us read line-by-line.
|
// Package `bufio` will help us read line-by-line.
|
||||||
import "bufio"
|
import "bufio"
|
||||||
import "bytes"
|
import "bytes"
|
||||||
import "os"
|
import "os"
|
||||||
import "io"
|
import "io"
|
||||||
|
|
||||||
// We'll need to add our own newlines between
|
// We'll need to add our own newlines between
|
||||||
// processed lines.
|
// processed lines.
|
||||||
func main() {
|
func main() {
|
||||||
newline := []byte("\n")
|
newline := []byte("\n")
|
||||||
|
|
||||||
// The buffered reader gives us `ReadLine`.
|
// The buffered reader gives us `ReadLine`.
|
||||||
in := bufio.NewReader(os.Stdin)
|
in := bufio.NewReader(os.Stdin)
|
||||||
out := os.Stdout
|
out := os.Stdout
|
||||||
|
|
||||||
// If successful, each `ReadLine` returns bytes and a
|
// If successful, each `ReadLine` returns bytes and a
|
||||||
// boolean indicating if don't have the whole line yet.
|
// boolean indicating if don't have the whole line yet.
|
||||||
for {
|
for {
|
||||||
inBytes, pfx, err := in.ReadLine()
|
inBytes, pfx, err := in.ReadLine()
|
||||||
|
|
||||||
// The `EOF` error is expected when we reach the end
|
// The `EOF` error is expected when we reach the end
|
||||||
// of the input, so exit gracefully in that case.
|
// of the input, so exit gracefully in that case.
|
||||||
// Otherwise there is a problem.
|
// Otherwise there is a problem.
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic (err)
|
panic (err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// `bytes.ToUpper` works directly on bytes, so we don't
|
// `bytes.ToUpper` works directly on bytes, so we don't
|
||||||
// need to convert to a string for `strings.ToUpper`.
|
// need to convert to a string for `strings.ToUpper`.
|
||||||
outBytes := bytes.ToUpper(inBytes)
|
outBytes := bytes.ToUpper(inBytes)
|
||||||
|
|
||||||
// Write out the upercased bytes, checking for an error
|
// Write out the upercased bytes, checking for an error
|
||||||
// here as well.
|
// here as well.
|
||||||
_, err = out.Write(outBytes)
|
_, err = out.Write(outBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unless this read was for a prefix (not the full
|
// Unless this read was for a prefix (not the full
|
||||||
// line), we need to add our own newline.
|
// line), we need to add our own newline.
|
||||||
if !pfx {
|
if !pfx {
|
||||||
out.Write(newline)
|
out.Write(newline)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user