...
 
Commits (3)
......@@ -6,10 +6,14 @@ import (
"io"
"log"
"os"
"jacobvosmaer.nl/go/text"
)
func main() {
s := bufio.NewScanner(os.Stdin)
s.Split(text.ScanLinesRaw)
w := bufio.NewWriter(os.Stdout)
for s.Scan() {
......
......@@ -5,10 +5,14 @@ import (
"io"
"log"
"os"
"jacobvosmaer.nl/go/text"
)
func main() {
s := bufio.NewScanner(os.Stdin)
s.Split(text.ScanLinesRaw)
w := bufio.NewWriter(os.Stdout)
for s.Scan() {
......
package text
import (
"bytes"
)
func ScanLinesRaw(data []byte, atEOF bool) (advance int, token []byte, err error) {
if atEOF && len(data) == 0 {
return 0, nil, nil
}
if i := bytes.IndexByte(data, '\n') + 1; i >= 1 {
return i, data[0:i], nil
}
// If we're at EOF, we have a final, non-terminated line. Return it.
if atEOF {
return len(data), data, nil
}
// Request more data.
return 0, nil, nil
}