let rec getc rope i =
check_index rope i;
match rope with
- | Leaf (s,off,_) -> (Char.code s.[off + i])
+ | Leaf (s,off,_) ->
+ let c = (Char.code s.[off + i]) in
+ let len = (length rope) in
+ let next = (i + 1) in
+ if (c == 0x0D && next < len && (getc rope next) == 0x0A) then
+ 0x0A
+ else
+ c
| Node (l,r,len) ->
let left_len = (length l) in
if i < left_len then
let rope = Node((Leaf("a", 0, 1)), (Leaf("b", 0, 1)), 2) in
assert( (getc rope (1)) == Char.code 'b' );
);
+ test "getc : return \\n for \\r\\n" (fun () ->
+ let rope = from_string "\r\n" in
+ assert( (getc rope (0)) == Char.code '\n' );
+ );
+ test "getc : return \\r for \\r at end of string" (fun () ->
+ let rope = from_string "\r" in
+ assert( (getc rope (0)) == Char.code '\r' );
+ );
+ test "getc : return \\r for \\r with no \\n" (fun () ->
+ let rope = from_string "\ra" in
+ assert( (getc rope (0)) == Char.code '\r' );
+ );
(* puts() tests *)
test "puts : insert at index 0" (fun () ->