28 lines
469 B
Go
28 lines
469 B
Go
package aocutils
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
)
|
|
|
|
func SplitComma(data []byte, atEOF bool) (advance int, token []byte, err error) {
|
|
if atEOF && len(data) == 0 {
|
|
return 0, nil, nil
|
|
}
|
|
if i := bytes.IndexByte(data, ','); i >= 0 {
|
|
return i + 1, data[0:i], nil
|
|
}
|
|
if atEOF {
|
|
return len(data), data, nil
|
|
}
|
|
return 0, nil, nil
|
|
}
|
|
|
|
func ReadString(r io.Reader) (string, error) {
|
|
buff, err := io.ReadAll(r)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(buff), nil
|
|
}
|