aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/sourcegraph/go-diff/diff/reader_util.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-07-04 11:12:55 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-07-04 15:05:30 +0200
commitc7d7f10bdff703e4a3c0414e8a33d4e45c91eb35 (patch)
tree0dff0ee1f98dbfa3ad8776112053a450d176592b /vendor/github.com/sourcegraph/go-diff/diff/reader_util.go
parent9573094ce235bd9afe88f5da27a47dd6bcc1e13b (diff)
go.mod: vendor golangci-lint
Diffstat (limited to 'vendor/github.com/sourcegraph/go-diff/diff/reader_util.go')
-rw-r--r--vendor/github.com/sourcegraph/go-diff/diff/reader_util.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/vendor/github.com/sourcegraph/go-diff/diff/reader_util.go b/vendor/github.com/sourcegraph/go-diff/diff/reader_util.go
new file mode 100644
index 000000000..395fb7baf
--- /dev/null
+++ b/vendor/github.com/sourcegraph/go-diff/diff/reader_util.go
@@ -0,0 +1,37 @@
+package diff
+
+import (
+ "bufio"
+ "io"
+)
+
+// readLine is a helper that mimics the functionality of calling bufio.Scanner.Scan() and
+// bufio.Scanner.Bytes(), but without the token size limitation. It will read and return
+// the next line in the Reader with the trailing newline stripped. It will return an
+// io.EOF error when there is nothing left to read (at the start of the function call). It
+// will return any other errors it receives from the underlying call to ReadBytes.
+func readLine(r *bufio.Reader) ([]byte, error) {
+ line_, err := r.ReadBytes('\n')
+ if err == io.EOF {
+ if len(line_) == 0 {
+ return nil, io.EOF
+ }
+
+ // ReadBytes returned io.EOF, because it didn't find another newline, but there is
+ // still the remainder of the file to return as a line.
+ line := line_
+ return line, nil
+ } else if err != nil {
+ return nil, err
+ }
+ line := line_[0 : len(line_)-1]
+ return dropCR(line), nil
+}
+
+// dropCR drops a terminal \r from the data.
+func dropCR(data []byte) []byte {
+ if len(data) > 0 && data[len(data)-1] == '\r' {
+ return data[0 : len(data)-1]
+ }
+ return data
+}