present: fix get-to-end-of-line code in present's pattern matcher
The old code was wrong: it always advanced before checking
if we were already at end-of-line.
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/8876043
diff --git a/pkg/present/code.go b/pkg/present/code.go
index 624552a..9322e63 100644
--- a/pkg/present/code.go
+++ b/pkg/present/code.go
@@ -75,15 +75,14 @@
return nil, fmt.Errorf("%s:%d: %v", sourceFile, sourceLine, err)
}
- // Acme pattern matches stop mid-line,
- // so run to end of line in both directions.
+ // Acme pattern matches can stop mid-line,
+ // so run to end of line in both directions if not at line start/end.
for lo > 0 && textBytes[lo-1] != '\n' {
lo--
}
- for hi < len(textBytes) {
- hi++
- if textBytes[hi-1] == '\n' {
- break
+ if hi > 0 {
+ for hi < len(textBytes) && textBytes[hi-1] != '\n' {
+ hi++
}
}
text := string(textBytes[lo:hi])