<pre><span id="VALmake"><span class="keyword">val</span> make</span> : <code class="type"><a href="Buf.html#TYPEbuf">Buf.buf</a> -> int -> <a href="Buf.Cursor.html#TYPEcsr">csr</a></code></pre>
<pre><span id="VALclone"><span class="keyword">val</span> clone</span> : <code class="type"><a href="Buf.Cursor.html#TYPEcsr">csr</a> -> <a href="Buf.Cursor.html#TYPEcsr">csr</a></code></pre>
-<pre><span id="VALiter"><span class="keyword">val</span> iter</span> : <code class="type">'a -> 'b -> 'c -> unit</code></pre>
-<pre><span id="VALoffset"><span class="keyword">val</span> offset</span> : <code class="type">'a -> <a href="Buf.Cursor.html#TYPEcsr">csr</a> -> int</code></pre>
+<pre><span id="VALoffset"><span class="keyword">val</span> offset</span> : <code class="type"><a href="Buf.Cursor.html#TYPEcsr">csr</a> -> int</code></pre>
<pre><span id="VALgoto"><span class="keyword">val</span> goto</span> : <code class="type"><a href="Buf.html#TYPEbuf">Buf.buf</a> -> <a href="Buf.Cursor.html#TYPEcsr">csr</a> -> int -> unit</code></pre>
+<pre><span id="VALiter"><span class="keyword">val</span> iter</span> : <code class="type">(<a href="Buf.Cursor.html#TYPEcsr">csr</a> -> <a href="Rope.html#TYPErune">Rope.rune</a> -> bool) -> <a href="Buf.html#TYPEbuf">Buf.buf</a> -> <a href="Buf.Cursor.html#TYPEcsr">csr</a> -> unit</code></pre>
<pre><span id="VALgetc"><span class="keyword">val</span> getc</span> : <code class="type"><a href="Buf.html#TYPEbuf">Buf.buf</a> -> <a href="Buf.Cursor.html#TYPEcsr">csr</a> -> <a href="Rope.html#TYPErune">Rope.rune</a></code></pre>
<pre><span id="VALnextc"><span class="keyword">val</span> nextc</span> : <code class="type"><a href="Buf.html#TYPEbuf">Buf.buf</a> -> <a href="Buf.Cursor.html#TYPEcsr">csr</a> -> int</code></pre>
<pre><span id="VALprevc"><span class="keyword">val</span> prevc</span> : <code class="type"><a href="Buf.html#TYPEbuf">Buf.buf</a> -> <a href="Buf.Cursor.html#TYPEcsr">csr</a> -> int</code></pre>
<pre><span id="VALempty"><span class="keyword">val</span> empty</span> : <code class="type"><a href="Buf.html#TYPEbuf">buf</a></code></pre>
<pre><span id="VALload"><span class="keyword">val</span> load</span> : <code class="type">string -> <a href="Buf.html#TYPEbuf">buf</a></code></pre>
-<pre><span id="VALiter"><span class="keyword">val</span> iter</span> : <code class="type">(<a href="Rope.html#TYPErune">Rope.rune</a> -> bool) -> <a href="Buf.html#TYPEbuf">buf</a> -> int -> unit</code></pre>
<pre><span id="VALiteri"><span class="keyword">val</span> iteri</span> : <code class="type">(int -> <a href="Rope.html#TYPErune">Rope.rune</a> -> bool) -> <a href="Buf.html#TYPEbuf">buf</a> -> int -> unit</code></pre>
-<pre><span id="VALis_eol"><span class="keyword">val</span> is_eol</span> : <code class="type"><a href="Buf.html#TYPEbuf">buf</a> -> int -> bool</code></pre>
+<pre><span id="VALiter"><span class="keyword">val</span> iter</span> : <code class="type">(<a href="Rope.html#TYPErune">Rope.rune</a> -> bool) -> <a href="Buf.html#TYPEbuf">buf</a> -> int -> unit</code></pre>
<pre><span class="keyword">module</span> <a href="Buf.Cursor.html">Cursor</a>: <code class="code">sig</code> <a href="Buf.Cursor.html">..</a> <code class="code">end</code></pre></body></html>
\ No newline at end of file
<pre><span id="VALgetb"><span class="keyword">val</span> getb</span> : <code class="type"><a href="Rope.html#TYPEt">t</a> -> int -> char</code></pre>
<pre><span id="VALgetc"><span class="keyword">val</span> getc</span> : <code class="type"><a href="Rope.html#TYPEt">t</a> -> int -> int</code></pre>
<pre><span id="VALputc"><span class="keyword">val</span> putc</span> : <code class="type">'a -> 'b -> 'c -> 'a</code></pre>
-<pre><span id="EXCEPTIONBreak_loop"><span class="keyword">exception</span> Break_loop</span></pre>
-
-<pre><span id="VALiteri_leaf"><span class="keyword">val</span> iteri_leaf</span> : <code class="type">(int -> int -> bool) -> int -> string -> int -> int -> unit</code></pre>
<pre><span id="VALiteri"><span class="keyword">val</span> iteri</span> : <code class="type">(int -> int -> bool) -> <a href="Rope.html#TYPEt">t</a> -> int -> unit</code></pre>
<pre><span id="VALgets"><span class="keyword">val</span> gets</span> : <code class="type"><a href="Rope.html#TYPEt">t</a> -> int -> int -> string</code></pre>
<pre><span id="VALputs"><span class="keyword">val</span> puts</span> : <code class="type"><a href="Rope.html#TYPEt">t</a> -> string -> int -> <a href="Rope.html#TYPEt">t</a></code></pre>
<tr><td align="left"><br>B</td></tr>
<tr><td><a href="Rope.html#EXCEPTIONBad_rotation">Bad_rotation</a> [<a href="Rope.html">Rope</a>]</td>
<td></td></tr>
-<tr><td><a href="Rope.html#EXCEPTIONBreak_loop">Break_loop</a> [<a href="Rope.html">Rope</a>]</td>
-<td></td></tr>
<tr><td align="left"><br>O</td></tr>
<tr><td><a href="Rope.html#EXCEPTIONOut_of_bounds">Out_of_bounds</a> [<a href="Rope.html">Rope</a>]</td>
<td></td></tr>
<td></td></tr>
<tr><td><a href="Buf.Cursor.html#VALis_eol">is_eol</a> [<a href="Buf.Cursor.html">Buf.Cursor</a>]</td>
<td></td></tr>
-<tr><td><a href="Buf.html#VALis_eol">is_eol</a> [<a href="Buf.html">Buf</a>]</td>
-<td></td></tr>
<tr><td><a href="Rope.html#VALis_eol">is_eol</a> [<a href="Rope.html">Rope</a>]</td>
<td></td></tr>
<tr><td><a href="Buf.Cursor.html#VALiter">iter</a> [<a href="Buf.Cursor.html">Buf.Cursor</a>]</td>
<td></td></tr>
<tr><td><a href="Rope.html#VALiteri">iteri</a> [<a href="Rope.html">Rope</a>]</td>
<td></td></tr>
-<tr><td><a href="Rope.html#VALiteri_leaf">iteri_leaf</a> [<a href="Rope.html">Rope</a>]</td>
-<td></td></tr>
<tr><td align="left"><br>J</td></tr>
<tr><td><a href="Rope.html#VALjoin">join</a> [<a href="Rope.html">Rope</a>]</td>
<td></td></tr>
<span class="keyword">type</span> t = <span class="constructor">Buf</span>.<span class="constructor">Cursor</span>.csr<br>
<span class="keyword">val</span> make : <span class="constructor">Buf</span>.buf <span class="keywordsign">-></span> int <span class="keywordsign">-></span> <span class="constructor">Buf</span>.<span class="constructor">Cursor</span>.csr<br>
<span class="keyword">val</span> clone : <span class="constructor">Buf</span>.<span class="constructor">Cursor</span>.csr <span class="keywordsign">-></span> <span class="constructor">Buf</span>.<span class="constructor">Cursor</span>.csr<br>
- <span class="keyword">val</span> iter : <span class="keywordsign">'</span>a <span class="keywordsign">-></span> <span class="keywordsign">'</span>b <span class="keywordsign">-></span> <span class="keywordsign">'</span>c <span class="keywordsign">-></span> unit<br>
- <span class="keyword">val</span> offset : <span class="keywordsign">'</span>a <span class="keywordsign">-></span> <span class="constructor">Buf</span>.<span class="constructor">Cursor</span>.csr <span class="keywordsign">-></span> int<br>
+ <span class="keyword">val</span> offset : <span class="constructor">Buf</span>.<span class="constructor">Cursor</span>.csr <span class="keywordsign">-></span> int<br>
<span class="keyword">val</span> goto : <span class="constructor">Buf</span>.buf <span class="keywordsign">-></span> <span class="constructor">Buf</span>.<span class="constructor">Cursor</span>.csr <span class="keywordsign">-></span> int <span class="keywordsign">-></span> unit<br>
+ <span class="keyword">val</span> iter :<br>
+ (<span class="constructor">Buf</span>.<span class="constructor">Cursor</span>.csr <span class="keywordsign">-></span> <span class="constructor">Rope</span>.rune <span class="keywordsign">-></span> bool) <span class="keywordsign">-></span><br>
+ <span class="constructor">Buf</span>.buf <span class="keywordsign">-></span> <span class="constructor">Buf</span>.<span class="constructor">Cursor</span>.csr <span class="keywordsign">-></span> unit<br>
<span class="keyword">val</span> getc : <span class="constructor">Buf</span>.buf <span class="keywordsign">-></span> <span class="constructor">Buf</span>.<span class="constructor">Cursor</span>.csr <span class="keywordsign">-></span> <span class="constructor">Rope</span>.rune<br>
<span class="keyword">val</span> nextc : <span class="constructor">Buf</span>.buf <span class="keywordsign">-></span> <span class="constructor">Buf</span>.<span class="constructor">Cursor</span>.csr <span class="keywordsign">-></span> int<br>
<span class="keyword">val</span> prevc : <span class="constructor">Buf</span>.buf <span class="keywordsign">-></span> <span class="constructor">Buf</span>.<span class="constructor">Cursor</span>.csr <span class="keywordsign">-></span> int<br>
let load path =
{ path = path; rope = Rope.from_string (Misc.load_file path) }
-let iter fn buf i =
- Rope.iteri (fun i c -> (fn c)) buf.rope i
-
let iteri fn buf i =
Rope.iteri fn buf.rope i
-let is_eol buf off =
- Rope.is_eol buf.rope off
+let iter fn buf i =
+ iteri (fun i c -> (fn c)) buf i
module Cursor = struct
type csr = {
let clone csr =
{ start = csr.start; stop = csr.stop }
- let iter fn buf csr = ()
-
- let offset buf csr =
+ let offset csr =
csr.stop
let goto buf csr idx =
csr.stop <- (Rope.limit_index buf.rope idx)
+ let iter fn buf csr =
+ Rope.iteri (fun i c -> csr.stop <- i; (fn csr c)) buf.rope csr.stop
+
let getc buf csr =
Rope.getc buf.rope csr.stop
val iter : (int -> bool) -> t -> int -> unit
val iteri : (int -> int -> bool) -> t -> int -> unit
-val is_eol : buf -> int -> bool
-
module Cursor : sig
type t
val make : buf -> int -> t
val clone : t -> t
- val iter : (t -> bool) -> buf -> t -> unit
- val offset : buf -> t -> int
+ val iter : (t -> int -> bool) -> buf -> t -> unit
+ val offset : t -> int
val goto : buf -> t -> int -> unit
val getc : buf -> t -> int
- (*
+(*
val putc : buf -> t -> int -> unit
val gets : buf -> t -> string
val puts : buf -> t -> string -> unit
- *)
+*)
val nextc : buf -> t -> int
val prevc : buf -> t -> int
val nextln : buf -> t -> int
val prevln : buf -> t -> int
-
(*
val is_bol : buf -> t -> bool
val to_eol : buf -> t -> int
*)
-
val is_eol : buf -> t -> bool
val to_bol : buf -> t -> int
end
(******************************************************************************)
+(* inefficient form of iteri *)
+let rec iteri fn rope pos =
+ if pos < (length rope) && (fn pos (getc rope pos)) then
+ iteri fn rope (pos + 1)
+
+(* More efficient form of iteri?
exception Break_loop
let iteri_leaf fn pos str off len =
let offset = pos - off in
- for i = off to off + len - 1 do (* break loop when fn returns false *)
+ for i = off to off + len - 1 do
if (fn (i + offset) (Char.code str.[i])) == false then
raise Break_loop
done
| Node (l,r,_,_) ->
iteri fn l pos;
iteri fn r (pos + (length l))
-
-(*
-let rec iter_from fn rope pos =
- if pos < (length rope) && (fn (getc rope pos)) then
- iter_from fn rope (pos + 1)
-
-let rec iteri_from fn rope pos =
- if pos < (length rope) && (fn pos (getc rope pos)) then
- iteri_from fn rope (pos + 1)
*)
(******************************************************************************)
idx
let make buf width off =
- let bcsr = Buf.Cursor.make buf off in
- let dcsr = Draw.Cursor.make (width, 0) 0 0 in
- let lines = ref [Buf.Cursor.to_bol buf bcsr] in
+ let csr = Draw.Cursor.make (width, 0) 0 0 in
+ (*let bol = Buf.goto StartOfLine buf off in*)
+ let bol = Buf.Cursor.to_bol buf (Buf.Cursor.make buf off) in
+ let lines = ref [bol] in
let process_glyph i c =
- let not_eol = ((Buf.is_eol buf i) == false) in
- if (Draw.Cursor.next_glyph dcsr c) && not_eol then
+ let not_eol = (c != 0x0A) in
+ if (Draw.Cursor.next_glyph csr c) && not_eol then
lines := i :: !lines;
not_eol
in
- Buf.iteri process_glyph buf off;
+ Buf.iteri process_glyph buf bol;
let lines = (Array.of_list (List.rev !lines)) in
- print_string "map: ";
- Array.iter (fun x -> Printf.printf "%d " x) lines;
- print_endline "";
let index = (find_line lines off ((Array.length lines) - 1)) in
{ width = width; lines = lines; index = index }
let first map =
- Printf.printf "first: %d\n" map.lines.(map.index);
map.lines.(map.index)
let bopl buf off =