[Pkg-cli-apps-commits] [fsharp] 44/60: Improve handling of buffer when line ends with /r

Christopher Halse Rogers raof-guest at moszumanska.debian.org
Sun Sep 14 08:13:41 UTC 2014


This is an automated email from the git hooks/post-receive script.

raof-guest pushed a commit to branch master
in repository fsharp.

commit 19283e7940e7334459d1c6d25a31b2725f5c7ce9
Author: KevinRansom <codecutter at hotmail.com>
Date:   Wed Aug 27 12:58:28 2014 -0700

    Improve handling of buffer when line ends with /r
---
 vsintegration/src/vs/FsPkgs/FSharp.VS.FSI/sessions.fs | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/vsintegration/src/vs/FsPkgs/FSharp.VS.FSI/sessions.fs b/vsintegration/src/vs/FsPkgs/FSharp.VS.FSI/sessions.fs
index e008bde..a9c3ab5 100644
--- a/vsintegration/src/vs/FsPkgs/FSharp.VS.FSI/sessions.fs
+++ b/vsintegration/src/vs/FsPkgs/FSharp.VS.FSI/sessions.fs
@@ -180,21 +180,25 @@ let readLinesAsync (reader: System.IO.StreamReader) trigger =
     let charBuffer = 
         let maxCharsInBuffer = encoding.GetMaxCharCount byteBuffer.Length
         Array.zeroCreate maxCharsInBuffer
-    
+
     let rec findLinesInBuffer pos =
         if pos >= buffer.Length then max (buffer.Length - 1) 0 // exit and point to the last char
         else
         let c = buffer.[pos]
-        if c = '\r' || c = '\n' then
+        let deletePos = match c with
+                        | '\r' when (pos + 1) < buffer.Length && buffer.[pos + 1] = '\n' -> Some(pos + 2)
+                        | '\r' when (pos + 1) = buffer.Length -> None
+                        | '\r' -> Some(pos + 1)
+                        | '\n' -> Some(pos + 1)
+                        | _  ->  None
+
+        match deletePos with
+        | Some deletePos ->
             let line = buffer.ToString(0, pos)
             trigger line
-
-            let deletePos = 
-                if c = '\r' && (pos + 1) < buffer.Length && buffer.[pos + 1] = '\n' then pos + 2 else pos + 1
             buffer.Remove(0, deletePos) |> ignore
             findLinesInBuffer 0
-        else
-            findLinesInBuffer (pos + 1)
+        | None ->  findLinesInBuffer (pos + 1)
 
     let rec read pos = 
         async {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-cli-apps/packages/fsharp.git



More information about the Pkg-cli-apps-commits mailing list