Skip to content

Commit e7f3917

Browse files
committed
Rename CROrLFLines function
1 parent be38f84 commit e7f3917

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

app/execflash.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func CopyConvert(iff string, of string) (chan DdProgress, io.WriteCloser, error)
8888
go (func() {
8989
phase := "Phase Unknown"
9090
scanner := bufio.NewScanner(output)
91-
scanner.Split(ScanCRLFLines)
91+
scanner.Split(ScanCROrLFLines)
9292
for scanner.Scan() {
9393
text := scanner.Text()
9494
println(text)
@@ -122,35 +122,37 @@ func CopyConvert(iff string, of string) (chan DdProgress, io.WriteCloser, error)
122122
return channel, stdin, nil
123123
}
124124

125-
// dropCRLF drops a terminal \r or \n from the data.
126-
func dropCRLF(data []byte) []byte {
125+
// dropCROrLF drops a terminal \r or \n from the data.
126+
func dropCROrLF(data []byte) []byte {
127127
// FIXME: Write unit tests
128128
if len(data) > 0 && (data[len(data)-1] == '\r' || data[len(data)-1] == '\n') {
129129
return data[0 : len(data)-1]
130130
}
131131
return data
132132
}
133133

134-
// ScanCRLFLines is a split function for a Scanner that returns each line of
134+
// ScanCROrLFLines is a split function for a Scanner that returns each line of
135135
// text, stripped of any trailing end-of-line marker. The returned line may
136136
// be empty. The end-of-line marker is one carriage return or one mandatory
137137
// newline. In regular expression notation, it is `\r|\n`. The last
138138
// non-empty line of input will be returned even if it has no newline.
139-
func ScanCRLFLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
139+
//
140+
// Modified from [bufio.ScanLines] to support \r as a line terminator on its own.
141+
func ScanCROrLFLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
140142
// FIXME: Write unit tests
141143
if atEOF && len(data) == 0 {
142144
return 0, nil, nil
143145
}
144146
if i := bytes.IndexByte(data, '\n'); i >= 0 {
145147
// We have a full newline-terminated line.
146-
return i + 1, dropCRLF(data[0:i]), nil
148+
return i + 1, dropCROrLF(data[0:i]), nil
147149
} else if i := bytes.IndexByte(data, '\r'); i >= 0 {
148150
// We have a full carriage return-terminated line.
149-
return i + 1, dropCRLF(data[0:i]), nil
151+
return i + 1, dropCROrLF(data[0:i]), nil
150152
}
151153
// If we're at EOF, we have a final, non-terminated line. Return it.
152154
if atEOF {
153-
return len(data), dropCRLF(data), nil
155+
return len(data), dropCROrLF(data), nil
154156
}
155157
// Request more data.
156158
return 0, nil, nil

0 commit comments

Comments
 (0)