Commits

Dmitry Grebeniuk  committed 79c59cb

'bytes' fix

  • Participants
  • Parent commits a3aa289

Comments (0)

Files changed (1)

File iteratees.ml

 
 
 value rec into_substring_step str ofs len =
+  let () = assert (len > 0) in
+  fun
+  [ Chunk c ->
+      let clen = S.length c in
+      if len < clen
+      then
+        let (to_blit, to_leave) = S.split_at len c in
+        ( S.to_substring to_blit str ofs len
+        ; ie_doneM () (Chunk to_leave)
+        )
+      else
+        ( S.to_substring c str ofs clen
+        ; let len' = len - clen in
+          if len' = 0
+          then ie_doneMsl () Sl.empty
+          else ie_contM (into_substring_step str (ofs + clen) len')
+        )
+  | EOF None -> IO.error End_of_file
+  | EOF (Some e) -> IO.error e
+  ]
+and into_substring str ofs len : iteratee char unit =
   if len = 0
-  then
-    ie_doneM ()
-  else
-    fun
-    [ Chunk c ->
-        let clen = S.length c in
-        if len < clen
-        then
-          let (to_blit, to_leave) = S.split_at len c in
-          ( S.to_substring to_blit str ofs len
-          ; ie_doneM () (Chunk to_leave)
-          )
-        else
-          ( S.to_substring c str ofs clen
-          ; ie_contM (into_substring_step str ofs len)
-          )
-    | EOF None -> IO.error End_of_file
-    | EOF (Some e) -> IO.error e
-    ]
-;
-
-value into_substring str ofs len : iteratee char unit =
-  IE_cont None (into_substring_step str ofs len)
+  then return ()
+  else IE_cont None (into_substring_step str ofs len)
 ;
 
 (* +