<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="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="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="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_from"><span class="keyword">val</span> iter_from</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_from"><span class="keyword">val</span> iteri_from</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="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 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="VALiter_from"><span class="keyword">val</span> iter_from</span> : <code class="type">(int -> bool) -> <a href="Rope.html#TYPEt">t</a> -> int -> unit</code></pre>
-<pre><span id="VALiteri_from"><span class="keyword">val</span> iteri_from</span> : <code class="type">(int -> int -> bool) -> <a href="Rope.html#TYPEt">t</a> -> int -> unit</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>
<pre><span id="VALnextc"><span class="keyword">val</span> nextc</span> : <code class="type"><a href="Rope.html#TYPEt">t</a> -> int -> int</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="Rope.html#VALcheck_index">check_index</a> [<a href="Rope.html">Rope</a>]</td>
<td></td></tr>
+<tr><td><a href="Buf.Cursor.html#VALclone">clone</a> [<a href="Buf.Cursor.html">Buf.Cursor</a>]</td>
+<td></td></tr>
<tr><td><a href="Cfg.html#VALclrvar">clrvar</a> [<a href="Cfg.html">Cfg</a>]</td>
<td></td></tr>
<tr><td><a href="Cfg.html#VALcmd_tags">cmd_tags</a> [<a href="Cfg.html">Cfg</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.html#VALiter_from">iter_from</a> [<a href="Buf.html">Buf</a>]</td>
+<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="Buf.html#VALiter">iter</a> [<a href="Buf.html">Buf</a>]</td>
<td></td></tr>
-<tr><td><a href="Rope.html#VALiter_from">iter_from</a> [<a href="Rope.html">Rope</a>]</td>
+<tr><td><a href="Buf.html#VALiteri">iteri</a> [<a href="Buf.html">Buf</a>]</td>
<td></td></tr>
-<tr><td><a href="Buf.html#VALiteri_from">iteri_from</a> [<a href="Buf.html">Buf</a>]</td>
+<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_from">iteri_from</a> [<a href="Rope.html">Rope</a>]</td>
+<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>
<span class="keyword">type</span> csr = { <span class="keyword">mutable</span> start : int; <span class="keyword">mutable</span> stop : int; }<br>
<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> 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> 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>
let load path =
{ path = path; rope = Rope.from_string (Misc.load_file path) }
-let iter_from fn buf i =
- Rope.iter_from fn buf.rope i
+let iter fn buf i =
+ Rope.iteri (fun i c -> (fn c)) buf.rope i
-let iteri_from fn buf i =
- Rope.iteri_from fn 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 make buf idx =
{ start = 0; stop = (Rope.limit_index buf.rope idx) }
+ let clone csr =
+ { start = csr.start; stop = csr.stop }
+
+ let iter fn buf csr = ()
+
let offset buf csr =
csr.stop
type t = buf
val empty : t
val load : string -> t
-val iter_from : (int -> bool) -> t -> int -> unit
-val iteri_from : (int -> int -> bool) -> t -> int -> unit
+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 goto : buf -> t -> int -> unit
val getc : 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
draw_glyph csr c;
has_next_line csr
in
- Buf.iter_from draw_rune buf off
+ Buf.iter draw_rune buf off
let status csr str =
dark_bkg csr.width (4 + font_height) csr;
(******************************************************************************)
+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 *)
+ if (fn (i + offset) (Char.code str.[i])) == false then
+ raise Break_loop
+ done
+
+let rec iteri fn rope pos =
+ match rope with
+ | Leaf (str, off, len) ->
+ (try iteri_leaf fn pos str off len
+ with Break_loop -> ())
+ | 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)
+*)
(******************************************************************************)
let gets rope i j =
let buf = Bytes.create (j - i) in
- iteri_from
+ iteri
(fun n c ->
Bytes.set buf (n - i) (getb rope i);
(n <= j))
val split : rope -> int -> (rope * rope)
val del : rope -> int -> int -> rope
-val iter_from : (rune -> bool) -> rope -> int -> unit
-val iteri_from : (int -> rune -> bool) -> rope -> int -> unit
+val iteri : (int -> rune -> bool) -> rope -> int -> unit
val getb : rope -> int -> char
val getc : rope -> int -> rune
lines := i :: !lines;
not_eol
in
- Buf.iteri_from process_glyph buf off;
+ Buf.iteri process_glyph buf off;
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 =