This commit is contained in:
Christopher Ramey 2020-08-12 18:16:15 -08:00
parent e8d45282e8
commit 79329520e2

54
main.go
View File

@ -1,12 +1,12 @@
package main package main
import ( import (
"bufio"
"fmt" "fmt"
"os" "os"
"bufio"
) )
func main(){ func main() {
if len(os.Args) < 2 { if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "filename required\n") fmt.Fprintf(os.Stderr, "filename required\n")
os.Exit(1) os.Exit(1)
@ -38,36 +38,36 @@ func Split(data []byte, atEOF bool) (int, []byte, error) {
for i := 0; i < len(data); i++ { for i := 0; i < len(data); i++ {
c := data[i] c := data[i]
switch c { switch c {
case '\f', '\n', '\r': case '\f', '\n', '\r':
if ignoreline { if ignoreline {
return i + 1, nil, nil return i + 1, nil, nil
} }
fallthrough fallthrough
case ' ', '\t', '\v': case ' ', '\t', '\v':
if started && quote == 0 { if started && quote == 0 {
return i + 1, data[startidx:i], nil return i + 1, data[startidx:i], nil
} }
case '\'', '"', '`': case '\'', '"', '`':
if started && quote == c { if started && quote == c {
return i + 1, data[startidx:i], nil return i + 1, data[startidx:i], nil
} }
if quote == 0 { if quote == 0 {
quote = c quote = c
} }
case '#': case '#':
if !started { if !started {
ignoreline = true ignoreline = true
} }
default: default:
if !ignoreline && !started { if !ignoreline && !started {
started = true started = true
startidx = i startidx = i
} }
} }
} }