]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: ignore \r in crlf EOL when splitlines()
authorShenghou Ma <minux@golang.org>
Fri, 12 Dec 2014 04:07:04 +0000 (23:07 -0500)
committeriant <iant@golang.org>
Fri, 12 Dec 2014 04:38:47 +0000 (04:38 +0000)
Fixes build on Windows. Fixes #9234.

Change-Id: Iebf4317e7cc20ba1afea5558553166cd89783316
Reviewed-on: https://go-review.googlesource.com/1421
Reviewed-by: <iant@golang.org>
src/cmd/dist/buf.c

index 2ddc6be7520243a51faf689de810caa48b24c806..fbecd567adb2f81a1a85f0dea20c5c698d0c85c3 100644 (file)
@@ -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;
                }
        }