aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorShenghou Ma <minux@golang.org>2014-12-11 23:07:04 -0500
committeriant <iant@golang.org>2014-12-12 04:38:47 +0000
commitd3072127ccac58f39df12a217f1fa9bb46d36a3b (patch)
tree17f5c48d143154e64242734e38c6d60a26947ea1 /src/cmd
parentbd8077116e2fe04306fc75ed1bd1eb3586b9cd1d (diff)
downloadgo-d3072127ccac58f39df12a217f1fa9bb46d36a3b.tar.xz
cmd/dist: ignore \r in crlf EOL when splitlines()
Fixes build on Windows. Fixes #9234. Change-Id: Iebf4317e7cc20ba1afea5558553166cd89783316 Reviewed-on: https://go-review.googlesource.com/1421 Reviewed-by: <iant@golang.org>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/dist/buf.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/cmd/dist/buf.c b/src/cmd/dist/buf.c
index 2ddc6be752..fbecd567ad 100644
--- a/src/cmd/dist/buf.c
+++ b/src/cmd/dist/buf.c
@@ -239,7 +239,8 @@ vuniq(Vec *v)
}
// splitlines replaces the vector v with the result of splitting
-// the input p after each \n.
+// the input p after each \n. If there is a \r immediately before
+// each \n, it will be removed.
void
splitlines(Vec *v, char *p)
{
@@ -249,8 +250,12 @@ splitlines(Vec *v, char *p)
vreset(v);
start = p;
for(i=0; p[i]; i++) {
- if(p[i] == '\n') {
+ if((p[i] == '\r' && p[i+1] == '\n') || p[i] == '\n') {
vaddn(v, start, (p+i+1)-start);
+ if(p[i] == '\r') {
+ v->p[v->len-1][(p+i)-start] = '\n';
+ i++;
+ }
start = p+i+1;
}
}